@anteriorai/srg-grammar 0.5.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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ # License
2
+
3
+ Copyright © 2026 Anterior. All rights reserved.
4
+
5
+ This package is made publicly available for inspection and research discussion only.
6
+
7
+ No license is granted to use, modify, merge, publish, distribute, sublicense,
8
+ sell, deploy, or otherwise exploit this software, except for:
9
+
10
+ 1. internal use by Anterior employees, contractors, and authorized agents for
11
+ Anterior business purposes;
12
+ 2. temporary copies made strictly as necessary to inspect the package; or
13
+ 3. uses otherwise expressly authorized in writing by Anterior.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @anteriorai/srg-grammar
2
+
3
+ Tree-sitter grammar for the SRG (Symbolic Reasoning Graph) language.
4
+
5
+ The published package ships a pre-built `tree-sitter-srg.wasm` and `language-configuration.json` ready for direct use — you don't need the tree-sitter CLI to consume it.
6
+
7
+ > **Public preview.** This package is an early public release of Anterior's symbolic reasoning tooling.
8
+ > It is being published to support transparency, research discussion, and early experimentation while the broader open-source repository is prepared for release.
9
+ >
10
+ > Future releases may be made available under updated licensing terms. Until then, use of this package is governed by the license included with this release.
11
+ >
12
+ > This release should not be treated as a supported product, a stable API, or a complete reference implementation.
13
+ > It is provided "as is," without warranties of any kind. Users are responsible for evaluating correctness, security, compliance, and suitability for their own use case.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @anteriorai/srg-grammar
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```javascript
24
+ // Editor metadata (tokens, comments, brackets, etc.)
25
+ import languageConfigJson from '@anteriorai/srg-grammar/language-configuration.json';
26
+
27
+ console.log(languageConfigJson);
28
+ ```
29
+
30
+ ## Development
31
+
32
+ ### Generate the parser
33
+
34
+ ```bash
35
+ npm run build
36
+ ```
37
+
38
+ ### Run tests
39
+
40
+ ```bash
41
+ npm test
42
+ ```
43
+
44
+ ### Parse a file
45
+
46
+ ```bash
47
+ npm run parse your_file.srg
48
+ ```
49
+
50
+ ## Grammar
51
+
52
+ The SRG grammar supports:
53
+
54
+ - **Predicates**: `predicate id: "question"`
55
+ - **Outcomes**: `outcome id: "description"`
56
+ - **Aggregators**: `all()`, `any()`, `none()`, `atleast(n, ...)`, etc.
57
+ - **Named definitions**: `define name: expression`
58
+ - **Paths**: `root => aggregator1 => aggregator2 => ... => outcome`
59
+ - **Comments**: `# comment`
60
+
61
+ See the [grammar.js](./grammar.js) file for the complete specification.
package/grammar.js ADDED
@@ -0,0 +1,299 @@
1
+ /**
2
+ * Tree-sitter grammar for SRG v2
3
+ *
4
+ * Defines the syntax for Symbolic Reasoning Graph language:
5
+ * - predicates: predicate id: "question"
6
+ * - outcomes: outcome id: "description"
7
+ * - named aggregators: define id: expression
8
+ * - citations: citation id { ... }
9
+ * - named paths: path id: expr => outcome
10
+ *
11
+ * All components support common properties:
12
+ * - label: "human readable label"
13
+ * - doc: "human readable documentation"
14
+ * - cite: citation_id or [citation_id1, citation_id2]
15
+ * - context: "additional context"
16
+ * - metadata: { ... }
17
+ */
18
+
19
+ module.exports = grammar({
20
+ name: 'srg',
21
+
22
+ extras: $ => [
23
+ /\s/, // whitespace
24
+ $.comment // comments
25
+ ],
26
+
27
+ rules: {
28
+ source_file: $ => repeat($._definition),
29
+
30
+ _definition: $ => choice(
31
+ $.predicate_definition,
32
+ $.outcome_definition,
33
+ $.aggregator_definition,
34
+ $.citation_definition,
35
+ $.path,
36
+ $.comment
37
+ ),
38
+
39
+ comment: $ => token(seq('#', /.*/)),
40
+
41
+ predicate_definition: $ => seq(
42
+ 'predicate',
43
+ field('id', $.identifier),
44
+ ':',
45
+ field('question', $.string),
46
+ repeat($._predicate_property)
47
+ ),
48
+
49
+ outcome_definition: $ => seq(
50
+ 'outcome',
51
+ field('id', $.identifier),
52
+ ':',
53
+ field('description', $.string),
54
+ repeat($._common_property)
55
+ ),
56
+
57
+ aggregator_definition: $ => seq(
58
+ 'define',
59
+ field('id', $.identifier),
60
+ ':',
61
+ field('expression', $.expression),
62
+ repeat($._common_property)
63
+ ),
64
+
65
+ citation_definition: $ => seq(
66
+ 'citation',
67
+ field('id', $.identifier),
68
+ ':',
69
+ $.property_block
70
+ ),
71
+
72
+ // Common properties that can be attached to any component (except predicates which have additional properties)
73
+ _common_property: $ => choice(
74
+ $.label_property,
75
+ $.doc_property,
76
+ $.cite_property,
77
+ $.metadata_property
78
+ ),
79
+
80
+ // Predicate-specific properties (all common properties + context)
81
+ _predicate_property: $ => choice(
82
+ $._common_property,
83
+ $.context_property
84
+ ),
85
+
86
+ label_property: $ => seq(
87
+ 'label',
88
+ ':',
89
+ field('value', $.string)
90
+ ),
91
+
92
+ doc_property: $ => seq(
93
+ 'doc',
94
+ ':',
95
+ field('value', $.string)
96
+ ),
97
+
98
+ cite_property: $ => seq(
99
+ 'cite',
100
+ ':',
101
+ choice(
102
+ field('citation', $.identifier),
103
+ $.citation_array
104
+ )
105
+ ),
106
+
107
+ citation_array: $ => seq(
108
+ '[',
109
+ field('citation', $.identifier),
110
+ repeat(seq(',', field('citation', $.identifier))),
111
+ optional(','),
112
+ ']'
113
+ ),
114
+
115
+ context_property: $ => seq(
116
+ 'context',
117
+ ':',
118
+ field('value', $.string)
119
+ ),
120
+
121
+ metadata_property: $ => seq(
122
+ 'metadata',
123
+ ':',
124
+ $.property_block
125
+ ),
126
+
127
+ property_block: $ => seq(
128
+ '{',
129
+ optional(seq(
130
+ $.property,
131
+ repeat(seq(optional(','), $.property)),
132
+ optional(',')
133
+ )),
134
+ '}'
135
+ ),
136
+
137
+ property: $ => seq(
138
+ field('key', $.identifier),
139
+ ':',
140
+ field('value', $.property_value)
141
+ ),
142
+
143
+ property_value: $ => choice(
144
+ $.string,
145
+ $.number,
146
+ $.boolean,
147
+ $.property_array,
148
+ $.property_object
149
+ ),
150
+
151
+ property_array: $ => seq(
152
+ '[',
153
+ optional(seq(
154
+ $.property_value,
155
+ repeat(seq(',', $.property_value)),
156
+ optional(',')
157
+ )),
158
+ ']'
159
+ ),
160
+
161
+ property_object: $ => seq(
162
+ '{',
163
+ optional(seq(
164
+ $.property,
165
+ repeat(seq(optional(','), $.property)),
166
+ optional(',')
167
+ )),
168
+ '}'
169
+ ),
170
+
171
+ boolean: $ => choice('true', 'false'),
172
+
173
+ // Supports chaining: expr => expr => ... => outcome
174
+ // Examples:
175
+ // path standard: root => all(p1, p2) => outcome1
176
+ // path simple: all(p1, p2) => any(p3, p4) => outcome1
177
+ path: $ => seq(
178
+ 'path',
179
+ field('id', $.identifier),
180
+ ':',
181
+ field('step', $.expression),
182
+ repeat(seq('=>', field('step', $.expression))),
183
+ '=>',
184
+ field('outcome', $.identifier),
185
+ repeat($._common_property)
186
+ ),
187
+
188
+ expression: $ => choice(
189
+ $.reference,
190
+ $.all_expression,
191
+ $.any_expression,
192
+ $.none_expression,
193
+ $.atleast_expression,
194
+ $.atmost_expression,
195
+ $.exactly_expression,
196
+ $.not_expression
197
+ ),
198
+
199
+ // Reference to predicate or named aggregator
200
+ reference: $ => $.identifier,
201
+
202
+ all_expression: $ => seq(
203
+ 'all',
204
+ '(',
205
+ optional($.argument_list),
206
+ ')'
207
+ ),
208
+
209
+ any_expression: $ => seq(
210
+ 'any',
211
+ '(',
212
+ optional($.argument_list),
213
+ ')'
214
+ ),
215
+
216
+ none_expression: $ => seq(
217
+ 'none',
218
+ '(',
219
+ optional($.argument_list),
220
+ ')'
221
+ ),
222
+
223
+ atleast_expression: $ => seq(
224
+ 'atleast',
225
+ '(',
226
+ field('count', $.number),
227
+ ',',
228
+ $.argument_list,
229
+ ')'
230
+ ),
231
+
232
+ atmost_expression: $ => seq(
233
+ 'atmost',
234
+ '(',
235
+ field('count', $.number),
236
+ ',',
237
+ $.argument_list,
238
+ ')'
239
+ ),
240
+
241
+ exactly_expression: $ => seq(
242
+ 'exactly',
243
+ '(',
244
+ field('count', $.number),
245
+ ',',
246
+ $.argument_list,
247
+ ')'
248
+ ),
249
+
250
+ not_expression: $ => seq(
251
+ 'not',
252
+ '(',
253
+ field('expr', $.expression),
254
+ ')'
255
+ ),
256
+
257
+ argument_list: $ => seq(
258
+ $.expression,
259
+ repeat(seq(',', $.expression))
260
+ ),
261
+
262
+ identifier: $ => /[A-Za-z_][A-Za-z0-9_]*/,
263
+
264
+ number: $ => choice(
265
+ /\d+\.\d+/, // float (must come first for precedence)
266
+ /\d+/ // integer
267
+ ),
268
+
269
+ // Supports both regular and triple-quoted strings
270
+ string: $ => choice(
271
+ seq(
272
+ '"',
273
+ repeat(choice(
274
+ token.immediate(prec(1, /[^"\\]+/)),
275
+ $.escape_sequence
276
+ )),
277
+ '"'
278
+ ),
279
+ seq(
280
+ '"""',
281
+ repeat(choice(
282
+ token.immediate(prec(1, /[^"\\]+/)),
283
+ $.escape_sequence,
284
+ '"'
285
+ )),
286
+ '"""'
287
+ )
288
+ ),
289
+
290
+ escape_sequence: $ => token.immediate(seq(
291
+ '\\',
292
+ choice(
293
+ /[\\'"nrt]/,
294
+ /u[0-9a-fA-F]{4}/,
295
+ /U[0-9a-fA-F]{8}/
296
+ )
297
+ ))
298
+ }
299
+ });
@@ -0,0 +1,64 @@
1
+ {
2
+ "$schema": "https://code.visualstudio.com/schemas/language-configuration",
3
+ "comments": {
4
+ "lineComment": "#"
5
+ },
6
+ "brackets": [
7
+ ["{", "}"],
8
+ ["[", "]"],
9
+ ["(", ")"]
10
+ ],
11
+ "autoClosingPairs": [
12
+ { "open": "{", "close": "}" },
13
+ { "open": "[", "close": "]" },
14
+ { "open": "(", "close": ")" },
15
+ { "open": "\"", "close": "\"", "notIn": ["string"] }
16
+ ],
17
+ "surroundingPairs": [
18
+ ["{", "}"],
19
+ ["[", "]"],
20
+ ["(", ")"],
21
+ ["\"", "\""]
22
+ ],
23
+ "folding": {
24
+ "markers": {
25
+ "start": "^\\s*#region\\b",
26
+ "end": "^\\s*#endregion\\b"
27
+ }
28
+ },
29
+ "wordPattern": "(-?\\d*\\.\\d\\w*)|([^\\`\\~\\!\\@\\#\\%\\^\\&\\*\\(\\)\\-\\=\\+\\[\\{\\]\\}\\\\\\|\\;\\:\\'\\\"\\,\\.\\<\\>\\/\\?\\s]+)",
30
+
31
+ "_metadata": {
32
+ "description": "Language metadata for tooling (Monaco, LSP, etc.)",
33
+ "version": "1.0.0",
34
+
35
+ "tokens": {
36
+ "keyword": ["predicate", "outcome", "define", "citation", "path"],
37
+ "function.builtin": ["all", "any", "none", "not", "atleast", "atmost", "exactly"],
38
+ "constant.language": ["true", "false"],
39
+ "operator": ["=>", ":"],
40
+ "property": [
41
+ "label", "doc", "cite", "context", "metadata",
42
+ "source_ref", "filename", "regions", "excerpt", "page", "box"
43
+ ]
44
+ },
45
+
46
+ "schemas": {
47
+ "citation": {
48
+ "description": "Citation block properties",
49
+ "properties": ["source_ref", "filename", "regions", "excerpt", "page", "box", "context"],
50
+ "required": ["source_ref"]
51
+ },
52
+ "metadata": {
53
+ "description": "Common metadata keys for user-defined metadata blocks",
54
+ "commonKeys": ["version", "author", "date", "tags", "priority", "category"]
55
+ }
56
+ },
57
+
58
+ "editor": {
59
+ "extensions": [".srg"],
60
+ "defaultMimeType": "text/x-srg"
61
+ }
62
+ }
63
+ }
64
+
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@anteriorai/srg-grammar",
3
+ "version": "0.5.1",
4
+ "private": false,
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "description": "Tree-sitter grammar for SRG (Symbolic Reasoning Graph) language",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "exports": {
11
+ "./language-configuration.json": "./language-configuration.json"
12
+ },
13
+ "files": [
14
+ "grammar.js",
15
+ "tree-sitter-srg.wasm",
16
+ "queries",
17
+ "language-configuration.json",
18
+ "README.md"
19
+ ],
20
+ "keywords": [
21
+ "tree-sitter",
22
+ "parser",
23
+ "srg",
24
+ "wasm",
25
+ "grammar"
26
+ ],
27
+ "engines": {
28
+ "node": ">=24.0.0"
29
+ },
30
+ "scripts": {
31
+ "build": "tree-sitter generate && tree-sitter build --wasm",
32
+ "prepack": "npm run build",
33
+ "test": "tree-sitter test",
34
+ "parse": "tree-sitter parse"
35
+ },
36
+ "tree-sitter": [
37
+ {
38
+ "scope": "source.srg",
39
+ "file-types": [
40
+ "srg"
41
+ ],
42
+ "highlights": [
43
+ "queries/highlights.scm"
44
+ ]
45
+ }
46
+ ],
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/anteriorai/symbolic-reasoning.git",
50
+ "directory": "packages/srg-grammar"
51
+ }
52
+ }
@@ -0,0 +1,58 @@
1
+ ; Syntax highlighting queries for SRG
2
+
3
+ ; Keywords
4
+ [
5
+ "predicate"
6
+ "outcome"
7
+ "define"
8
+ "true"
9
+ "false"
10
+ ] @keyword
11
+
12
+ ; Aggregator functions
13
+ [
14
+ "all"
15
+ "any"
16
+ "none"
17
+ "atleast"
18
+ "atmost"
19
+ "exactly"
20
+ "not"
21
+ ] @function.builtin
22
+
23
+ ; Operators
24
+ "=>" @operator
25
+ ":" @punctuation.delimiter
26
+ "," @punctuation.delimiter
27
+
28
+ ; Brackets
29
+ ["(" ")" "[" "]" "{" "}"] @punctuation.bracket
30
+
31
+ ; Component definitions - these get special colors when being defined
32
+ (predicate_definition id: (identifier) @function)
33
+ (outcome_definition id: (identifier) @type)
34
+ (aggregator_definition id: (identifier) @variable.parameter)
35
+
36
+ ; Component references - references to predicates/aggregators
37
+ (reference (identifier) @variable)
38
+
39
+ ; Outcome references (right side of =>)
40
+ (path outcome: (identifier) @type)
41
+
42
+ ; Property keys in property blocks
43
+ (property key: (identifier) @property)
44
+
45
+ ; Booleans
46
+ (boolean) @boolean
47
+
48
+ ; Numbers
49
+ (number) @number
50
+
51
+ ; Strings
52
+ (string) @string
53
+
54
+ ; Escape sequences
55
+ (escape_sequence) @string.escape
56
+
57
+ ; Comments
58
+ (comment) @comment
Binary file