occam-parsers 23.0.53 → 23.0.54
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/README.md +7 -7
- package/example.js +494 -167
- package/lib/bnf/bnf.js +2 -2
- package/lib/bnf/parser.js +4 -4
- package/lib/definition/{lookAheadModifierRule.js → callAheadModifierRule.js} +11 -11
- package/lib/definition/partRule/nonTerminal/ruleName.js +3 -3
- package/lib/example/basic/bnf.js +14 -0
- package/lib/example/basic/entries.js +18 -0
- package/lib/example/basic/lexer.js +136 -0
- package/lib/example/basic/parser.js +134 -0
- package/lib/example/view/basic.js +8 -8
- package/lib/example/view/div/sizeable.js +2 -2
- package/lib/node/bnf/{lookAheadModifier.js → callAheadModifier.js} +12 -12
- package/lib/node/bnf/choiceOfParts.js +4 -4
- package/lib/node/bnf/definition.js +3 -3
- package/lib/node/bnf/endOfLine.js +2 -2
- package/lib/node/bnf/epsilon.js +2 -2
- package/lib/node/bnf/noWhitespacePart.js +2 -2
- package/lib/node/bnf/part/nonTerminal.js +6 -6
- package/lib/node/bnf/part/terminal.js +3 -3
- package/lib/node/bnf/part.js +5 -5
- package/lib/node/bnf/partChoice.js +4 -4
- package/lib/node/bnf/regularExpression.js +2 -2
- package/lib/node/bnf/ruleName.js +3 -3
- package/lib/node/bnf/sequenceOfParts.js +4 -4
- package/lib/node/bnf/significantTokenType.js +2 -2
- package/lib/node/bnf/startOfContentPart.js +2 -2
- package/lib/node/bnf/terminalSymbol.js +2 -2
- package/lib/node/bnf/wildcard.js +2 -2
- package/lib/part/nonTerminal/choiceOfParts.js +4 -4
- package/lib/part/nonTerminal/oneOrMoreParts.js +4 -4
- package/lib/part/nonTerminal/optionalPart.js +4 -4
- package/lib/part/nonTerminal/ruleName.js +8 -8
- package/lib/part/nonTerminal/sequenceOfParts.js +4 -4
- package/lib/part/nonTerminal/zeroOrMoreParts.js +4 -4
- package/lib/part/nonTerminal.js +6 -6
- package/lib/part/terminal.js +5 -5
- package/lib/rule/{lookAheadModifier.js → callAheadModifier.js} +15 -15
- package/lib/rule.js +15 -9
- package/lib/ruleNames.js +5 -5
- package/lib/utilities/bnf.js +9 -9
- package/lib/utilities/parse.js +28 -28
- package/package.json +1 -1
- package/src/bnf/bnf.js +2 -2
- package/src/bnf/parser.js +3 -3
- package/src/definition/{lookAheadModifierRule.js → callAheadModifierRule.js} +3 -3
- package/src/definition/partRule/nonTerminal/ruleName.js +4 -4
- package/src/example/basic/bnf.js +27 -0
- package/src/example/basic/entries.js +9 -0
- package/src/example/basic/lexer.js +17 -0
- package/src/example/basic/parser.js +15 -0
- package/src/example/view/basic.js +13 -10
- package/src/example/view/div/sizeable.js +1 -1
- package/src/node/bnf/callAheadModifier.js +7 -0
- package/src/node/bnf/choiceOfParts.js +3 -3
- package/src/node/bnf/definition.js +2 -2
- package/src/node/bnf/endOfLine.js +1 -1
- package/src/node/bnf/epsilon.js +1 -1
- package/src/node/bnf/noWhitespacePart.js +1 -1
- package/src/node/bnf/part/nonTerminal.js +6 -6
- package/src/node/bnf/part/terminal.js +2 -2
- package/src/node/bnf/part.js +4 -4
- package/src/node/bnf/partChoice.js +3 -3
- package/src/node/bnf/regularExpression.js +1 -1
- package/src/node/bnf/ruleName.js +2 -2
- package/src/node/bnf/sequenceOfParts.js +3 -3
- package/src/node/bnf/significantTokenType.js +1 -1
- package/src/node/bnf/startOfContentPart.js +1 -1
- package/src/node/bnf/terminalSymbol.js +1 -1
- package/src/node/bnf/wildcard.js +1 -1
- package/src/part/nonTerminal/choiceOfParts.js +4 -4
- package/src/part/nonTerminal/oneOrMoreParts.js +4 -4
- package/src/part/nonTerminal/optionalPart.js +4 -4
- package/src/part/nonTerminal/ruleName.js +9 -9
- package/src/part/nonTerminal/sequenceOfParts.js +4 -4
- package/src/part/nonTerminal/zeroOrMoreParts.js +4 -4
- package/src/part/nonTerminal.js +4 -4
- package/src/part/terminal.js +3 -3
- package/src/rule/callAheadModifier.js +22 -0
- package/src/rule.js +21 -15
- package/src/ruleNames.js +1 -1
- package/src/utilities/bnf.js +6 -6
- package/src/utilities/parse.js +38 -28
- package/src/node/bnf/lookAheadModifier.js +0 -7
- package/src/rule/lookAheadModifier.js +0 -22
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ All parsers share common functionality. The last two parse content according to
|
|
|
42
42
|
|
|
43
43
|
| sequenceOfParts
|
|
44
44
|
|
|
45
|
-
| ruleName
|
|
45
|
+
| ruleName callAheadModifier?
|
|
46
46
|
|
|
47
47
|
;
|
|
48
48
|
|
|
@@ -98,7 +98,7 @@ All parsers share common functionality. The last two parse content according to
|
|
|
98
98
|
|
|
99
99
|
opacityModifier ::= <NO_WHITESPACE>( "." | ".." );
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
callAheadModifier ::= <NO_WHITESPACE>"..." ;
|
|
102
102
|
|
|
103
103
|
optionalQuantifier ::= <NO_WHITESPACE>"?" ;
|
|
104
104
|
|
|
@@ -224,7 +224,7 @@ Consider the following rules:
|
|
|
224
224
|
|
|
225
225
|
BC ::= "b" "c" ;
|
|
226
226
|
|
|
227
|
-
These will not parse the tokens `a`, `b`, `c` because the first definition of the `AAB` rule will parse the `a` and `b` tokens, leaving only the `c` token for the `BC` rule to parse. This situation can be addressed by making the `AAB` rule
|
|
227
|
+
These will not parse the tokens `a`, `b`, `c` because the first definition of the `AAB` rule will parse the `a` and `b` tokens, leaving only the `c` token for the `BC` rule to parse. This situation can be addressed by making the `AAB` rule call ahead, that is, try each of its definitions in turn until one is found that allows the remainder of the parent rule to parse. The call-ahead modifier is an ellipsis, thus the rules above become:
|
|
228
228
|
|
|
229
229
|
ABC ::= AAB... BC ;
|
|
230
230
|
|
|
@@ -234,19 +234,19 @@ These will not parse the tokens `a`, `b`, `c` because the first definition of th
|
|
|
234
234
|
|
|
235
235
|
Now the `ABC` rule will indeed parse the tokens `a`, `b`, `c`, because the second definition of the `AAB` rule will be tried after the first definition fails to allow the `BC` rule name part to parse.
|
|
236
236
|
|
|
237
|
-
Also bear in mind that
|
|
237
|
+
Also bear in mind that call-ahead is carried out to arbitrary depth and this it affects the behaviour of the `?`, `*` and `+` quantifiers, which become lazy. For example:
|
|
238
238
|
|
|
239
239
|
ABC ::= AAB... ;
|
|
240
240
|
|
|
241
241
|
AAB ::= "a" "b"+ "b" "c" ;
|
|
242
242
|
|
|
243
|
-
Here the
|
|
243
|
+
Here the call-ahead modifier on the `AAB` rule name part forces the `+` quantifier on the `"b"` terminal part to be lazy, allowing the following to parse:
|
|
244
244
|
|
|
245
245
|
a b b b c
|
|
246
246
|
|
|
247
|
-
Without
|
|
247
|
+
Without call-ahead, the `"b"+` part would consume all of the `b` tokens, leaving none for the subsequent `"b"` terminal part.
|
|
248
248
|
|
|
249
|
-
It seems that the parser parses in time that is roughly directly proportional to the length of the input. However, on the ohter hand it is most likely that
|
|
249
|
+
It seems that the parser parses in time that is roughly directly proportional to the length of the input. However, on the ohter hand it is most likely that call-ahead takes exponential time given its nested nature. For this reason, call-ahead should be used sparingly.
|
|
250
250
|
|
|
251
251
|
## Building
|
|
252
252
|
|