novac 2.0.1 → 2.2.0
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/LICENSE +1 -1
- package/README.md +1574 -597
- package/bin/novac +468 -171
- package/bin/nvc +522 -0
- package/bin/nvml +78 -17
- package/demo.nv +0 -0
- package/demo_builtins.nv +0 -0
- package/demo_http.nv +0 -0
- package/examples/bf.nv +69 -0
- package/examples/math.nv +21 -0
- package/kits/birdAPI/kitdef.js +954 -0
- package/kits/kitRNG/kitdef.js +740 -0
- package/kits/kitSSH/kitdef.js +1272 -0
- package/kits/kitadb/kitdef.js +606 -0
- package/kits/kitai/kitdef.js +2185 -0
- package/kits/kitansi/kitdef.js +1402 -0
- package/kits/kitcanvas/kitdef.js +914 -0
- package/kits/kitclippy/kitdef.js +925 -0
- package/kits/kitformat/kitdef.js +1485 -0
- package/kits/kitgps/kitdef.js +1862 -0
- package/kits/kitlibproc/kitdef.js +3 -2
- package/kits/kitmatrix/ex.js +19 -0
- package/kits/kitmatrix/kitdef.js +960 -0
- package/kits/kitmorse/kitdef.js +229 -0
- package/kits/kitmpatch/kitdef.js +906 -0
- package/kits/kitnet/kitdef.js +1401 -0
- package/kits/kitnovacweb/README.md +1416 -143
- package/kits/kitnovacweb/kitdef.js +92 -2
- package/kits/kitnovacweb/nvml/executor.js +578 -176
- package/kits/kitnovacweb/nvml/index.js +2 -2
- package/kits/kitnovacweb/nvml/lexer.js +72 -69
- package/kits/kitnovacweb/nvml/parser.js +328 -159
- package/kits/kitnovacweb/nvml/renderer.js +770 -270
- package/kits/kitparse/kitdef.js +1688 -0
- package/kits/kitproto/kitdef.js +613 -0
- package/kits/kitqr/kitdef.js +637 -0
- package/kits/kitregex++/kitdef.js +1353 -0
- package/kits/kitrequire/kitdef.js +1599 -0
- package/kits/kitx11/kitdef.js +1 -0
- package/kits/kitx11/kitx11.js +2472 -0
- package/kits/kitx11/kitx11_conn.js +948 -0
- package/kits/kitx11/kitx11_worker.js +121 -0
- package/kits/libtea/kitdef.js +2691 -0
- package/kits/libterm/ex.js +285 -0
- package/kits/libterm/kitdef.js +1927 -0
- package/novac/LICENSE +21 -0
- package/novac/README.md +1823 -0
- package/novac/bin/novac +950 -0
- package/novac/bin/nvc +522 -0
- package/novac/bin/nvml +542 -0
- package/novac/demo.nv +245 -0
- package/novac/demo_builtins.nv +209 -0
- package/novac/demo_http.nv +62 -0
- package/novac/examples/bf.nv +69 -0
- package/novac/examples/math.nv +21 -0
- package/novac/kits/kitai/kitdef.js +2185 -0
- package/novac/kits/kitansi/kitdef.js +1402 -0
- package/novac/kits/kitformat/kitdef.js +1485 -0
- package/novac/kits/kitgps/kitdef.js +1862 -0
- package/novac/kits/kitlibfs/kitdef.js +231 -0
- package/{examples/example-project/nova_modules → novac/kits}/kitlibproc/kitdef.js +3 -2
- package/novac/kits/kitmatrix/ex.js +19 -0
- package/novac/kits/kitmatrix/kitdef.js +960 -0
- package/novac/kits/kitmpatch/kitdef.js +906 -0
- package/novac/kits/kitnovacweb/README.md +1572 -0
- package/novac/kits/kitnovacweb/demo.nv +12 -0
- package/novac/kits/kitnovacweb/demo.nvml +71 -0
- package/novac/kits/kitnovacweb/index.nova +12 -0
- package/novac/kits/kitnovacweb/kitdef.js +692 -0
- package/novac/kits/kitnovacweb/nova.kit.json +8 -0
- package/novac/kits/kitnovacweb/nvml/executor.js +739 -0
- package/novac/kits/kitnovacweb/nvml/index.js +67 -0
- package/novac/kits/kitnovacweb/nvml/lexer.js +263 -0
- package/novac/kits/kitnovacweb/nvml/parser.js +508 -0
- package/novac/kits/kitnovacweb/nvml/renderer.js +924 -0
- package/novac/kits/kitparse/kitdef.js +1688 -0
- package/novac/kits/kitregex++/kitdef.js +1353 -0
- package/novac/kits/kitrequire/kitdef.js +1599 -0
- package/novac/kits/kitx11/kitdef.js +1 -0
- package/novac/kits/kitx11/kitx11.js +2472 -0
- package/novac/kits/kitx11/kitx11_conn.js +948 -0
- package/novac/kits/kitx11/kitx11_worker.js +121 -0
- package/novac/kits/libtea/tf.js +2691 -0
- package/novac/kits/libterm/ex.js +285 -0
- package/novac/kits/libterm/kitdef.js +1927 -0
- package/novac/node_modules/chalk/license +9 -0
- package/novac/node_modules/chalk/package.json +83 -0
- package/novac/node_modules/chalk/readme.md +297 -0
- package/novac/node_modules/chalk/source/index.d.ts +325 -0
- package/novac/node_modules/chalk/source/index.js +225 -0
- package/novac/node_modules/chalk/source/utilities.js +33 -0
- package/novac/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
- package/novac/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
- package/novac/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
- package/novac/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
- package/novac/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
- package/novac/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
- package/novac/node_modules/commander/LICENSE +22 -0
- package/novac/node_modules/commander/Readme.md +1176 -0
- package/novac/node_modules/commander/esm.mjs +16 -0
- package/novac/node_modules/commander/index.js +24 -0
- package/novac/node_modules/commander/lib/argument.js +150 -0
- package/novac/node_modules/commander/lib/command.js +2777 -0
- package/novac/node_modules/commander/lib/error.js +39 -0
- package/novac/node_modules/commander/lib/help.js +747 -0
- package/novac/node_modules/commander/lib/option.js +380 -0
- package/novac/node_modules/commander/lib/suggestSimilar.js +101 -0
- package/novac/node_modules/commander/package-support.json +19 -0
- package/novac/node_modules/commander/package.json +82 -0
- package/novac/node_modules/commander/typings/esm.d.mts +3 -0
- package/novac/node_modules/commander/typings/index.d.ts +1113 -0
- package/novac/node_modules/node-addon-api/LICENSE.md +9 -0
- package/novac/node_modules/node-addon-api/README.md +95 -0
- package/novac/node_modules/node-addon-api/common.gypi +21 -0
- package/novac/node_modules/node-addon-api/except.gypi +25 -0
- package/novac/node_modules/node-addon-api/index.js +14 -0
- package/novac/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
- package/novac/node_modules/node-addon-api/napi-inl.h +7165 -0
- package/novac/node_modules/node-addon-api/napi.h +3364 -0
- package/novac/node_modules/node-addon-api/node_addon_api.gyp +42 -0
- package/novac/node_modules/node-addon-api/node_api.gyp +9 -0
- package/novac/node_modules/node-addon-api/noexcept.gypi +26 -0
- package/novac/node_modules/node-addon-api/package-support.json +21 -0
- package/novac/node_modules/node-addon-api/package.json +480 -0
- package/novac/node_modules/node-addon-api/tools/README.md +73 -0
- package/novac/node_modules/node-addon-api/tools/check-napi.js +99 -0
- package/novac/node_modules/node-addon-api/tools/clang-format.js +71 -0
- package/novac/node_modules/node-addon-api/tools/conversion.js +301 -0
- package/novac/node_modules/serialize-javascript/LICENSE +27 -0
- package/novac/node_modules/serialize-javascript/README.md +149 -0
- package/novac/node_modules/serialize-javascript/index.js +297 -0
- package/novac/node_modules/serialize-javascript/package.json +33 -0
- package/novac/package.json +27 -0
- package/novac/scripts/update-bin.js +24 -0
- package/novac/src/core/bstd.js +1035 -0
- package/novac/src/core/config.js +155 -0
- package/novac/src/core/describe.js +187 -0
- package/novac/src/core/emitter.js +499 -0
- package/novac/src/core/error.js +86 -0
- package/novac/src/core/executor.js +5606 -0
- package/novac/src/core/formatter.js +686 -0
- package/novac/src/core/lexer.js +1026 -0
- package/novac/src/core/nova_builtins.js +717 -0
- package/novac/src/core/nova_thread_worker.js +166 -0
- package/novac/src/core/parser.js +2181 -0
- package/novac/src/core/types.js +112 -0
- package/novac/src/index.js +28 -0
- package/novac/src/runtime/stdlib.js +244 -0
- package/package.json +6 -3
- package/scripts/update-bin.js +0 -0
- package/src/core/bstd.js +838 -362
- package/src/core/executor.js +2578 -170
- package/src/core/lexer.js +502 -54
- package/src/core/nova_builtins.js +21 -3
- package/src/core/parser.js +413 -72
- package/src/core/types.js +30 -2
- package/src/index.js +0 -0
- package/examples/example-project/README.md +0 -3
- package/examples/example-project/src/main.nova +0 -3
- package/src/core/environment.js +0 -0
- /package/{examples/example-project/bin/example-project.nv → novac/node_modules/node-addon-api/nothing.c} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* NVML — Full pipeline
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* const nvml = require('./nvml');
|
|
8
|
+
* const html = nvml.compile(source, { novaRunner, novaEmitter });
|
|
9
|
+
* const doc = nvml.execute(source, { novaRunner });
|
|
10
|
+
* const html = nvml.renderDoc(doc, { novaEmitter });
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const { Lexer } = require('./lexer');
|
|
14
|
+
const { Parser } = require('./parser');
|
|
15
|
+
const { Executor, NvmlDocument, makeBfObject } = require('./executor');
|
|
16
|
+
const { Renderer } = require('./renderer');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parse NVML source into AST (no side effects).
|
|
20
|
+
*/
|
|
21
|
+
function parse(source) {
|
|
22
|
+
return new Parser(source).parse();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Execute AST into a live NvmlDocument.
|
|
27
|
+
* @param {object} ast
|
|
28
|
+
* @param {object} opts
|
|
29
|
+
* novaRunner(code, doc) — called for server-side Nova scripts
|
|
30
|
+
* existingDoc — reuse an existing document (for incremental re-runs)
|
|
31
|
+
*/
|
|
32
|
+
function executeAst(ast, opts = {}) {
|
|
33
|
+
const exec = new Executor(opts.novaRunner || null);
|
|
34
|
+
return exec.execute(ast, opts.existingDoc || null);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Render a live NvmlDocument to an HTML string.
|
|
39
|
+
* @param {NvmlDocument} doc
|
|
40
|
+
* @param {object} opts
|
|
41
|
+
* novaEmitter(code) — compiles Nova code to JS for client scripts
|
|
42
|
+
*/
|
|
43
|
+
function renderDoc(doc, opts = {}) {
|
|
44
|
+
const renderer = new Renderer({ novaEmitter: opts.novaEmitter || null });
|
|
45
|
+
return renderer.render(doc);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Full pipeline: source → HTML
|
|
50
|
+
*/
|
|
51
|
+
function compile(source, opts = {}) {
|
|
52
|
+
const ast = parse(source);
|
|
53
|
+
const doc = executeAst(ast, opts);
|
|
54
|
+
return renderDoc(doc, opts);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Execute source and return both doc + html.
|
|
59
|
+
*/
|
|
60
|
+
function run(source, opts = {}) {
|
|
61
|
+
const ast = parse(source);
|
|
62
|
+
const doc = executeAst(ast, opts);
|
|
63
|
+
const html = renderDoc(doc, opts);
|
|
64
|
+
return { doc, html, ast };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = { parse, executeAst, renderDoc, compile, run, NvmlDocument, makeBfObject };
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// ══════════════════════════════════════════════════════════════════════
|
|
4
|
+
// NVML Lexer v2
|
|
5
|
+
// New tokens:
|
|
6
|
+
// HASH #signal-name (reactive signal ref)
|
|
7
|
+
// BANG_IDENT !event (event emit shorthand)
|
|
8
|
+
// AT_IDENT @config @visual @ss @component @state @computed @effect @route @slot @use
|
|
9
|
+
// ELEMENT {tag} {element.tag} {component.Name}
|
|
10
|
+
// LBRACKET [ RBRACKET ]
|
|
11
|
+
// LPAREN ( (multiline string / expression)
|
|
12
|
+
// COLONCOLON ::
|
|
13
|
+
// ARROW -> (one-way binding)
|
|
14
|
+
// DARROW <-> (two-way binding)
|
|
15
|
+
// QUESTION ? (conditional render)
|
|
16
|
+
// TILDE ~ (transition/animation hint)
|
|
17
|
+
// EQ = COMMA , PIPE | STRING IDENT NUMBER DOT DOTDOT EOF
|
|
18
|
+
// ══════════════════════════════════════════════════════════════════════
|
|
19
|
+
|
|
20
|
+
const TT = {
|
|
21
|
+
AT_IDENT: 'AT_IDENT',
|
|
22
|
+
ELEMENT: 'ELEMENT',
|
|
23
|
+
LBRACKET: 'LBRACKET',
|
|
24
|
+
RBRACKET: 'RBRACKET',
|
|
25
|
+
LPAREN: 'LPAREN',
|
|
26
|
+
RPAREN: 'RPAREN',
|
|
27
|
+
COLONCOLON: 'COLONCOLON',
|
|
28
|
+
ARROW: 'ARROW', // ->
|
|
29
|
+
DARROW: 'DARROW', // <->
|
|
30
|
+
QUESTION: 'QUESTION', // ?
|
|
31
|
+
TILDE: 'TILDE', // ~
|
|
32
|
+
HASH: 'HASH', // #signalName
|
|
33
|
+
BANG_IDENT: 'BANG_IDENT', // !eventName
|
|
34
|
+
EQ: 'EQ',
|
|
35
|
+
COMMA: 'COMMA',
|
|
36
|
+
PIPE: 'PIPE',
|
|
37
|
+
STRING: 'STRING',
|
|
38
|
+
IDENT: 'IDENT',
|
|
39
|
+
NUMBER: 'NUMBER',
|
|
40
|
+
DOT: 'DOT',
|
|
41
|
+
DOTDOT: 'DOTDOT',
|
|
42
|
+
EOF: 'EOF',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
class Token {
|
|
46
|
+
constructor(type, value, line, col) {
|
|
47
|
+
this.type = type;
|
|
48
|
+
this.value = value;
|
|
49
|
+
this.line = line;
|
|
50
|
+
this.col = col;
|
|
51
|
+
}
|
|
52
|
+
toString() { return `Token(${this.type}, ${JSON.stringify(this.value)}, ${this.line}:${this.col})`; }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
class LexError extends Error {
|
|
56
|
+
constructor(msg, line, col) {
|
|
57
|
+
super(`[NVML Lexer ${line}:${col}] ${msg}`);
|
|
58
|
+
this.name = 'LexError';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class Lexer {
|
|
63
|
+
constructor(source) {
|
|
64
|
+
this.src = source;
|
|
65
|
+
this.pos = 0;
|
|
66
|
+
this.line = 1;
|
|
67
|
+
this.col = 1;
|
|
68
|
+
this.tokens = [];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
peek(offset = 0) { return this.src[this.pos + offset] ?? '\0'; }
|
|
72
|
+
isAtEnd() { return this.pos >= this.src.length; }
|
|
73
|
+
|
|
74
|
+
advance() {
|
|
75
|
+
const ch = this.src[this.pos++];
|
|
76
|
+
if (ch === '\n') { this.line++; this.col = 1; } else { this.col++; }
|
|
77
|
+
return ch;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
addToken(type, value) {
|
|
81
|
+
this.tokens.push(new Token(type, value, this.line, this.col));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
error(msg) { throw new LexError(msg, this.line, this.col); }
|
|
85
|
+
|
|
86
|
+
skipWhitespaceAndComments() {
|
|
87
|
+
while (!this.isAtEnd()) {
|
|
88
|
+
const ch = this.peek();
|
|
89
|
+
if (ch === ' ' || ch === '\t' || ch === '\r' || ch === '\n') { this.advance(); continue; }
|
|
90
|
+
// line comment
|
|
91
|
+
if (ch === '/' && this.peek(1) === '/') {
|
|
92
|
+
while (!this.isAtEnd() && this.peek() !== '\n') this.advance();
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
// block comment
|
|
96
|
+
if (ch === '/' && this.peek(1) === '*') {
|
|
97
|
+
this.advance(); this.advance();
|
|
98
|
+
while (!this.isAtEnd()) {
|
|
99
|
+
if (this.peek() === '*' && this.peek(1) === '/') { this.advance(); this.advance(); break; }
|
|
100
|
+
this.advance();
|
|
101
|
+
}
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
readQuotedString(quote) {
|
|
109
|
+
let val = '';
|
|
110
|
+
while (!this.isAtEnd()) {
|
|
111
|
+
const ch = this.advance();
|
|
112
|
+
if (ch === '\\') {
|
|
113
|
+
const esc = this.advance();
|
|
114
|
+
switch (esc) {
|
|
115
|
+
case 'n': val += '\n'; break; case 't': val += '\t'; break;
|
|
116
|
+
case 'r': val += '\r'; break; case '\\': val += '\\'; break;
|
|
117
|
+
default: val += esc;
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (ch === quote) break;
|
|
122
|
+
val += ch;
|
|
123
|
+
}
|
|
124
|
+
return val;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
readParenString() {
|
|
128
|
+
let val = '', depth = 1;
|
|
129
|
+
while (!this.isAtEnd()) {
|
|
130
|
+
const ch = this.advance();
|
|
131
|
+
if (ch === '(') { depth++; val += ch; continue; }
|
|
132
|
+
if (ch === ')') { depth--; if (depth === 0) break; val += ch; continue; }
|
|
133
|
+
val += ch;
|
|
134
|
+
}
|
|
135
|
+
return val;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
readElement() {
|
|
139
|
+
let name = '';
|
|
140
|
+
while (!this.isAtEnd() && this.peek() !== '}') name += this.advance();
|
|
141
|
+
if (this.isAtEnd()) this.error("Unterminated element name, expected '}'");
|
|
142
|
+
this.advance();
|
|
143
|
+
return name.trim();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
readIdent(firstChar) {
|
|
147
|
+
let val = firstChar;
|
|
148
|
+
while (!this.isAtEnd() && /[a-zA-Z0-9_\-]/.test(this.peek())) val += this.advance();
|
|
149
|
+
return val;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
readNumber(firstChar) {
|
|
153
|
+
let val = firstChar;
|
|
154
|
+
while (!this.isAtEnd() && /[0-9\.]/.test(this.peek())) val += this.advance();
|
|
155
|
+
return parseFloat(val);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
tokenize() {
|
|
159
|
+
while (true) {
|
|
160
|
+
this.skipWhitespaceAndComments();
|
|
161
|
+
if (this.isAtEnd()) { this.addToken(TT.EOF, null); break; }
|
|
162
|
+
|
|
163
|
+
const line = this.line, col = this.col;
|
|
164
|
+
const ch = this.advance();
|
|
165
|
+
|
|
166
|
+
switch (ch) {
|
|
167
|
+
case '[': {
|
|
168
|
+
if (this.peek() === '.' && this.peek(1) === '.') {
|
|
169
|
+
this.advance(); this.advance();
|
|
170
|
+
if (this.peek() === ']') {
|
|
171
|
+
this.advance();
|
|
172
|
+
this.tokens.push(new Token(TT.DOTDOT, '..', line, col));
|
|
173
|
+
} else { this.error("Expected ']' after '..'"); }
|
|
174
|
+
} else {
|
|
175
|
+
this.tokens.push(new Token(TT.LBRACKET, '[', line, col));
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case ']': this.tokens.push(new Token(TT.RBRACKET, ']', line, col)); break;
|
|
180
|
+
case '(': {
|
|
181
|
+
const val = this.readParenString();
|
|
182
|
+
this.tokens.push(new Token(TT.STRING, val, line, col));
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case ')': this.tokens.push(new Token(TT.RPAREN, ')', line, col)); break;
|
|
186
|
+
case ',': this.tokens.push(new Token(TT.COMMA, ',', line, col)); break;
|
|
187
|
+
case '|': this.tokens.push(new Token(TT.PIPE, '|', line, col)); break;
|
|
188
|
+
case '=': this.tokens.push(new Token(TT.EQ, '=', line, col)); break;
|
|
189
|
+
case '?': this.tokens.push(new Token(TT.QUESTION, '?', line, col)); break;
|
|
190
|
+
case '~': this.tokens.push(new Token(TT.TILDE, '~', line, col)); break;
|
|
191
|
+
case '-': {
|
|
192
|
+
if (this.peek() === '>') { this.advance(); this.tokens.push(new Token(TT.ARROW, '->', line, col)); }
|
|
193
|
+
else this.error("Unexpected '-', did you mean '->'?");
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case '<': {
|
|
197
|
+
if (this.peek() === '-' && this.peek(1) === '>') {
|
|
198
|
+
this.advance(); this.advance();
|
|
199
|
+
this.tokens.push(new Token(TT.DARROW, '<->', line, col));
|
|
200
|
+
} else { this.error("Unexpected '<', did you mean '<->'?"); }
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case ':': {
|
|
204
|
+
if (this.peek() === ':') { this.advance(); this.tokens.push(new Token(TT.COLONCOLON, '::', line, col)); }
|
|
205
|
+
else this.error("Unexpected ':', did you mean '::'?");
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
case '.': {
|
|
209
|
+
if (this.peek() === '.') { this.advance(); this.tokens.push(new Token(TT.DOTDOT, '..', line, col)); }
|
|
210
|
+
else this.tokens.push(new Token(TT.DOT, '.', line, col));
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case '#': {
|
|
214
|
+
// #signalName — reactive signal reference
|
|
215
|
+
if (/[a-zA-Z_]/.test(this.peek())) {
|
|
216
|
+
const name = this.readIdent(this.advance());
|
|
217
|
+
this.tokens.push(new Token(TT.HASH, name, line, col));
|
|
218
|
+
} else { this.error("Expected signal name after '#'"); }
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
case '!': {
|
|
222
|
+
// !eventName — event emit shorthand
|
|
223
|
+
if (/[a-zA-Z_]/.test(this.peek())) {
|
|
224
|
+
const name = this.readIdent(this.advance());
|
|
225
|
+
this.tokens.push(new Token(TT.BANG_IDENT, name, line, col));
|
|
226
|
+
} else { this.error("Expected event name after '!'"); }
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
case '@': {
|
|
230
|
+
if (/[a-zA-Z_]/.test(this.peek())) {
|
|
231
|
+
const name = this.readIdent(this.advance());
|
|
232
|
+
this.tokens.push(new Token(TT.AT_IDENT, name, line, col));
|
|
233
|
+
} else { this.error("Expected identifier after '@'"); }
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case '{': {
|
|
237
|
+
const name = this.readElement();
|
|
238
|
+
this.tokens.push(new Token(TT.ELEMENT, name, line, col));
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case "'": case '"': {
|
|
242
|
+
const val = this.readQuotedString(ch);
|
|
243
|
+
this.tokens.push(new Token(TT.STRING, val, line, col));
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
default: {
|
|
247
|
+
if (/[a-zA-Z_]/.test(ch)) {
|
|
248
|
+
const val = this.readIdent(ch);
|
|
249
|
+
this.tokens.push(new Token(TT.IDENT, val, line, col));
|
|
250
|
+
} else if (/[0-9]/.test(ch)) {
|
|
251
|
+
const val = this.readNumber(ch);
|
|
252
|
+
this.tokens.push(new Token(TT.NUMBER, val, line, col));
|
|
253
|
+
} else {
|
|
254
|
+
this.error(`Unexpected character '${ch}'`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return this.tokens;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
module.exports = { Lexer, Token, TT };
|