starlight-cli 1.0.19 → 1.0.20

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/dist/index.js CHANGED
@@ -1741,7 +1741,7 @@ class Lexer {
1741
1741
  skipComment() {
1742
1742
  if (this.currentChar === '#') {
1743
1743
  if (this.peek() === '*') {
1744
- this.advance(); this.advance(); // skip #*
1744
+ this.advance(); this.advance(); // #*
1745
1745
  while (this.currentChar !== null) {
1746
1746
  if (this.currentChar === '*' && this.peek() === '#') {
1747
1747
  this.advance(); this.advance();
@@ -1749,7 +1749,7 @@ class Lexer {
1749
1749
  }
1750
1750
  this.advance();
1751
1751
  }
1752
- this.error("Unterminated multi-line comment (#* ... *#)");
1752
+ this.error('Unterminated multi-line comment (#* ... *#)');
1753
1753
  } else {
1754
1754
  while (this.currentChar && this.currentChar !== '\n') this.advance();
1755
1755
  }
@@ -1764,7 +1764,8 @@ class Lexer {
1764
1764
  }
1765
1765
 
1766
1766
  if (this.currentChar === '.' && /[0-9]/.test(this.peek())) {
1767
- result += '.'; this.advance();
1767
+ result += '.';
1768
+ this.advance();
1768
1769
  while (this.currentChar && /[0-9]/.test(this.currentChar)) {
1769
1770
  result += this.currentChar;
1770
1771
  this.advance();
@@ -1772,11 +1773,13 @@ class Lexer {
1772
1773
  }
1773
1774
 
1774
1775
  if (this.currentChar && /[eE]/.test(this.currentChar)) {
1775
- result += this.currentChar; this.advance();
1776
+ result += this.currentChar;
1777
+ this.advance();
1776
1778
  if (this.currentChar === '+' || this.currentChar === '-') {
1777
- result += this.currentChar; this.advance();
1779
+ result += this.currentChar;
1780
+ this.advance();
1778
1781
  }
1779
- if (!/[0-9]/.test(this.currentChar)) this.error("Invalid exponent in number");
1782
+ if (!/[0-9]/.test(this.currentChar)) this.error('Invalid exponent in number');
1780
1783
  while (this.currentChar && /[0-9]/.test(this.currentChar)) {
1781
1784
  result += this.currentChar;
1782
1785
  this.advance();
@@ -1795,8 +1798,9 @@ class Lexer {
1795
1798
 
1796
1799
  const keywords = [
1797
1800
  'let', 'sldeploy', 'if', 'else', 'while', 'for',
1798
- 'break', 'continue', 'func', 'return', 'true', 'false', 'null',
1799
- 'ask', 'define', 'import', 'from', 'as', 'undefined'
1801
+ 'break', 'continue', 'func', 'return',
1802
+ 'true', 'false', 'null', 'undefined',
1803
+ 'ask', 'define', 'import', 'from', 'as'
1800
1804
  ];
1801
1805
 
1802
1806
  if (keywords.includes(result)) {
@@ -1814,67 +1818,59 @@ class Lexer {
1814
1818
  while (this.currentChar && this.currentChar !== quote) {
1815
1819
  if (this.currentChar === '\\') {
1816
1820
  this.advance();
1817
- switch (this.currentChar) {
1818
- case 'n': result += '\n'; break;
1819
- case 't': result += '\t'; break;
1820
- case '"': result += '"'; break;
1821
- case "'": result += "'"; break;
1822
- case '\\': result += '\\'; break;
1823
- default: result += this.currentChar;
1824
- }
1821
+ const map = { n: '\n', t: '\t', '"': '"', "'": "'", '\\': '\\' };
1822
+ result += map[this.currentChar] ?? this.currentChar;
1825
1823
  } else {
1826
1824
  result += this.currentChar;
1827
1825
  }
1828
1826
  this.advance();
1829
1827
  }
1830
1828
 
1831
- if (this.currentChar !== quote) {
1832
- this.error('Unterminated string literal');
1833
- }
1829
+ if (this.currentChar !== quote) this.error('Unterminated string literal');
1834
1830
 
1835
1831
  this.advance();
1836
1832
  return { type: 'STRING', value: result };
1837
1833
  }
1838
1834
 
1839
- templateString() {
1840
- this.advance(); // skip initial backtick `
1841
- let buffer = '';
1842
- const tokens = [];
1843
1835
 
1844
- while (this.currentChar && this.currentChar !== '`') {
1845
- if (this.currentChar === '$' && this.peek() === '{') {
1846
- if (buffer.length > 0) {
1847
- tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
1848
- buffer = '';
1849
- }
1850
- tokens.push({ type: 'DOLLAR_LBRACE' }); // ${
1851
- this.advance(); this.advance();
1852
- continue;
1853
- }
1836
+ templateString(tokens) {
1837
+ this.advance(); // skip opening `
1854
1838
 
1855
- if (this.currentChar === '\\') {
1856
- this.advance();
1857
- switch (this.currentChar) {
1858
- case 'n': buffer += '\n'; break;
1859
- case 't': buffer += '\t'; break;
1860
- case '`': buffer += '`'; break;
1861
- case '\\': buffer += '\\'; break;
1862
- default: buffer += this.currentChar;
1839
+ let buffer = '';
1840
+
1841
+ while (this.currentChar !== null) {
1842
+ if (this.currentChar === '`') {
1843
+ if (buffer.length > 0) {
1844
+ tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
1845
+ }
1846
+ this.advance();
1847
+ return;
1863
1848
  }
1864
- } else {
1865
- buffer += this.currentChar;
1866
- }
1867
- this.advance();
1868
- }
1869
1849
 
1870
- if (buffer.length > 0) tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
1850
+ if (this.currentChar === '$' && this.peek() === '{') {
1851
+ if (buffer.length > 0) {
1852
+ tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
1853
+ buffer = '';
1854
+ }
1855
+ this.advance(); // $
1856
+ this.advance(); // {
1857
+ tokens.push({ type: 'DOLLAR_LBRACE' });
1858
+ return;
1859
+ }
1871
1860
 
1872
- if (this.currentChar !== '`') this.error('Unterminated template string');
1873
- this.advance(); // skip closing backtick
1861
+ if (this.currentChar === '\\') {
1862
+ this.advance();
1863
+ buffer += this.currentChar;
1864
+ this.advance();
1865
+ continue;
1866
+ }
1874
1867
 
1875
- return tokens; // return array of tokens
1876
- }
1868
+ buffer += this.currentChar;
1869
+ this.advance();
1870
+ }
1877
1871
 
1872
+ this.error('Unterminated template string');
1873
+ }
1878
1874
 
1879
1875
  getTokens() {
1880
1876
  const tokens = [];
@@ -1885,12 +1881,11 @@ class Lexer {
1885
1881
  if (/[0-9]/.test(this.currentChar)) { tokens.push(this.number()); continue; }
1886
1882
  if (/[A-Za-z_]/.test(this.currentChar)) { tokens.push(this.identifier()); continue; }
1887
1883
  if (this.currentChar === '"' || this.currentChar === "'") { tokens.push(this.string()); continue; }
1888
- if (this.currentChar === '`') {
1889
- const tTokens = this.templateString();
1890
- tokens.push(...tTokens); // push all tokens returned from templateString
1891
- continue;
1892
- }
1893
1884
 
1885
+ if (this.currentChar === '`') {
1886
+ this.templateString(tokens);
1887
+ continue;
1888
+ }
1894
1889
 
1895
1890
  const char = this.currentChar;
1896
1891
  const next = this.peek();
@@ -1910,20 +1905,30 @@ class Lexer {
1910
1905
  if (char === '+' && next === '+') { tokens.push({ type: 'PLUSPLUS' }); this.advance(); this.advance(); continue; }
1911
1906
  if (char === '-' && next === '-') { tokens.push({ type: 'MINUSMINUS' }); this.advance(); this.advance(); continue; }
1912
1907
 
1913
- const map = { '+': 'PLUSEQ', '-': 'MINUSEQ', '*': 'STAREQ', '/': 'SLASHEQ', '%': 'MODEQ' };
1914
- if (next === '=' && map[char]) { tokens.push({ type: map[char] }); this.advance(); this.advance(); continue; }
1908
+ const compound = { '+': 'PLUSEQ', '-': 'MINUSEQ', '*': 'STAREQ', '/': 'SLASHEQ', '%': 'MODEQ' };
1909
+ if (next === '=' && compound[char]) {
1910
+ tokens.push({ type: compound[char] });
1911
+ this.advance(); this.advance();
1912
+ continue;
1913
+ }
1915
1914
 
1916
1915
  const singles = {
1917
1916
  '+': 'PLUS', '-': 'MINUS', '*': 'STAR', '/': 'SLASH', '%': 'MOD',
1918
1917
  '=': 'EQUAL', '<': 'LT', '>': 'GT', '!': 'NOT',
1919
- '(': 'LPAREN', ')': 'RPAREN', '{': 'LBRACE', '}': 'RBRACE',
1920
- ';': 'SEMICOLON', ',': 'COMMA', '[': 'LBRACKET', ']': 'RBRACKET',
1918
+ '(': 'LPAREN', ')': 'RPAREN',
1919
+ '{': 'LBRACE', '}': 'RBRACE',
1920
+ '[': 'LBRACKET', ']': 'RBRACKET',
1921
+ ';': 'SEMICOLON', ',': 'COMMA',
1921
1922
  ':': 'COLON', '.': 'DOT'
1922
1923
  };
1923
1924
 
1924
- if (singles[char]) { tokens.push({ type: singles[char] }); this.advance(); continue; }
1925
+ if (singles[char]) {
1926
+ tokens.push({ type: singles[char] });
1927
+ this.advance();
1928
+ continue;
1929
+ }
1925
1930
 
1926
- this.error("Unexpected character: " + char);
1931
+ this.error(`Unexpected character: ${char}`);
1927
1932
  }
1928
1933
 
1929
1934
  tokens.push({ type: 'EOF' });
@@ -2329,10 +2334,11 @@ class Parser {
2329
2334
 
2330
2335
  if (t.type === 'NUMBER') { this.eat('NUMBER'); return { type: 'Literal', value: t.value }; }
2331
2336
  if (t.type === 'STRING') { this.eat('STRING'); return { type: 'Literal', value: t.value }; }
2332
- if (t.type === 'TEMPLATE_STRING' || t.type === 'DOLLAR_LBRACE') {
2337
+ if (t.type === 'TEMPLATE_STRING') {
2333
2338
  return this.parseTemplateLiteral();
2334
2339
  }
2335
2340
 
2341
+
2336
2342
  if (t.type === 'TRUE') { this.eat('TRUE'); return { type: 'Literal', value: true }; }
2337
2343
  if (t.type === 'FALSE') { this.eat('FALSE'); return { type: 'Literal', value: false }; }
2338
2344
  if (t.type === 'NULL') { this.eat('NULL'); return { type: 'Literal', value: null }; }
@@ -2504,7 +2510,7 @@ const Lexer = __nccwpck_require__(211);
2504
2510
  const Parser = __nccwpck_require__(222);
2505
2511
  const Evaluator = __nccwpck_require__(112);
2506
2512
 
2507
- const VERSION = '1.0.19';
2513
+ const VERSION = '1.0.20';
2508
2514
 
2509
2515
  const COLOR = {
2510
2516
  reset: '\x1b[0m',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.0.19",
3
+ "version": "1.0.20",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/lexer.js CHANGED
@@ -25,7 +25,7 @@ class Lexer {
25
25
  skipComment() {
26
26
  if (this.currentChar === '#') {
27
27
  if (this.peek() === '*') {
28
- this.advance(); this.advance(); // skip #*
28
+ this.advance(); this.advance(); // #*
29
29
  while (this.currentChar !== null) {
30
30
  if (this.currentChar === '*' && this.peek() === '#') {
31
31
  this.advance(); this.advance();
@@ -33,7 +33,7 @@ class Lexer {
33
33
  }
34
34
  this.advance();
35
35
  }
36
- this.error("Unterminated multi-line comment (#* ... *#)");
36
+ this.error('Unterminated multi-line comment (#* ... *#)');
37
37
  } else {
38
38
  while (this.currentChar && this.currentChar !== '\n') this.advance();
39
39
  }
@@ -48,7 +48,8 @@ class Lexer {
48
48
  }
49
49
 
50
50
  if (this.currentChar === '.' && /[0-9]/.test(this.peek())) {
51
- result += '.'; this.advance();
51
+ result += '.';
52
+ this.advance();
52
53
  while (this.currentChar && /[0-9]/.test(this.currentChar)) {
53
54
  result += this.currentChar;
54
55
  this.advance();
@@ -56,11 +57,13 @@ class Lexer {
56
57
  }
57
58
 
58
59
  if (this.currentChar && /[eE]/.test(this.currentChar)) {
59
- result += this.currentChar; this.advance();
60
+ result += this.currentChar;
61
+ this.advance();
60
62
  if (this.currentChar === '+' || this.currentChar === '-') {
61
- result += this.currentChar; this.advance();
63
+ result += this.currentChar;
64
+ this.advance();
62
65
  }
63
- if (!/[0-9]/.test(this.currentChar)) this.error("Invalid exponent in number");
66
+ if (!/[0-9]/.test(this.currentChar)) this.error('Invalid exponent in number');
64
67
  while (this.currentChar && /[0-9]/.test(this.currentChar)) {
65
68
  result += this.currentChar;
66
69
  this.advance();
@@ -79,8 +82,9 @@ class Lexer {
79
82
 
80
83
  const keywords = [
81
84
  'let', 'sldeploy', 'if', 'else', 'while', 'for',
82
- 'break', 'continue', 'func', 'return', 'true', 'false', 'null',
83
- 'ask', 'define', 'import', 'from', 'as', 'undefined'
85
+ 'break', 'continue', 'func', 'return',
86
+ 'true', 'false', 'null', 'undefined',
87
+ 'ask', 'define', 'import', 'from', 'as'
84
88
  ];
85
89
 
86
90
  if (keywords.includes(result)) {
@@ -98,67 +102,59 @@ class Lexer {
98
102
  while (this.currentChar && this.currentChar !== quote) {
99
103
  if (this.currentChar === '\\') {
100
104
  this.advance();
101
- switch (this.currentChar) {
102
- case 'n': result += '\n'; break;
103
- case 't': result += '\t'; break;
104
- case '"': result += '"'; break;
105
- case "'": result += "'"; break;
106
- case '\\': result += '\\'; break;
107
- default: result += this.currentChar;
108
- }
105
+ const map = { n: '\n', t: '\t', '"': '"', "'": "'", '\\': '\\' };
106
+ result += map[this.currentChar] ?? this.currentChar;
109
107
  } else {
110
108
  result += this.currentChar;
111
109
  }
112
110
  this.advance();
113
111
  }
114
112
 
115
- if (this.currentChar !== quote) {
116
- this.error('Unterminated string literal');
117
- }
113
+ if (this.currentChar !== quote) this.error('Unterminated string literal');
118
114
 
119
115
  this.advance();
120
116
  return { type: 'STRING', value: result };
121
117
  }
122
118
 
123
- templateString() {
124
- this.advance(); // skip initial backtick `
125
- let buffer = '';
126
- const tokens = [];
127
119
 
128
- while (this.currentChar && this.currentChar !== '`') {
129
- if (this.currentChar === '$' && this.peek() === '{') {
130
- if (buffer.length > 0) {
131
- tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
132
- buffer = '';
133
- }
134
- tokens.push({ type: 'DOLLAR_LBRACE' }); // ${
135
- this.advance(); this.advance();
136
- continue;
137
- }
120
+ templateString(tokens) {
121
+ this.advance(); // skip opening `
138
122
 
139
- if (this.currentChar === '\\') {
140
- this.advance();
141
- switch (this.currentChar) {
142
- case 'n': buffer += '\n'; break;
143
- case 't': buffer += '\t'; break;
144
- case '`': buffer += '`'; break;
145
- case '\\': buffer += '\\'; break;
146
- default: buffer += this.currentChar;
123
+ let buffer = '';
124
+
125
+ while (this.currentChar !== null) {
126
+ if (this.currentChar === '`') {
127
+ if (buffer.length > 0) {
128
+ tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
129
+ }
130
+ this.advance();
131
+ return;
147
132
  }
148
- } else {
149
- buffer += this.currentChar;
150
- }
151
- this.advance();
152
- }
153
133
 
154
- if (buffer.length > 0) tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
134
+ if (this.currentChar === '$' && this.peek() === '{') {
135
+ if (buffer.length > 0) {
136
+ tokens.push({ type: 'TEMPLATE_STRING', value: buffer });
137
+ buffer = '';
138
+ }
139
+ this.advance(); // $
140
+ this.advance(); // {
141
+ tokens.push({ type: 'DOLLAR_LBRACE' });
142
+ return;
143
+ }
155
144
 
156
- if (this.currentChar !== '`') this.error('Unterminated template string');
157
- this.advance(); // skip closing backtick
145
+ if (this.currentChar === '\\') {
146
+ this.advance();
147
+ buffer += this.currentChar;
148
+ this.advance();
149
+ continue;
150
+ }
158
151
 
159
- return tokens; // return array of tokens
160
- }
152
+ buffer += this.currentChar;
153
+ this.advance();
154
+ }
161
155
 
156
+ this.error('Unterminated template string');
157
+ }
162
158
 
163
159
  getTokens() {
164
160
  const tokens = [];
@@ -169,12 +165,11 @@ class Lexer {
169
165
  if (/[0-9]/.test(this.currentChar)) { tokens.push(this.number()); continue; }
170
166
  if (/[A-Za-z_]/.test(this.currentChar)) { tokens.push(this.identifier()); continue; }
171
167
  if (this.currentChar === '"' || this.currentChar === "'") { tokens.push(this.string()); continue; }
172
- if (this.currentChar === '`') {
173
- const tTokens = this.templateString();
174
- tokens.push(...tTokens); // push all tokens returned from templateString
175
- continue;
176
- }
177
168
 
169
+ if (this.currentChar === '`') {
170
+ this.templateString(tokens);
171
+ continue;
172
+ }
178
173
 
179
174
  const char = this.currentChar;
180
175
  const next = this.peek();
@@ -194,20 +189,30 @@ class Lexer {
194
189
  if (char === '+' && next === '+') { tokens.push({ type: 'PLUSPLUS' }); this.advance(); this.advance(); continue; }
195
190
  if (char === '-' && next === '-') { tokens.push({ type: 'MINUSMINUS' }); this.advance(); this.advance(); continue; }
196
191
 
197
- const map = { '+': 'PLUSEQ', '-': 'MINUSEQ', '*': 'STAREQ', '/': 'SLASHEQ', '%': 'MODEQ' };
198
- if (next === '=' && map[char]) { tokens.push({ type: map[char] }); this.advance(); this.advance(); continue; }
192
+ const compound = { '+': 'PLUSEQ', '-': 'MINUSEQ', '*': 'STAREQ', '/': 'SLASHEQ', '%': 'MODEQ' };
193
+ if (next === '=' && compound[char]) {
194
+ tokens.push({ type: compound[char] });
195
+ this.advance(); this.advance();
196
+ continue;
197
+ }
199
198
 
200
199
  const singles = {
201
200
  '+': 'PLUS', '-': 'MINUS', '*': 'STAR', '/': 'SLASH', '%': 'MOD',
202
201
  '=': 'EQUAL', '<': 'LT', '>': 'GT', '!': 'NOT',
203
- '(': 'LPAREN', ')': 'RPAREN', '{': 'LBRACE', '}': 'RBRACE',
204
- ';': 'SEMICOLON', ',': 'COMMA', '[': 'LBRACKET', ']': 'RBRACKET',
202
+ '(': 'LPAREN', ')': 'RPAREN',
203
+ '{': 'LBRACE', '}': 'RBRACE',
204
+ '[': 'LBRACKET', ']': 'RBRACKET',
205
+ ';': 'SEMICOLON', ',': 'COMMA',
205
206
  ':': 'COLON', '.': 'DOT'
206
207
  };
207
208
 
208
- if (singles[char]) { tokens.push({ type: singles[char] }); this.advance(); continue; }
209
+ if (singles[char]) {
210
+ tokens.push({ type: singles[char] });
211
+ this.advance();
212
+ continue;
213
+ }
209
214
 
210
- this.error("Unexpected character: " + char);
215
+ this.error(`Unexpected character: ${char}`);
211
216
  }
212
217
 
213
218
  tokens.push({ type: 'EOF' });
package/src/parser.js CHANGED
@@ -388,10 +388,11 @@ class Parser {
388
388
 
389
389
  if (t.type === 'NUMBER') { this.eat('NUMBER'); return { type: 'Literal', value: t.value }; }
390
390
  if (t.type === 'STRING') { this.eat('STRING'); return { type: 'Literal', value: t.value }; }
391
- if (t.type === 'TEMPLATE_STRING' || t.type === 'DOLLAR_LBRACE') {
391
+ if (t.type === 'TEMPLATE_STRING') {
392
392
  return this.parseTemplateLiteral();
393
393
  }
394
394
 
395
+
395
396
  if (t.type === 'TRUE') { this.eat('TRUE'); return { type: 'Literal', value: true }; }
396
397
  if (t.type === 'FALSE') { this.eat('FALSE'); return { type: 'Literal', value: false }; }
397
398
  if (t.type === 'NULL') { this.eat('NULL'); return { type: 'Literal', value: null }; }
package/src/starlight.js CHANGED
@@ -9,7 +9,7 @@ const Lexer = require('./lexer');
9
9
  const Parser = require('./parser');
10
10
  const Evaluator = require('./evaluator');
11
11
 
12
- const VERSION = '1.0.19';
12
+ const VERSION = '1.0.20';
13
13
 
14
14
  const COLOR = {
15
15
  reset: '\x1b[0m',