Skip to content

Commit ae638ac

Browse files
committed
Split group and seq
1 parent cd4c0cb commit ae638ac

4 files changed

Lines changed: 16 additions & 21 deletions

File tree

feature/group.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
import { nary, group, operator, compile } from '../parse.js';
1+
import { group } from '../parse.js';
22

3-
const STATEMENT = 5, SEQ = 10, ACCESS = 170;
3+
const ACCESS = 170;
44

55
// (a,b,c), (a) — uses ACCESS to avoid conflict with ?.
66
group('()', ACCESS);
7-
8-
// Sequences
9-
nary(',', SEQ);
10-
nary(';', STATEMENT, true); // right-assoc to allow same-prec statements
11-
12-
// Compile sequences - returns last evaluated value
13-
const seq = (...args) => (args = args.map(compile), ctx => { let r; for (const a of args) r = a(ctx); return r; });
14-
operator(',', seq);
15-
operator(';', seq);

index.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
326326
literal: 'feature/literal.js',
327327
access: 'feature/access.js',
328328
group: 'feature/group.js',
329+
seq: 'feature/seq.js',
329330

330331
// Operators (from subscript.js and justin.js)
331332
assign: 'feature/op/assignment.js',
@@ -380,7 +381,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
380381
// Control flow foundations (needed by group via loop)
381382
'control', 'block', 'destruct', 'loop',
382383
// Expression features
383-
'group', 'access',
384+
'seq', 'group', 'access',
384385
// Justin additions
385386
'comment', 'identity', 'nullish', 'pow', 'unary',
386387
'literal', 'ternary', 'arrow', 'spread', 'optional',
@@ -392,7 +393,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
392393

393394
// UI feature groups (maps to internal IDs)
394395
const FEATURES = [
395-
{ cat: 'Core', items: ['number', 'string', 'group', 'access'] },
396+
{ cat: 'Core', items: ['number', 'string', 'group', 'seq', 'access'] },
396397
{ cat: 'Operators', items: ['assign', 'arithmetic', 'logical', 'bit', 'cmp', 'equality', 'increment', 'pow'] },
397398
{ cat: 'Advanced Ops', items: ['ternary', 'arrow', 'optional', 'spread', 'unary', 'identity', 'nullish'] },
398399
{ cat: 'Literals', items: ['literal', 'collection', 'template', 'regex', 'unit', 'comment'] },
@@ -402,7 +403,7 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
402403

403404
const DESC = {
404405
// Core
405-
number: '123, 1.5', string: '"x", \'y\'', group: '()', access: 'a.b, a[i]',
406+
number: '123, 1.5', string: '"x", \'y\'', group: '()', seq: ', ;', access: 'a.b, a[i]',
406407
// Operators
407408
assign: '=, +=', arithmetic: '+-*/%', logical: '&& || !', bit: '& | ^ ~',
408409
cmp: '< > <= >=', equality: '== !=', increment: '++ --', pow: '**',
@@ -424,7 +425,8 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
424425
const TIPS = {
425426
number: 'Decimal numbers<br><code>42</code> <code>3.14</code> <code>1e3</code> <code>0xFF</code> <code>0b101</code>',
426427
string: 'String literals<br><code>"hello"</code> <code>\'world\'</code> with escapes',
427-
group: 'Grouping & sequences<br><code>(a + b)</code> <code>a, b</code> <code>a; b</code>',
428+
group: 'Grouping<br><code>(a + b)</code>',
429+
seq: 'Sequences<br><code>a, b</code> <code>a; b</code>',
428430
access: 'Property access<br><code>a.b</code> <code>a[i]</code> <code>fn()</code>',
429431
assign: 'Assignment operators<br><code>=</code> <code>+=</code> <code>-=</code> <code>*=</code> <code>/=</code>',
430432
arithmetic: 'Math operators<br><code>+ - * / %</code> unary: <code>+x</code> <code>-x</code>',
@@ -658,15 +660,15 @@ <h1><a href="https://github.com/dy/subscript" class="logo-link" target="_blank"
658660

659661
const PRESETS = {
660662
// Minimal: just numbers and basic arithmetic
661-
minimal: ['number', 'string', 'group', 'arithmetic'],
663+
minimal: ['number', 'string', 'seq', 'group', 'arithmetic'],
662664
// Expressions: subscript.js features
663-
expr: ['number', 'string', 'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment', 'group', 'access'],
665+
expr: ['number', 'string', 'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment', 'seq', 'group', 'access'],
664666
// Justin: JSON + expressions (no statements)
665-
justin: ['number', 'string', 'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment', 'group', 'access',
667+
justin: ['number', 'string', 'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment', 'seq', 'group', 'access',
666668
'comment', 'identity', 'nullish', 'pow', 'unary', 'literal', 'ternary', 'arrow', 'spread', 'optional',
667669
'collection', 'template'],
668670
// Jessie: practical JS subset with statements
669-
jessie: ['number', 'string', 'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment', 'group', 'access',
671+
jessie: ['number', 'string', 'assign', 'logical', 'bit', 'cmp', 'equality', 'arithmetic', 'increment', 'seq', 'group', 'access',
670672
'comment', 'identity', 'nullish', 'pow', 'unary', 'literal', 'ternary', 'arrow', 'spread', 'optional',
671673
'collection', 'template', 'regex', 'block', 'var', 'function', 'destruct', 'if', 'loop', 'try', 'switch', 'asi'],
672674
// Full: all features

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
],
3030
"scripts": {
3131
"build": "esbuild subscript.js --bundle --minify --format=esm --outfile=subscript.min.js && esbuild justin.js --bundle --minify --format=esm --outfile=justin.min.js && esbuild jessie.js --bundle --minify --format=esm --outfile=jessie.min.js",
32-
"prepublishOnly": "npm run build",
32+
"prepublishOnly": "npm run build && npm run test:e2e",
3333
"test": "node --import ./test/https-loader.js test/test.js",
34+
"test:e2e": "npx playwright test test/index.spec.js",
3435
"check-types": "tsc --noEmit subscript.d.ts"
3536
},
3637
"repository": {

subscript.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import './feature/op/equality.js'; // == !=
2424
import './feature/op/arithmetic.js'; // + - * / %
2525
import './feature/op/increment.js'; // ++ --
2626

27-
import './feature/group.js'; // Grouping: (a), sequences: a, b; a; b
27+
import './feature/seq.js'; // Sequences: a, b; a; b
28+
import './feature/group.js'; // Grouping: (a)
2829
import './feature/access.js'; // Property access: a.b, a[b], f(), [a,b]
2930

3031
import { parse, compile } from './parse.js';

0 commit comments

Comments
 (0)