occam-parsers 23.0.52 → 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.
Files changed (85) hide show
  1. package/README.md +7 -7
  2. package/example.js +494 -167
  3. package/lib/bnf/bnf.js +2 -2
  4. package/lib/bnf/parser.js +4 -4
  5. package/lib/definition/{lookAheadModifierRule.js → callAheadModifierRule.js} +11 -11
  6. package/lib/definition/partRule/nonTerminal/ruleName.js +3 -3
  7. package/lib/example/basic/bnf.js +14 -0
  8. package/lib/example/basic/entries.js +18 -0
  9. package/lib/example/basic/lexer.js +136 -0
  10. package/lib/example/basic/parser.js +134 -0
  11. package/lib/example/view/basic.js +8 -8
  12. package/lib/example/view/div/sizeable.js +2 -2
  13. package/lib/node/bnf/{lookAheadModifier.js → callAheadModifier.js} +12 -12
  14. package/lib/node/bnf/choiceOfParts.js +4 -4
  15. package/lib/node/bnf/definition.js +3 -3
  16. package/lib/node/bnf/endOfLine.js +2 -2
  17. package/lib/node/bnf/epsilon.js +2 -2
  18. package/lib/node/bnf/noWhitespacePart.js +2 -2
  19. package/lib/node/bnf/part/nonTerminal.js +6 -6
  20. package/lib/node/bnf/part/terminal.js +3 -3
  21. package/lib/node/bnf/part.js +5 -5
  22. package/lib/node/bnf/partChoice.js +4 -4
  23. package/lib/node/bnf/regularExpression.js +2 -2
  24. package/lib/node/bnf/ruleName.js +3 -3
  25. package/lib/node/bnf/sequenceOfParts.js +4 -4
  26. package/lib/node/bnf/significantTokenType.js +2 -2
  27. package/lib/node/bnf/startOfContentPart.js +2 -2
  28. package/lib/node/bnf/terminalSymbol.js +2 -2
  29. package/lib/node/bnf/wildcard.js +2 -2
  30. package/lib/part/nonTerminal/choiceOfParts.js +4 -4
  31. package/lib/part/nonTerminal/oneOrMoreParts.js +4 -4
  32. package/lib/part/nonTerminal/optionalPart.js +4 -4
  33. package/lib/part/nonTerminal/ruleName.js +8 -8
  34. package/lib/part/nonTerminal/sequenceOfParts.js +4 -4
  35. package/lib/part/nonTerminal/zeroOrMoreParts.js +4 -4
  36. package/lib/part/nonTerminal.js +6 -6
  37. package/lib/part/terminal.js +5 -5
  38. package/lib/rule/{lookAheadModifier.js → callAheadModifier.js} +15 -15
  39. package/lib/rule.js +15 -9
  40. package/lib/ruleNames.js +5 -5
  41. package/lib/utilities/bnf.js +9 -9
  42. package/lib/utilities/parse.js +28 -28
  43. package/package.json +3 -3
  44. package/src/bnf/bnf.js +2 -2
  45. package/src/bnf/parser.js +3 -3
  46. package/src/definition/{lookAheadModifierRule.js → callAheadModifierRule.js} +3 -3
  47. package/src/definition/partRule/nonTerminal/ruleName.js +4 -4
  48. package/src/example/basic/bnf.js +27 -0
  49. package/src/example/basic/entries.js +9 -0
  50. package/src/example/basic/lexer.js +17 -0
  51. package/src/example/basic/parser.js +15 -0
  52. package/src/example/view/basic.js +13 -10
  53. package/src/example/view/div/sizeable.js +1 -1
  54. package/src/node/bnf/callAheadModifier.js +7 -0
  55. package/src/node/bnf/choiceOfParts.js +3 -3
  56. package/src/node/bnf/definition.js +2 -2
  57. package/src/node/bnf/endOfLine.js +1 -1
  58. package/src/node/bnf/epsilon.js +1 -1
  59. package/src/node/bnf/noWhitespacePart.js +1 -1
  60. package/src/node/bnf/part/nonTerminal.js +6 -6
  61. package/src/node/bnf/part/terminal.js +2 -2
  62. package/src/node/bnf/part.js +4 -4
  63. package/src/node/bnf/partChoice.js +3 -3
  64. package/src/node/bnf/regularExpression.js +1 -1
  65. package/src/node/bnf/ruleName.js +2 -2
  66. package/src/node/bnf/sequenceOfParts.js +3 -3
  67. package/src/node/bnf/significantTokenType.js +1 -1
  68. package/src/node/bnf/startOfContentPart.js +1 -1
  69. package/src/node/bnf/terminalSymbol.js +1 -1
  70. package/src/node/bnf/wildcard.js +1 -1
  71. package/src/part/nonTerminal/choiceOfParts.js +4 -4
  72. package/src/part/nonTerminal/oneOrMoreParts.js +4 -4
  73. package/src/part/nonTerminal/optionalPart.js +4 -4
  74. package/src/part/nonTerminal/ruleName.js +9 -9
  75. package/src/part/nonTerminal/sequenceOfParts.js +4 -4
  76. package/src/part/nonTerminal/zeroOrMoreParts.js +4 -4
  77. package/src/part/nonTerminal.js +4 -4
  78. package/src/part/terminal.js +3 -3
  79. package/src/rule/callAheadModifier.js +22 -0
  80. package/src/rule.js +21 -15
  81. package/src/ruleNames.js +1 -1
  82. package/src/utilities/bnf.js +6 -6
  83. package/src/utilities/parse.js +38 -28
  84. package/src/node/bnf/lookAheadModifier.js +0 -7
  85. 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 lookAheadModifier?
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
- lookAheadModifier ::= <NO_WHITESPACE>"..." ;
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 look 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 look-ahead modifier is an ellipsis, thus the rules above become:
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 look-ahead is carried out to arbitrary depth and this it affects the behaviour of the `?`, `*` and `+` quantifiers, which become lazy. For example:
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 look-ahead modifier on the `AAB` rule name part forces the `+` quantifier on the `"b"` terminal part to be lazy, allowing the following to parse:
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 look-ahead, the `"b"+` part would consume all of the `b` tokens, leaving none for the subsequent `"b"` terminal part.
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 look-ahead takes exponential time given its nested nature. For this reason, look-ahead should be used sparingly.
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