tagset-parser 0.0.0 → 1.0.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.
@@ -5,7 +5,6 @@ import { SetDeclContext } from "./TagSetParser.js";
5
5
  import { LabelPartContext } from "./TagSetParser.js";
6
6
  import { ItemDeclContext } from "./TagSetParser.js";
7
7
  import { SugarDeclContext } from "./TagSetParser.js";
8
- import { PatternContext } from "./TagSetParser.js";
9
8
  import { ValueListContext } from "./TagSetParser.js";
10
9
  import { ValueItemContext } from "./TagSetParser.js";
11
10
  /**
@@ -73,16 +72,6 @@ export declare class TagSetListener implements ParseTreeListener {
73
72
  * @param ctx the parse tree
74
73
  */
75
74
  exitSugarDecl?: (ctx: SugarDeclContext) => void;
76
- /**
77
- * Enter a parse tree produced by `TagSetParser.pattern`.
78
- * @param ctx the parse tree
79
- */
80
- enterPattern?: (ctx: PatternContext) => void;
81
- /**
82
- * Exit a parse tree produced by `TagSetParser.pattern`.
83
- * @param ctx the parse tree
84
- */
85
- exitPattern?: (ctx: PatternContext) => void;
86
75
  /**
87
76
  * Enter a parse tree produced by `TagSetParser.valueList`.
88
77
  * @param ctx the parse tree
@@ -4,11 +4,11 @@ import { TagSetVisitor } from "./TagSetVisitor.js";
4
4
  export declare class TagSetParser extends antlr.Parser {
5
5
  static readonly SET = 1;
6
6
  static readonly ITEM = 2;
7
- static readonly AMP = 3;
8
- static readonly COMMA = 4;
9
- static readonly COLON = 5;
10
- static readonly QUOTED_STRING = 6;
11
- static readonly WORD = 7;
7
+ static readonly COMMA = 3;
8
+ static readonly COLON = 4;
9
+ static readonly QUOTED_STRING = 5;
10
+ static readonly WORD = 6;
11
+ static readonly COMMENT = 7;
12
12
  static readonly NL = 8;
13
13
  static readonly WS = 9;
14
14
  static readonly RULE_program = 0;
@@ -17,9 +17,8 @@ export declare class TagSetParser extends antlr.Parser {
17
17
  static readonly RULE_labelPart = 3;
18
18
  static readonly RULE_itemDecl = 4;
19
19
  static readonly RULE_sugarDecl = 5;
20
- static readonly RULE_pattern = 6;
21
- static readonly RULE_valueList = 7;
22
- static readonly RULE_valueItem = 8;
20
+ static readonly RULE_valueList = 6;
21
+ static readonly RULE_valueItem = 7;
23
22
  static readonly literalNames: (string | null)[];
24
23
  static readonly symbolicNames: (string | null)[];
25
24
  static readonly ruleNames: string[];
@@ -36,7 +35,6 @@ export declare class TagSetParser extends antlr.Parser {
36
35
  labelPart(): LabelPartContext;
37
36
  itemDecl(): ItemDeclContext;
38
37
  sugarDecl(): SugarDeclContext;
39
- pattern(): PatternContext;
40
38
  valueList(): ValueListContext;
41
39
  valueItem(): ValueItemContext;
42
40
  static readonly _serializedATN: number[];
@@ -92,7 +90,7 @@ export declare class LabelPartContext extends antlr.ParserRuleContext {
92
90
  export declare class ItemDeclContext extends antlr.ParserRuleContext {
93
91
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
94
92
  ITEM(): antlr.TerminalNode;
95
- pattern(): PatternContext;
93
+ WORD(): antlr.TerminalNode;
96
94
  valueList(): ValueListContext;
97
95
  get ruleIndex(): number;
98
96
  enterRule(listener: TagSetListener): void;
@@ -112,17 +110,6 @@ export declare class SugarDeclContext extends antlr.ParserRuleContext {
112
110
  exitRule(listener: TagSetListener): void;
113
111
  accept<Result>(visitor: TagSetVisitor<Result>): Result | null;
114
112
  }
115
- export declare class PatternContext extends antlr.ParserRuleContext {
116
- constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
117
- WORD(): antlr.TerminalNode[];
118
- WORD(i: number): antlr.TerminalNode | null;
119
- AMP(): antlr.TerminalNode[];
120
- AMP(i: number): antlr.TerminalNode | null;
121
- get ruleIndex(): number;
122
- enterRule(listener: TagSetListener): void;
123
- exitRule(listener: TagSetListener): void;
124
- accept<Result>(visitor: TagSetVisitor<Result>): Result | null;
125
- }
126
113
  export declare class ValueListContext extends antlr.ParserRuleContext {
127
114
  constructor(parent: antlr.ParserRuleContext | null, invokingState: number);
128
115
  valueItem(): ValueItemContext[];
@@ -5,7 +5,6 @@ import { SetDeclContext } from "./TagSetParser.js";
5
5
  import { LabelPartContext } from "./TagSetParser.js";
6
6
  import { ItemDeclContext } from "./TagSetParser.js";
7
7
  import { SugarDeclContext } from "./TagSetParser.js";
8
- import { PatternContext } from "./TagSetParser.js";
9
8
  import { ValueListContext } from "./TagSetParser.js";
10
9
  import { ValueItemContext } from "./TagSetParser.js";
11
10
  /**
@@ -52,12 +51,6 @@ export declare class TagSetVisitor<Result> extends AbstractParseTreeVisitor<Resu
52
51
  * @return the visitor result
53
52
  */
