expressir 2.4.47-aarch64-linux → 2.4.49-aarch64-linux
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.
- checksums.yaml +4 -4
- data/docs/_guides/reference/grammar-crosswalk.adoc +1 -0
- data/expressir.gemspec +1 -1
- data/grammar-parg/CONVENTIONS.md +90 -0
- data/grammar-parg/RULE-INVENTORY.txt +252 -0
- data/grammar-parg/atoms_to_parg.rb +232 -0
- data/grammar-parg/bisect.sh +37 -0
- data/grammar-parg/ddmin.sh +39 -0
- data/grammar-parg/dsl-dump.json +1 -0
- data/grammar-parg/entries.parg.frag +12 -0
- data/grammar-parg/express-grammar.artifact.json +1 -0
- data/grammar-parg/express-grammar.parg +381 -0
- data/grammar-parg/express.json +1 -0
- data/grammar-parg/express.parg +57 -0
- data/grammar-parg/express_keywords.parg +132 -0
- data/grammar-parg/express_literals.parg +14 -0
- data/grammar-parg/express_operators.parg +34 -0
- data/grammar-parg/express_remarks.parg +19 -0
- data/grammar-parg/express_structure.parg +11 -0
- data/grammar-parg/generate-terminals.rb +55 -0
- data/grammar-parg/keywords.parg.frag +130 -0
- data/grammar-parg/literals.parg.frag +9 -0
- data/grammar-parg/operators.parg.frag +34 -0
- data/grammar-parg/parity-model.rb +68 -0
- data/grammar-parg/parity-vm.rb +60 -0
- data/grammar-parg/parity.sh +66 -0
- data/grammar-parg/parser-dsl-reference.rb.txt +757 -0
- data/grammar-parg/splice.rb +16 -0
- data/grammar-parg/tree_diff.rb +62 -0
- data/lib/expressir/express/grammar/express-grammar.artifact.json +1 -0
- data/lib/expressir/express/grammar/parser.rb +55 -1
- data/lib/expressir/express/parser.rb +3 -3
- data/lib/expressir/express/remark_attacher.rb +4 -2
- data/lib/expressir/model/model_element.rb +3 -0
- data/lib/expressir/reference/grammar_crosswalk.yml +3 -0
- data/lib/expressir/version.rb +1 -1
- metadata +31 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2e71cda146f7f97ffc2bcafa4a30f67e4261b0ecf7981270bd1bdba5f70c753
|
|
4
|
+
data.tar.gz: 77d10c63f0c17288bb8e8e7b7285ca2800821eb0726d692cf9a8c8e7d879ecb8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 912021286eea062a6968d4517ae148de3e3d9e3f035b179bf7f8fda756f5df6d001186706576a5263eff4408666066ce7af07646b11e6adca583f234718dc4eb
|
|
7
|
+
data.tar.gz: d3fc741661b7d4e232a0bafed10f23c45932f82aa4cf0350b9054fb50ee50eab134a3ede98a06bc26ea417bb5fec1a1f5a693a929088bb7245ea9ceb2d8fc0c9
|
|
@@ -230,6 +230,7 @@ grammar are classified with one of these statuses:
|
|
|
230
230
|
| `simpleFactorExpression` | simple_factor | decomposed |
|
|
231
231
|
| `simpleFactorUnaryExpression` | simple_factor | decomposed |
|
|
232
232
|
| `simpleId` | simple_id | aligned |
|
|
233
|
+
| `unguardedId` | simple_id | aligned |
|
|
233
234
|
| `simpleStringLiteral` | simple_string_literal | aligned |
|
|
234
235
|
| `simpleTypes` | simple_types | aligned |
|
|
235
236
|
| `skipStmt` | skip_stmt | aligned |
|
data/expressir.gemspec
CHANGED
|
@@ -53,7 +53,7 @@ Gem::Specification.new do |spec|
|
|
|
53
53
|
spec.add_dependency "lutaml-model", "~> 0.8.156"
|
|
54
54
|
spec.add_dependency "moxml", "~> 0.6.0"
|
|
55
55
|
spec.add_dependency "paint"
|
|
56
|
-
spec.add_dependency "parsanol", "~> 1.3.
|
|
56
|
+
spec.add_dependency "parsanol", "~> 1.3.123"
|
|
57
57
|
spec.add_dependency "ruby-progressbar", "~> 1.11"
|
|
58
58
|
spec.add_dependency "rubyzip", "~> 3.7"
|
|
59
59
|
spec.add_dependency "table_tennis"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# DSL → PARG edition-2 migration conventions
|
|
2
|
+
|
|
3
|
+
The authoritative edition-2 authoring reference is pubid's own grammar
|
|
4
|
+
fleet (pubid-grammar/grammars/*.parg) — working `edition 2` files with
|
|
5
|
+
the migration idioms documented in their headers. This file pins the
|
|
6
|
+
expressir-specific mapping and the parity-critical surfaces.
|
|
7
|
+
|
|
8
|
+
## Header
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
grammar ExpressSyntax version "0.1.0" edition 2 {
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## DSL → PARG mapping (verified against parsanol 1.3.120's frontend)
|
|
15
|
+
|
|
16
|
+
| DSL | PARG |
|
|
17
|
+
|---|---|
|
|
18
|
+
| `str("x")` | `"x"` |
|
|
19
|
+
| `match[/re/]` (char class) | `%xNN-NN` / `%xNN` classes, or literals |
|
|
20
|
+
| `a >> b` | juxtaposition: `a b` |
|
|
21
|
+
| `a \| b` | `a / b` (ordered choice) |
|
|
22
|
+
| `.maybe` | `[a]` |
|
|
23
|
+
| `.repeat(1)` / `.repeat` | `1*a` / `*a` |
|
|
24
|
+
| `.repeat(m, n)` | `m*n a` |
|
|
25
|
+
| `.as(:name)` | `(...) as name` |
|
|
26
|
+
| `rule(:x)` (capturing body) | `x = { ... }` brace rule |
|
|
27
|
+
| `rule(:x) { simple }` | `x = ...` |
|
|
28
|
+
| `skip(:trivia, whitespace: :space, exempt: [...])` | `skip = trivia capture: space` + `atomic <name> = ...` per exempt rule |
|
|
29
|
+
| lookahead/behind | `!a` / ¬(behind) — PARG rejects some constructs NAMING them |
|
|
30
|
+
|
|
31
|
+
## Edition-2 capture discipline (from pubid's fleet, cen_cenelec.parg header)
|
|
32
|
+
|
|
33
|
+
> Every reference inside a captured body is inlined to raw terms (a rule
|
|
34
|
+
> reference materializes as a named node in the edition-2 tree, so only a
|
|
35
|
+
> raw capture binds a scalar span); references to rules that themselves
|
|
36
|
+
> capture float their captures unchanged. Repetition wrappers keep the
|
|
37
|
+
> v1 tree shape and the bindings name the scalar leaves.
|
|
38
|
+
|
|
39
|
+
Consequence for the translation: a `.as` on a rule REFERENCE does not
|
|
40
|
+
bind a span in v2 — either inline the referenced body or bind the leaf
|
|
41
|
+
literals directly. The corpus parity loop (Step 1 of issue #578) is the
|
|
42
|
+
referee for every one of these decisions.
|
|
43
|
+
|
|
44
|
+
## Parity-critical surfaces (do not translate mechanically)
|
|
45
|
+
|
|
46
|
+
1. **Trivia injection + exemptions**: the DSL's `skip(:trivia, exempt:
|
|
47
|
+
%i[simpleId digits spaces space embeddedRemark tailRemark])` encodes
|
|
48
|
+
parsanol-ruby#195's token-boundary semantics — PARG's `atomic`
|
|
49
|
+
declarations must reproduce the exact exemption set, or multi-token
|
|
50
|
+
rules glue ("RULE r FOR" → one simpleId).
|
|
51
|
+
2. **Remarks are product data**: tailRemark/embeddedRemark manage their
|
|
52
|
+
own trivia end to end; RemarkScanner attaches them backward. They stay
|
|
53
|
+
OUT of the skip declaration.
|
|
54
|
+
3. **Fresh-parse thresholds** are runtime strategy, not grammar — they
|
|
55
|
+
stay on the engine facade.
|
|
56
|
+
|
|
57
|
+
## Toolchain loop
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
parsanol parg compile express.parg -o express.json # + tables dir beside
|
|
61
|
+
parsanol parg test express.json # the grammar's own accepts
|
|
62
|
+
parsanol parg check --source express.parg --artifact express.json
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Compile requires the full `use` closure in one directory (pubid bake
|
|
66
|
+
finding).
|
|
67
|
+
|
|
68
|
+
## Language facts learned while translating (parsanol 1.3.120/1.3.121)
|
|
69
|
+
|
|
70
|
+
- Parenthesized groups do NOT span newlines — multi-line rule bodies use
|
|
71
|
+
the brace-block form (`rule = { ... }`), with the `as` inside.
|
|
72
|
+
- Self-references inside a grammar file are UNQUALIFIED; a qualified
|
|
73
|
+
self-reference gets double-namespaced and fails.
|
|
74
|
+
- `use <grammar>` sections sit at TOP LEVEL (before the grammar block);
|
|
75
|
+
imports resolve by FILENAME; chained/transitive imports and duplicate-
|
|
76
|
+
import collision detection work.
|
|
77
|
+
- Entry targets must be LOCAL rules — alias imported rules and rebind
|
|
78
|
+
explicitly (`digits = (express_literals.digits) as digits`), or the
|
|
79
|
+
alias binds a namespaced tree key (a builder-parity trap).
|
|
80
|
+
- Backslash literals: the escaped form is rejected by the lexer — use
|
|
81
|
+
`%x5C`.
|
|
82
|
+
- The `test` section's `accept` runs against the DEFAULT entry only;
|
|
83
|
+
mid-migration probing uses declared entries instead.
|
|
84
|
+
|
|
85
|
+
- The skip rule must be NON-NULLABLE (`skip = trivia` with `1*`); the
|
|
86
|
+
compiler rejects nullable skips (injection loops on empty). Injection
|
|
87
|
+
itself is optional-before-every-terminal (parsanol-ruby#134) and
|
|
88
|
+
entries get leading/trailing maybe-skips automatically.
|
|
89
|
+
- The `parg parse` CLI uses the FIRST declared entry when `--entry` is
|
|
90
|
+
omitted — mid-migration probes must pass `--entry` explicitly.
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
[ ] trivia
|
|
2
|
+
[ ] sym
|
|
3
|
+
[ ] abstractEntityDeclaration
|
|
4
|
+
[ ] abstractSupertypeDeclaration
|
|
5
|
+
[ ] abstractSupertype
|
|
6
|
+
[ ] actualParameterList
|
|
7
|
+
[ ] addLikeOp
|
|
8
|
+
[ ] aggregateInitializer
|
|
9
|
+
[ ] aggregateSource
|
|
10
|
+
[ ] aggregateType
|
|
11
|
+
[ ] aggregationTypes
|
|
12
|
+
[ ] algorithmHead
|
|
13
|
+
[ ] aliasStmt
|
|
14
|
+
[ ] anyKeyword
|
|
15
|
+
[ ] arrayType
|
|
16
|
+
[ ] assignmentStmt
|
|
17
|
+
[ ] attributeDecl
|
|
18
|
+
[ ] attributeId
|
|
19
|
+
[ ] attributeQualifier
|
|
20
|
+
[ ] attributeRef
|
|
21
|
+
[ ] bagType
|
|
22
|
+
[ ] binaryLiteral
|
|
23
|
+
[ ] binaryType
|
|
24
|
+
[ ] bit
|
|
25
|
+
[ ] booleanType
|
|
26
|
+
[ ] bound1
|
|
27
|
+
[ ] bound2
|
|
28
|
+
[ ] boundSpec
|
|
29
|
+
[ ] builtInConstant
|
|
30
|
+
[ ] builtInFunction
|
|
31
|
+
[ ] builtInProcedure
|
|
32
|
+
[ ] caseAction
|
|
33
|
+
[ ] caseLabel
|
|
34
|
+
[ ] caseStmt
|
|
35
|
+
[ ] compoundStmt
|
|
36
|
+
[ ] concreteTypes
|
|
37
|
+
[ ] constantBody
|
|
38
|
+
[ ] constantDecl
|
|
39
|
+
[ ] constantFactor
|
|
40
|
+
[ ] constantId
|
|
41
|
+
[ ] constantRef
|
|
42
|
+
[ ] constructedTypes
|
|
43
|
+
[ ] declaration
|
|
44
|
+
[ ] delim
|
|
45
|
+
[ ] deriveClause
|
|
46
|
+
[ ] derivedAttr
|
|
47
|
+
[ ] digit
|
|
48
|
+
[ ] digits
|
|
49
|
+
[ ] domainRule
|
|
50
|
+
[ ] element
|
|
51
|
+
[ ] embeddedRemark
|
|
52
|
+
[ ] encodedCharacter
|
|
53
|
+
[ ] encodedStringLiteral
|
|
54
|
+
[ ] entityBody
|
|
55
|
+
[ ] entityConstructor
|
|
56
|
+
[ ] entityDecl
|
|
57
|
+
[ ] entityHead
|
|
58
|
+
[ ] entityId
|
|
59
|
+
[ ] entityHeaderTail
|
|
60
|
+
[ ] entityRef
|
|
61
|
+
[ ] enumerationExtension
|
|
62
|
+
[ ] enumerationId
|
|
63
|
+
[ ] enumerationItem
|
|
64
|
+
[ ] enumerationItems
|
|
65
|
+
[ ] enumerationRef
|
|
66
|
+
[ ] enumerationReference
|
|
67
|
+
[ ] enumerationType
|
|
68
|
+
[ ] escapeStmt
|
|
69
|
+
[ ] explicitAttr
|
|
70
|
+
[ ] expression
|
|
71
|
+
[ ] factor
|
|
72
|
+
[ ] formalParameter
|
|
73
|
+
[ ] functionCall
|
|
74
|
+
[ ] functionDecl
|
|
75
|
+
[ ] functionHead
|
|
76
|
+
[ ] functionId
|
|
77
|
+
[ ] functionRef
|
|
78
|
+
[ ] generalAggregationTypes
|
|
79
|
+
[ ] generalArrayType
|
|
80
|
+
[ ] generalBagType
|
|
81
|
+
[ ] generalizedTypes
|
|
82
|
+
[ ] generalListType
|
|
83
|
+
[ ] generalRef
|
|
84
|
+
[ ] generalSetType
|
|
85
|
+
[ ] genericEntityType
|
|
86
|
+
[ ] genericType
|
|
87
|
+
[ ] groupQualifier
|
|
88
|
+
[ ] hexDigit
|
|
89
|
+
[ ] ifStmtElseStatements
|
|
90
|
+
[ ] ifStmtStatements
|
|
91
|
+
[ ] ifStmt
|
|
92
|
+
[ ] incrementControl
|
|
93
|
+
[ ] increment
|
|
94
|
+
[ ] index1
|
|
95
|
+
[ ] index2
|
|
96
|
+
[ ] index
|
|
97
|
+
[ ] indexQualifier
|
|
98
|
+
[ ] instantiableType
|
|
99
|
+
[ ] integerLiteral
|
|
100
|
+
[ ] integerType
|
|
101
|
+
[ ] interfaceSpecification
|
|
102
|
+
[ ] intervalHigh
|
|
103
|
+
[ ] intervalItem
|
|
104
|
+
[ ] intervalLow
|
|
105
|
+
[ ] interval
|
|
106
|
+
[ ] intervalOp
|
|
107
|
+
[ ] inverseAttr
|
|
108
|
+
[ ] inverseAttrType
|
|
109
|
+
[ ] inverseClause
|
|
110
|
+
[ ] letter
|
|
111
|
+
[ ] listType
|
|
112
|
+
[ ] literal
|
|
113
|
+
[ ] localDecl
|
|
114
|
+
[ ] localVariable
|
|
115
|
+
[ ] logicalExpression
|
|
116
|
+
[ ] logicalLiteral
|
|
117
|
+
[ ] logicalType
|
|
118
|
+
[ ] multiplicationLikeOp
|
|
119
|
+
[ ] namedTypeOrRename
|
|
120
|
+
[ ] namedTypes
|
|
121
|
+
[ ] nullStmt
|
|
122
|
+
[ ] numberType
|
|
123
|
+
[ ] numericExpression
|
|
124
|
+
[ ] octet
|
|
125
|
+
[ ] oneOf
|
|
126
|
+
[ ] op_asterisk
|
|
127
|
+
[ ] op_colon
|
|
128
|
+
[ ] op_colon_equals_colon
|
|
129
|
+
[ ] op_colon_less_greater_colon
|
|
130
|
+
[ ] op_comma
|
|
131
|
+
[ ] op_decl
|
|
132
|
+
[ ] op_delim
|
|
133
|
+
[ ] op_double_asterisk
|
|
134
|
+
[ ] op_double_backslash
|
|
135
|
+
[ ] op_double_pipe
|
|
136
|
+
[ ] op_equals
|
|
137
|
+
[ ] op_greater_equal
|
|
138
|
+
[ ] op_greater_than
|
|
139
|
+
[ ] op_leftbracket
|
|
140
|
+
[ ] op_left_curly_brace
|
|
141
|
+
[ ] op_leftparen
|
|
142
|
+
[ ] op_less_equal
|
|
143
|
+
[ ] op_less_greater
|
|
144
|
+
[ ] op_less_than
|
|
145
|
+
[ ] op_minus
|
|
146
|
+
[ ] op_period
|
|
147
|
+
[ ] op_pipe
|
|
148
|
+
[ ] op_plus
|
|
149
|
+
[ ] op_query_begin
|
|
150
|
+
[ ] op_query_end
|
|
151
|
+
[ ] op_question_mark
|
|
152
|
+
[ ] op_rightbracket
|
|
153
|
+
[ ] op_right_curly_brace
|
|
154
|
+
[ ] op_rightparen
|
|
155
|
+
[ ] op_slash
|
|
156
|
+
[ ] parameter
|
|
157
|
+
[ ] parameterId
|
|
158
|
+
[ ] parameterRef
|
|
159
|
+
[ ] parameterType
|
|
160
|
+
[ ] population
|
|
161
|
+
[ ] precisionSpec
|
|
162
|
+
[ ] primary
|
|
163
|
+
[ ] procedureCallStmt
|
|
164
|
+
[ ] procedureDecl
|
|
165
|
+
[ ] procedureHeadParameter
|
|
166
|
+
[ ] procedureHead
|
|
167
|
+
[ ] procedureId
|
|
168
|
+
[ ] procedureRef
|
|
169
|
+
[ ] qualifiableFactor
|
|
170
|
+
[ ] qualifiedAttribute
|
|
171
|
+
[ ] qualifier
|
|
172
|
+
[ ] queryExpression
|
|
173
|
+
[ ] realLiteral
|
|
174
|
+
[ ] realType
|
|
175
|
+
[ ] redeclaredAttribute
|
|
176
|
+
[ ] referenceClause
|
|
177
|
+
[ ] referencedAttribute
|
|
178
|
+
[ ] relOpExtended
|
|
179
|
+
[ ] relOp
|
|
180
|
+
[ ] renameId
|
|
181
|
+
[ ] repeatControl
|
|
182
|
+
[ ] repeatStmt
|
|
183
|
+
[ ] repetition
|
|
184
|
+
[ ] resourceOrRename
|
|
185
|
+
[ ] resourceRef
|
|
186
|
+
[ ] returnStmt
|
|
187
|
+
[ ] ruleDecl
|
|
188
|
+
[ ] ruleHead
|
|
189
|
+
[ ] ruleId
|
|
190
|
+
[ ] ruleLabelId
|
|
191
|
+
[ ] ruleLabelRef
|
|
192
|
+
[ ] ruleRef
|
|
193
|
+
[ ] schemaBodyDeclaration
|
|
194
|
+
[ ] schemaBody
|
|
195
|
+
[ ] schemaDecl
|
|
196
|
+
[ ] schemaId
|
|
197
|
+
[ ] schemaRef
|
|
198
|
+
[ ] schemaVersionId
|
|
199
|
+
[ ] selectExtension
|
|
200
|
+
[ ] selectList
|
|
201
|
+
[ ] selector
|
|
202
|
+
[ ] selectType
|
|
203
|
+
[ ] setType
|
|
204
|
+
[ ] sign
|
|
205
|
+
[ ] simpleExpression
|
|
206
|
+
[ ] simpleFactor
|
|
207
|
+
[ ] simpleFactorExpression
|
|
208
|
+
[ ] simpleFactorUnaryExpression
|
|
209
|
+
[ ] simpleId
|
|
210
|
+
[ ] simpleStringLiteral
|
|
211
|
+
[ ] simpleTypes
|
|
212
|
+
[ ] skipStmt
|
|
213
|
+
[ ] space
|
|
214
|
+
[ ] spaces
|
|
215
|
+
[ ] stmt
|
|
216
|
+
[ ] stringLiteral
|
|
217
|
+
[ ] stringType
|
|
218
|
+
[ ] subsuper
|
|
219
|
+
[ ] subtypeConstraintBody
|
|
220
|
+
[ ] subtypeConstraintDecl
|
|
221
|
+
[ ] subtypeConstraintHead
|
|
222
|
+
[ ] subtypeConstraintId
|
|
223
|
+
[ ] subtypeConstraintRef
|
|
224
|
+
[ ] subtypeConstraint
|
|
225
|
+
[ ] subtypeDeclaration
|
|
226
|
+
[ ] supertypeConstraint
|
|
227
|
+
[ ] supertypeExpression
|
|
228
|
+
[ ] supertypeFactor
|
|
229
|
+
[ ] supertypeRule
|
|
230
|
+
[ ] supertypeTerm
|
|
231
|
+
[ ] syntax
|
|
232
|
+
[ ] tailRemark
|
|
233
|
+
[ ] term
|
|
234
|
+
[ ] totalOver
|
|
235
|
+
[ ] typeDecl
|
|
236
|
+
[ ] typeId
|
|
237
|
+
[ ] typeLabelId
|
|
238
|
+
[ ] typeLabelRef
|
|
239
|
+
[ ] typeLabel
|
|
240
|
+
[ ] typeRef
|
|
241
|
+
[ ] unaryOp
|
|
242
|
+
[ ] underlyingType
|
|
243
|
+
[ ] uniqueClause
|
|
244
|
+
[ ] uniqueRule
|
|
245
|
+
[ ] untilControl
|
|
246
|
+
[ ] useClause
|
|
247
|
+
[ ] variableId
|
|
248
|
+
[ ] variableRef
|
|
249
|
+
[ ] whereClause
|
|
250
|
+
[ ] whileControl
|
|
251
|
+
[ ] width
|
|
252
|
+
[ ] widthSpec
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# STEP 1 (issue #578): serialize the LIVE DSL atom tree to PARG text at
|
|
4
|
+
# edition v2. The native serialize_grammar dump is a flattened VM
|
|
5
|
+
# program — it CSE-mangles alias rules and drops leading lookaheads —
|
|
6
|
+
# so this walks the real atoms from the cached parser instead: rule
|
|
7
|
+
# bodies from Parser#send(name), Lookahead#bound_parslet for guards,
|
|
8
|
+
# Named#parslet/#name for captures, Entity#rule_name for references.
|
|
9
|
+
|
|
10
|
+
out_path = ARGV[0] || File.join(__dir__, "express-grammar.parg")
|
|
11
|
+
|
|
12
|
+
require "bundler/setup"
|
|
13
|
+
require "expressir"
|
|
14
|
+
|
|
15
|
+
require_relative File.join(__dir__, "generate-terminals.rb")
|
|
16
|
+
|
|
17
|
+
# generate-terminals.rb prints its generated PARG text on load; silence
|
|
18
|
+
# that noise — the serializer only needs its KEYWORDS constant.
|
|
19
|
+
def puts(*); end
|
|
20
|
+
|
|
21
|
+
parser = Expressir::Express::Grammar::Parser.cached_parser
|
|
22
|
+
|
|
23
|
+
SKIP_RULE = "space"
|
|
24
|
+
ATOMIC_RULES = %w[simpleId unguardedId digits spaces space embeddedRemark tailRemark].freeze
|
|
25
|
+
RULE_NAMES = File.read(File.join(__dir__, "RULE-INVENTORY.txt"))
|
|
26
|
+
.scan(/^\[ \] (\w+)$/).flatten + ["syntax"] + ["unguardedId"] +
|
|
27
|
+
KEYWORDS.map { |kw| "t#{kw}" }
|
|
28
|
+
|
|
29
|
+
REJECTED = Hash.new(0)
|
|
30
|
+
|
|
31
|
+
# The DSL skip configuration: skip(:trivia, whitespace: :space, exempt:
|
|
32
|
+
# [simpleId digits spaces space embeddedRemark tailRemark]) — the trivia
|
|
33
|
+
# channel is PURE WHITESPACE (remarks are product data, matched
|
|
34
|
+
# explicitly by grammar bodies via `space`/`spaces`); the exempt list
|
|
35
|
+
# rides the `atomic` keyword. No `capture:` clause: the DSL's trivia
|
|
36
|
+
# recording is builder-inert (find_slice skips :spaces, remarks ride
|
|
37
|
+
# the RemarkScanner), and parsanol 1.3.123's TriviaCapture#record
|
|
38
|
+
# crashes on this grammar (`lstrip` for nil) — plain Trivia keeps the
|
|
39
|
+
# artifact lane on the backtracking, capture-free wrapper instead.
|
|
40
|
+
SKIP_DECL = "skip = trivia"
|
|
41
|
+
|
|
42
|
+
class AtomRenderer
|
|
43
|
+
def initialize(rejected, alt_rules)
|
|
44
|
+
@rejected = rejected
|
|
45
|
+
@alt_rules = alt_rules
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def render(atom)
|
|
49
|
+
case atom
|
|
50
|
+
when Parsanol::Atoms::Str then literal(atom.str)
|
|
51
|
+
when Parsanol::Atoms::Re then lower_re(atom.re.source)
|
|
52
|
+
when Parsanol::Atoms::Entity then atom.rule_name.to_s
|
|
53
|
+
when Parsanol::Atoms::Named then "(#{render(atom.parslet)}) as #{atom.name}"
|
|
54
|
+
when Parsanol::Atoms::Sequence
|
|
55
|
+
atom.parslets.map { |c| child_seq(c) }.join(" ")
|
|
56
|
+
when Parsanol::Atoms::Alternative
|
|
57
|
+
atom.alternatives.map { |c| child_alt(c) }.join(" / ")
|
|
58
|
+
when Parsanol::Atoms::Repetition
|
|
59
|
+
mx = atom.max
|
|
60
|
+
inner = child_rep(atom.parslet)
|
|
61
|
+
# PARG binds `as name` to the whole repetition, so an inline
|
|
62
|
+
# capture would hoist outside it (artifacts yield {item: [...]},
|
|
63
|
+
# never the DSL's per-iteration [{item: ...}, ...]). The extra
|
|
64
|
+
# paren layer keeps the capture inside the repetition body.
|
|
65
|
+
inner = "(#{inner})" if atom.parslet.is_a?(Parsanol::Atoms::Named)
|
|
66
|
+
if atom.min.zero? && mx == 1
|
|
67
|
+
# the DSL's .maybe: PARG's bracket-optional compiles to the
|
|
68
|
+
# :maybe tag (named flatten unwraps -> flat trees); a 0*1
|
|
69
|
+
# repetition compiles to :repetition (arrays even when named),
|
|
70
|
+
# which segments the tree exactly like the DSL never would
|
|
71
|
+
"[ #{inner} ]"
|
|
72
|
+
else
|
|
73
|
+
"#{atom.min}#{mx ? "*#{mx}" : '*'} #{inner}"
|
|
74
|
+
end
|
|
75
|
+
when Parsanol::Atoms::Lookahead
|
|
76
|
+
inner = render(atom.bound_parslet)
|
|
77
|
+
atom.positive ? "&(#{inner})" : "!(#{inner})"
|
|
78
|
+
else
|
|
79
|
+
@rejected["atom #{atom.class}"] += 1
|
|
80
|
+
"<REJECTED>"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
def child_seq(atom)
|
|
87
|
+
raw = render(atom)
|
|
88
|
+
atom.is_a?(Parsanol::Atoms::Alternative) ? "(#{raw})" : raw
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def child_alt(atom)
|
|
92
|
+
raw = render(atom)
|
|
93
|
+
atom.is_a?(Parsanol::Atoms::Sequence) && !raw.start_with?("(") ? "(#{raw})" : raw
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def child_rep(atom)
|
|
97
|
+
raw = render(atom)
|
|
98
|
+
if atom.is_a?(Parsanol::Atoms::Sequence) || atom.is_a?(Parsanol::Atoms::Alternative)
|
|
99
|
+
"(#{raw})"
|
|
100
|
+
else
|
|
101
|
+
raw
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Lower a single-character-class regex to PARG %x alternatives.
|
|
106
|
+
def lower_re(pattern)
|
|
107
|
+
case pattern
|
|
108
|
+
when "." then "%x01-10FFFF"
|
|
109
|
+
# the one quantified concat in the grammar (identifier head+tail)
|
|
110
|
+
when "[a-zA-Z_][a-zA-Z0-9_]*"
|
|
111
|
+
"((%x41-5A / %x61-7A / %x5F) 0* (%x30-39 / %x41-5A / %x61-7A / %x5F))"
|
|
112
|
+
else
|
|
113
|
+
m = pattern.match(/\A\[(.*)\]\z/m) or return reject_re(pattern)
|
|
114
|
+
body = m[1]
|
|
115
|
+
negated = body.delete_prefix!("^")
|
|
116
|
+
pairs = [] # [lo, hi] numeric pairs
|
|
117
|
+
i = 0
|
|
118
|
+
while i < body.length
|
|
119
|
+
ch = body[i]
|
|
120
|
+
if ch == "\\" && i + 1 < body.length
|
|
121
|
+
nxt = body[i + 1]
|
|
122
|
+
codes = { "r" => 0x0D, "n" => 0x0A, "t" => 0x09, "f" => 0x0C }
|
|
123
|
+
if (code = codes[nxt])
|
|
124
|
+
pairs << [code, code]
|
|
125
|
+
elsif nxt == "s"
|
|
126
|
+
pairs.push([0x20, 0x20], [0x09, 0x09], [0x0A, 0x0A],
|
|
127
|
+
[0x0D, 0x0D], [0x0C, 0x0C])
|
|
128
|
+
else
|
|
129
|
+
return reject_re(pattern)
|
|
130
|
+
end
|
|
131
|
+
i += 2
|
|
132
|
+
elsif i + 2 < body.length && body[i + 1] == "-"
|
|
133
|
+
return reject_re(pattern) if ch == "\\"
|
|
134
|
+
|
|
135
|
+
pairs << [ch.ord, body[i + 2].ord]
|
|
136
|
+
i += 3
|
|
137
|
+
else
|
|
138
|
+
pairs << [ch.ord, ch.ord]
|
|
139
|
+
i += 1
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
if negated
|
|
143
|
+
# numeric complement over [0x01, 0x10FFFF]
|
|
144
|
+
comp = []
|
|
145
|
+
lo = 1
|
|
146
|
+
pairs.sort.each do |plo, phi|
|
|
147
|
+
next if phi < lo
|
|
148
|
+
|
|
149
|
+
comp << [lo, plo - 1] if plo > lo
|
|
150
|
+
lo = [lo, phi + 1].max
|
|
151
|
+
end
|
|
152
|
+
comp << [lo, 0x10FFFF] if lo <= 0x10FFFF
|
|
153
|
+
render_ranges(comp)
|
|
154
|
+
else
|
|
155
|
+
grouped = pairs.size > 1
|
|
156
|
+
text = render_ranges(pairs)
|
|
157
|
+
grouped ? "(#{text})" : text
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def render_ranges(ranges)
|
|
163
|
+
ranges.map do |lo, hi|
|
|
164
|
+
lo == hi ? "%x#{format('%02X', lo)}" : "%x#{format('%02X', lo)}-#{format('%02X', hi)}"
|
|
165
|
+
end.join(" / ")
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def reject_re(pattern)
|
|
169
|
+
@rejected["Re #{pattern.inspect}"] += 1
|
|
170
|
+
"<UNLOWERABLE-RE>"
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def literal(text)
|
|
174
|
+
text.chars.map do |c|
|
|
175
|
+
case c.ord
|
|
176
|
+
when 0x22 then "%x22"
|
|
177
|
+
when 0x5C then "%x5C"
|
|
178
|
+
when 0x2F then "%x2F"
|
|
179
|
+
else
|
|
180
|
+
c.match?(/[[:print:]]/) && !c.match?(/[[:space:]]/) ? "\"#{c}\"" : "%x#{format('%02X', c.ord)}"
|
|
181
|
+
end
|
|
182
|
+
end.join(" ")
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# -- build the rule table: name -> body atom --
|
|
187
|
+
# rule(:x) returns a lazy Entity holding @body (the DSL block); the body
|
|
188
|
+
# materializes by instance_exec on the parser, exactly as parsanol does
|
|
189
|
+
# at parse time.
|
|
190
|
+
rules = {}
|
|
191
|
+
RULE_NAMES.uniq.each do |name|
|
|
192
|
+
atom = begin
|
|
193
|
+
parser.public_send(name)
|
|
194
|
+
rescue StandardError
|
|
195
|
+
next
|
|
196
|
+
end
|
|
197
|
+
if atom.is_a?(Parsanol::Atoms::Entity) && atom.rule_name.to_s == name
|
|
198
|
+
body = atom.instance_variable_get(:@cached_atom)
|
|
199
|
+
body ||= parser.instance_exec(&atom.instance_variable_get(:@body))
|
|
200
|
+
rules[name] = body || atom
|
|
201
|
+
else
|
|
202
|
+
rules[name] = atom
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
alt_rules = rules.select { |_, body| body.is_a?(Parsanol::Atoms::Alternative) }.keys
|
|
207
|
+
warn "rules: #{rules.size}/#{RULE_NAMES.uniq.size}"
|
|
208
|
+
|
|
209
|
+
# -- emit --
|
|
210
|
+
out = []
|
|
211
|
+
out << "grammar ExpressSyntax version \"0.1.0\" edition 2 {"
|
|
212
|
+
out << " # The DSL's trivia channel (match[\" \\r\\n\\t\\f\"].repeat(1)) is"
|
|
213
|
+
out << " # emitted below from the live rule; remarks stay product data."
|
|
214
|
+
|
|
215
|
+
renderer = AtomRenderer.new(REJECTED, alt_rules)
|
|
216
|
+
rules.sort_by { |name, _| name }.each do |name, body|
|
|
217
|
+
decl = ATOMIC_RULES.include?(name) ? "atomic #{name} =" : "#{name} ="
|
|
218
|
+
out << " #{decl} #{renderer.render(body)}"
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
out << " #{SKIP_DECL}"
|
|
222
|
+
|
|
223
|
+
out << " entry syntax: syntax"
|
|
224
|
+
out << "}"
|
|
225
|
+
|
|
226
|
+
File.write(out_path, "#{out.join("\n")}\n")
|
|
227
|
+
warn "wrote #{out_path} (#{out.size} lines)"
|
|
228
|
+
unless REJECTED.empty?
|
|
229
|
+
warn "REJECTED (#{REJECTED.values.sum}):"
|
|
230
|
+
REJECTED.first(10).each { |k, n| warn " #{n}x #{k}" }
|
|
231
|
+
end
|
|
232
|
+
exit REJECTED.empty? ? 0 : 1
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Bisect a fixture to the minimal failing prefix through the artifact.
|
|
3
|
+
set -uo pipefail
|
|
4
|
+
F="$1"
|
|
5
|
+
GRAM="${2:-/tmp/diag.json}"
|
|
6
|
+
EXE=/Users/mulgogi/.local/share/mise/installs/ruby/3.4.8/lib/ruby/gems/3.4.0/gems/parsanol-1.3.120-arm64-darwin/exe/parsanol
|
|
7
|
+
total=$(wc -c < "$F")
|
|
8
|
+
lo=1; hi=$total
|
|
9
|
+
# does the full file fail?
|
|
10
|
+
tail -c "$total" "$F" > /tmp/bisect-in.txt
|
|
11
|
+
ruby "$EXE" parg parse "$GRAM" --entry syntax "$(cat /tmp/bisect-in.txt)" >/dev/null 2>&1 || true
|
|
12
|
+
if ruby "$EXE" parg parse "$GRAM" --entry syntax "$(cat /tmp/bisect-in.txt)" >/dev/null 2>&1; then
|
|
13
|
+
echo "FULL PARSES — no failure to bisect"
|
|
14
|
+
exit 0
|
|
15
|
+
fi
|
|
16
|
+
# binary search the smallest failing PREFIX
|
|
17
|
+
while [ "$lo" -lt "$hi" ]; do
|
|
18
|
+
mid=$(( (lo + hi) / 2 ))
|
|
19
|
+
tail -c "$mid" "$F" > /tmp/bisect-in.txt
|
|
20
|
+
# NOTE: tail -c prefix loses the head; prefix probing needs head -c
|
|
21
|
+
break
|
|
22
|
+
done
|
|
23
|
+
# prefix bisection: find the smallest prefix that FAILS
|
|
24
|
+
lo=1; hi=$total
|
|
25
|
+
while [ "$lo" -lt "$hi" ]; do
|
|
26
|
+
mid=$(( (lo + hi) / 2 ))
|
|
27
|
+
head -c "$mid" "$F" > /tmp/bisect-in.txt
|
|
28
|
+
if ruby "$EXE" parg parse "$GRAM" --entry syntax "$(cat /tmp/bisect-in.txt)" >/dev/null 2>&1; then
|
|
29
|
+
lo=$((mid + 1))
|
|
30
|
+
else
|
|
31
|
+
hi=$mid
|
|
32
|
+
fi
|
|
33
|
+
done
|
|
34
|
+
echo "minimal failing prefix: $lo of $total bytes"
|
|
35
|
+
head -c "$lo" "$F" > /tmp/bisect-min.txt
|
|
36
|
+
tail -c 120 /tmp/bisect-min.txt
|
|
37
|
+
echo
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Delta-debug a failing fixture: remove line-ranges while the remainder
|
|
3
|
+
# still fails through the artifact; prints the minimized file.
|
|
4
|
+
set -uo pipefail
|
|
5
|
+
F="$1"
|
|
6
|
+
GRAM="${2:-/tmp/diag.json}"
|
|
7
|
+
EXE=/Users/mulgogi/.local/share/mise/installs/ruby/3.4.8/lib/ruby/gems/3.4.0/gems/parsanol-1.3.120-arm64-darwin/exe/parsanol
|
|
8
|
+
cp "$F" /tmp/ddmin.cur
|
|
9
|
+
|
|
10
|
+
fails() {
|
|
11
|
+
ruby "$EXE" parg parse "$GRAM" --entry syntax "$(cat /tmp/ddmin.cur)" >/dev/null 2>&1
|
|
12
|
+
}
|
|
13
|
+
fails || { echo "input does not fail — nothing to minimize"; exit 1; }
|
|
14
|
+
|
|
15
|
+
n=$(wc -l < /tmp/ddmin.cur)
|
|
16
|
+
chunk=$((n / 4)); [ "$chunk" -lt 1 ] && chunk=1
|
|
17
|
+
while [ "$chunk" -ge 1 ]; do
|
|
18
|
+
changed=1
|
|
19
|
+
while [ "$changed" -eq 1 ]; do
|
|
20
|
+
changed=0
|
|
21
|
+
start=1
|
|
22
|
+
while [ "$start" -le "$n" ]; do
|
|
23
|
+
end=$((start + chunk - 1))
|
|
24
|
+
cp /tmp/ddmin.cur /tmp/ddmin.prev
|
|
25
|
+
awk -v s="$start" -v e="$end" 'NR < s || NR > e' /tmp/ddmin.prev > /tmp/ddmin.cur
|
|
26
|
+
if fails; then
|
|
27
|
+
changed=1
|
|
28
|
+
n=$(wc -l < /tmp/ddmin.cur)
|
|
29
|
+
else
|
|
30
|
+
cp /tmp/ddmin.prev /tmp/ddmin.cur
|
|
31
|
+
fi
|
|
32
|
+
start=$((end + 1))
|
|
33
|
+
done
|
|
34
|
+
n=$(wc -l < /tmp/ddmin.cur)
|
|
35
|
+
done
|
|
36
|
+
chunk=$((chunk / 2))
|
|
37
|
+
done
|
|
38
|
+
echo "=== minimized ($(wc -l < /tmp/ddmin.cur) lines):"
|
|
39
|
+
cat /tmp/ddmin.cur
|