@oddo/lang 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -0
- package/dist/index.js +4966 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4966 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @oddo/lang
|
|
2
|
+
|
|
3
|
+
A high-performance parser and compiler for the Oddo language built with Chevrotain.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @oddo/lang
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
You'll also need Babel packages for code generation:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @babel/generator @babel/traverse @babel/types
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- Complete Oddo language support
|
|
20
|
+
- Brace-based blocks (JavaScript-style)
|
|
21
|
+
- JSX syntax
|
|
22
|
+
- Modifiers (`@state`, `@computed`, `@effect`, `@mutate`)
|
|
23
|
+
- All JavaScript operators with correct precedence
|
|
24
|
+
- Arrow functions
|
|
25
|
+
- Arrays, objects, and all data types
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### Parsing
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { parseOddo, parseOddoExpression } from '@oddo/lang';
|
|
33
|
+
|
|
34
|
+
// Parse a full program
|
|
35
|
+
const ast = parseOddo(`
|
|
36
|
+
x = 10
|
|
37
|
+
y = 20
|
|
38
|
+
return x + y
|
|
39
|
+
`);
|
|
40
|
+
|
|
41
|
+
// Parse an expression
|
|
42
|
+
const exprAst = parseOddoExpression('1 + 2 * 3');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Compiling to JavaScript
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
import { compileOddoToJS } from '@oddo/lang';
|
|
49
|
+
|
|
50
|
+
const jsCode = compileOddoToJS(`
|
|
51
|
+
Counter = () => {
|
|
52
|
+
@state count = 0
|
|
53
|
+
@mutate increment = () => {
|
|
54
|
+
count := count + 1
|
|
55
|
+
}
|
|
56
|
+
return <button onclick={increment}>
|
|
57
|
+
Count: {count}
|
|
58
|
+
</button>
|
|
59
|
+
}
|
|
60
|
+
`, { runtimeLibrary: '@oddo/ui' });
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Syntax Highlighting
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { highlightOddo, getHighlightingCSS } from '@oddo/lang';
|
|
67
|
+
|
|
68
|
+
// Get CSS for highlighting
|
|
69
|
+
const css = getHighlightingCSS();
|
|
70
|
+
|
|
71
|
+
// Highlight code
|
|
72
|
+
const html = highlightOddo('@state count = 0');
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## API
|
|
76
|
+
|
|
77
|
+
### `parseOddo(input: string): AST`
|
|
78
|
+
Parses Oddo source code and returns an Abstract Syntax Tree.
|
|
79
|
+
|
|
80
|
+
### `parseOddoExpression(input: string): ASTNode`
|
|
81
|
+
Parses a single Oddo expression.
|
|
82
|
+
|
|
83
|
+
### `compileOddoToJS(input: string, config?: CompileConfig): string`
|
|
84
|
+
Compiles Oddo source code to JavaScript.
|
|
85
|
+
|
|
86
|
+
### `highlightOddo(input: string): string`
|
|
87
|
+
Returns syntax-highlighted HTML for the given Oddo code.
|
|
88
|
+
|
|
89
|
+
### `getHighlightingCSS(): string`
|
|
90
|
+
Returns CSS styles for syntax highlighting.
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|