54
53
  visitSugarDecl?: (ctx: SugarDeclContext) => Result;
55
- /**
56
- * Visit a parse tree produced by `TagSetParser.pattern`.
57
- * @param ctx the parse tree
58
- * @return the visitor result
59
- */
60
- visitPattern?: (ctx: PatternContext) => Result;
61
54
  /**
62
55
  * Visit a parse tree produced by `TagSetParser.valueList`.
63
56
  * @param ctx the parse tree
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tagset-parser",
3
- "version": "0.0.0",
3
+ "version": "1.0.0",
4
4
  "description": "TagSet DSL parser",
5
5
  "author": "elzup",
6
6
  "license": "MIT",
@@ -28,6 +28,23 @@
28
28
  "engines": {
29
29
  "node": ">=18"
30
30
  },
31
+ "packageManager": "pnpm@9.15.4",
32
+ "scripts": {
33
+ "generate": "antlr-ng -Dlanguage=TypeScript --generate-visitor -o src/generated src/grammar/TagSet.g4",
34
+ "clean": "rimraf lib",
35
+ "build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types",
36
+ "build:cjs": "tsc --module commonjs --outDir lib/cjs && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
37
+ "build:esm": "tsc --module esnext --outDir lib/esm --moduleResolution node --allowSyntheticDefaultImports",
38
+ "build:types": "tsc --declaration --emitDeclarationOnly --outDir lib/types",
39
+ "format": "prettier --write .",
40
+ "lint": "oxlint --ignore-pattern src/generated/",
41
+ "lint:fix": "oxlint --fix --ignore-pattern src/generated/",
42
+ "test": "vitest run",
43
+ "test:watch": "vitest",
44
+ "test:ui": "vitest --ui",
45
+ "test:cov": "vitest run --coverage",
46
+ "prepublishOnly": "npm run build && npm test"
47
+ },
31
48
  "files": [
32
49
  "lib/"
33
50
  ],
@@ -46,20 +63,5 @@
46
63
  },
47
64
  "dependencies": {
48
65
  "antlr4ng": "^3.0.16"
49
- },
50
- "scripts": {
51
- "generate": "antlr-ng -Dlanguage=TypeScript --generate-visitor -o src/generated src/grammar/TagSet.g4",
52
- "clean": "rimraf lib",
53
- "build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:types",
54
- "build:cjs": "tsc --module commonjs --outDir lib/cjs && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
55
- "build:esm": "tsc --module esnext --outDir lib/esm --moduleResolution node --allowSyntheticDefaultImports",
56
- "build:types": "tsc --declaration --emitDeclarationOnly --outDir lib/types",
57
- "format": "prettier --write .",
58
- "lint": "oxlint --ignore-pattern src/generated/",
59
- "lint:fix": "oxlint --fix --ignore-pattern src/generated/",
60
- "test": "vitest run",
61
- "test:watch": "vitest",
62
- "test:ui": "vitest --ui",
63
- "test:cov": "vitest run --coverage"
64
66
  }
65
- }
67
+ }
package/readme.md CHANGED
@@ -8,36 +8,84 @@
8
8
  $ npm install tagset-parser
9
9
  ```
10
10
 
11
- ## Usage
11
+ ## DSL Examples
12
12
 
13
- ```ts
14
- import { parse } from 'tagset-parser'
13
+ ### Basic
15
14
 
16
- // Classic syntax
17
- const ast = parse(`set A 赤
15
+ ```
16
+ set A 赤
18
17
  set B 青
19
- item A&B x,c`)
20
18
 
21
- // Sugar syntax (colon)
22
- const ast2 = parse(`A, B: x, y`)
19
+ item A apple, red
20
+ item B sky, ocean
21
+ # colon syntax (both syntaxes can be mixed freely)
22
+ A, B: purple, violet
23
+ A, B, _: purple, violet
24
+ ```
25
+
26
+ ### Auto-Detect Sets
23
27
 
24
- // Auto-detect sets (no set declarations needed)
25
- const ast3 = parse(`item A&B x`)
26
- // ast3.sets → [{ id: 'A', label: 'A', index: 0 }, { id: 'B', label: 'B', index: 1 }]
28
+ `set` declarations are optional. Sets are auto-detected from patterns.
29
+
30
+ ```
31
+ A: apple
32
+ B: sky
33
+ A, B: purple
27
34
  ```
28
35
 
29
- ## Syntax
36
+ Explicit and auto-detected sets can coexist — `set A Red` gives A a label, while B is auto-detected as `{ id: 'B', label: 'B' }`.
37
+
38
+ ### Placeholder `_`
39
+
40
+ `_` is ignored in patterns, useful for alignment.
30
41
 
31
42
  ```
32
- set <id> <label> # Declare a set (optional)
33
- item <pattern> <values> # Declare an item with & pattern
34
- <ids>: <values> # Sugar syntax (comma-separated IDs)
43
+ A, _, C: a-and-c
44
+ _, B, _: only-b
35
45
  ```
36
46
 
37
- - `set` declarations are optional; sets are auto-detected from patterns
38
- - Patterns use `&` between set IDs: `A&B`, `A&_&C`
39
- - `_` is a placeholder (ignored in bitmask)
40
- - Values are comma-separated: `x,y` or `x, y`
47
+ ### Quoted Strings
48
+
49
+ ```
50
+ item A "hello world", "foo bar"
51
+ ```
52
+
53
+ ## Bitmask
54
+
55
+ Each item gets a `bitmask` based on which sets appear in its pattern. Set index determines the bit position.
56
+
57
+ ```
58
+ set A 赤 → index 0 → bit 1
59
+ set B 青 → index 1 → bit 2
60
+ set C 緑 → index 2 → bit 4
61
+
62
+ A: → bitmask: 1 (0b001)
63
+ B: → bitmask: 2 (0b010)
64
+ A, C: → bitmask: 5 (0b101)
65
+ A, B, C: → bitmask: 7 (0b111)
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ ```ts
71
+ import { parse } from 'tagset-parser'
72
+
73
+ const ast = parse(`
74
+ set A 赤
75
+ set B 青
76
+ A, B: x, y
77
+ A: solo
78
+ `)
79
+
80
+ ast.sets
81
+ // [{ id: 'A', label: '赤', index: 0 }, { id: 'B', label: '青', index: 1 }]
82
+
83
+ ast.items
84
+ // [
85
+ // { pattern: 'A,B', bitmask: 3, values: ['x', 'y'] },
86
+ // { pattern: 'A', bitmask: 1, values: ['solo'] },
87
+ // ]
88
+ ```
41
89
 
42
90
  ## License
43
91