grammar-well 1.3.3 → 2.0.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.
Files changed (246) hide show
  1. package/README.md +76 -560
  2. package/build/generator/artifacts/basic.d.ts +7 -0
  3. package/build/generator/artifacts/basic.js +24 -0
  4. package/build/generator/artifacts/basic.js.map +1 -0
  5. package/build/generator/artifacts/lexer.d.ts +13 -0
  6. package/build/generator/artifacts/lexer.js +204 -0
  7. package/build/generator/artifacts/lexer.js.map +1 -0
  8. package/build/{compiler/generator → generator}/artifacts/lr.d.ts +14 -14
  9. package/build/{compiler/generator → generator}/artifacts/lr.js +18 -22
  10. package/build/generator/artifacts/lr.js.map +1 -0
  11. package/build/generator/builtin/registry.json +1 -0
  12. package/build/generator/generator.d.ts +38 -0
  13. package/build/generator/generator.js +368 -0
  14. package/build/generator/generator.js.map +1 -0
  15. package/build/generator/grammars/index.d.ts +2 -0
  16. package/build/generator/grammars/index.js +3 -0
  17. package/build/generator/grammars/index.js.map +1 -0
  18. package/build/generator/grammars/v1.d.ts +1190 -0
  19. package/build/generator/grammars/v1.js +614 -0
  20. package/build/generator/grammars/v1.js.map +1 -0
  21. package/build/generator/grammars/v2.d.ts +1367 -0
  22. package/build/generator/grammars/v2.js +695 -0
  23. package/build/generator/grammars/v2.js.map +1 -0
  24. package/build/generator/import-resolvers/auto.d.ts +2 -0
  25. package/build/generator/import-resolvers/auto.js +11 -0
  26. package/build/generator/import-resolvers/auto.js.map +1 -0
  27. package/build/generator/import-resolvers/browser.d.ts +7 -0
  28. package/build/generator/import-resolvers/browser.js +13 -0
  29. package/build/generator/import-resolvers/browser.js.map +1 -0
  30. package/build/generator/import-resolvers/filesystem.d.ts +7 -0
  31. package/build/generator/import-resolvers/filesystem.js +15 -0
  32. package/build/generator/import-resolvers/filesystem.js.map +1 -0
  33. package/build/generator/index.d.ts +3 -0
  34. package/build/generator/index.js +4 -0
  35. package/build/generator/index.js.map +1 -0
  36. package/build/generator/state.d.ts +28 -0
  37. package/build/generator/state.js +73 -0
  38. package/build/generator/state.js.map +1 -0
  39. package/build/generator/stringify/common.d.ts +22 -0
  40. package/build/generator/stringify/common.js +83 -0
  41. package/build/generator/stringify/common.js.map +1 -0
  42. package/build/generator/stringify/exports/javascript.d.ts +3 -0
  43. package/build/generator/stringify/exports/javascript.js +26 -0
  44. package/build/generator/stringify/exports/javascript.js.map +1 -0
  45. package/build/generator/stringify/exports/json.d.ts +2 -0
  46. package/build/generator/stringify/exports/json.js +4 -0
  47. package/build/generator/stringify/exports/json.js.map +1 -0
  48. package/build/generator/stringify/exports/registry.d.ts +20 -0
  49. package/build/generator/stringify/exports/registry.js +17 -0
  50. package/build/generator/stringify/exports/registry.js.map +1 -0
  51. package/build/generator/stringify/exports/typescript.d.ts +2 -0
  52. package/build/generator/stringify/exports/typescript.js +16 -0
  53. package/build/generator/stringify/exports/typescript.js.map +1 -0
  54. package/build/generator/stringify/grammar/v2.d.ts +20 -0
  55. package/build/generator/stringify/grammar/v2.js +211 -0
  56. package/build/generator/stringify/grammar/v2.js.map +1 -0
  57. package/build/generator/stringify/javascript.d.ts +13 -0
  58. package/build/generator/stringify/javascript.js +83 -0
  59. package/build/generator/stringify/javascript.js.map +1 -0
  60. package/build/index.d.ts +7 -6
  61. package/build/index.js +7 -24
  62. package/build/index.js.map +1 -1
  63. package/build/lexers/character-lexer.d.ts +2 -2
  64. package/build/lexers/character-lexer.js +1 -5
  65. package/build/lexers/character-lexer.js.map +1 -1
  66. package/build/lexers/stateful-lexer.d.ts +12 -17
  67. package/build/lexers/stateful-lexer.js +38 -186
  68. package/build/lexers/stateful-lexer.js.map +1 -1
  69. package/build/lexers/token-buffer.d.ts +8 -8
  70. package/build/lexers/token-buffer.js +1 -5
  71. package/build/lexers/token-buffer.js.map +1 -1
  72. package/build/parser/algorithms/cyk.d.ts +6 -6
  73. package/build/parser/algorithms/cyk.js +10 -13
  74. package/build/parser/algorithms/cyk.js.map +1 -1
  75. package/build/parser/algorithms/earley.d.ts +7 -7
  76. package/build/parser/algorithms/earley.js +7 -11
  77. package/build/parser/algorithms/earley.js.map +1 -1
  78. package/build/parser/algorithms/lrk/algorithm.d.ts +3 -3
  79. package/build/parser/algorithms/lrk/algorithm.js +10 -13
  80. package/build/parser/algorithms/lrk/algorithm.js.map +1 -1
  81. package/build/parser/algorithms/lrk/bimap.js +1 -5
  82. package/build/parser/algorithms/lrk/bimap.js.map +1 -1
  83. package/build/parser/algorithms/lrk/canonical-collection.d.ts +7 -7
  84. package/build/parser/algorithms/lrk/canonical-collection.js +11 -15
  85. package/build/parser/algorithms/lrk/canonical-collection.js.map +1 -1
  86. package/build/parser/algorithms/lrk/closure.d.ts +3 -3
  87. package/build/parser/algorithms/lrk/closure.js +3 -7
  88. package/build/parser/algorithms/lrk/closure.js.map +1 -1
  89. package/build/parser/algorithms/lrk/stack.d.ts +6 -6
  90. package/build/parser/algorithms/lrk/stack.js +1 -5
  91. package/build/parser/algorithms/lrk/stack.js.map +1 -1
  92. package/build/parser/algorithms/lrk/state.d.ts +5 -5
  93. package/build/parser/algorithms/lrk/state.js +1 -2
  94. package/build/parser/parse.d.ts +10 -0
  95. package/build/parser/parse.js +34 -0
  96. package/build/parser/parse.js.map +1 -0
  97. package/build/tsconfig.tsbuildinfo +1 -0
  98. package/build/typings/ast.d.ts +134 -0
  99. package/build/typings/ast.js +3 -0
  100. package/build/typings/ast.js.map +1 -0
  101. package/build/typings/common.d.ts +4 -0
  102. package/build/typings/common.js +2 -0
  103. package/build/typings/common.js.map +1 -0
  104. package/build/typings/generator.d.ts +58 -0
  105. package/build/typings/generator.js +3 -0
  106. package/build/typings/generator.js.map +1 -0
  107. package/build/typings/index.d.ts +43 -0
  108. package/build/typings/index.js +5 -0
  109. package/build/typings/index.js.map +1 -0
  110. package/build/typings/runtime.d.ts +70 -0
  111. package/build/typings/runtime.js +2 -0
  112. package/build/typings/runtime.js.map +1 -0
  113. package/build/utility/format.d.ts +1 -0
  114. package/build/utility/format.js +12 -0
  115. package/build/utility/format.js.map +1 -0
  116. package/build/utility/general.d.ts +1 -1
  117. package/build/utility/general.js +5 -13
  118. package/build/utility/general.js.map +1 -1
  119. package/build/utility/index.d.ts +4 -1
  120. package/build/utility/index.js +4 -17
  121. package/build/utility/index.js.map +1 -1
  122. package/build/utility/lint.d.ts +2 -2
  123. package/build/utility/lint.js +2 -6
  124. package/build/utility/lint.js.map +1 -1
  125. package/build/utility/monarch.d.ts +2 -2
  126. package/build/utility/monarch.js +33 -38
  127. package/build/utility/monarch.js.map +1 -1
  128. package/build/utility/parsing.d.ts +6 -0
  129. package/build/utility/parsing.js +26 -0
  130. package/build/utility/parsing.js.map +1 -0
  131. package/build/utility/text-format.d.ts +6 -6
  132. package/build/utility/text-format.js +2 -6
  133. package/build/utility/text-format.js.map +1 -1
  134. package/package.json +17 -24
  135. package/src/generator/artifacts/basic.ts +26 -0
  136. package/src/generator/artifacts/lexer.ts +228 -0
  137. package/src/{compiler/generator → generator}/artifacts/lr.ts +25 -24
  138. package/src/generator/builtin/character.well +7 -0
  139. package/src/generator/builtin/json.well +85 -0
  140. package/src/generator/builtin/number.well +21 -0
  141. package/src/generator/builtin/registry.json +1 -0
  142. package/src/generator/builtin/string.well +54 -0
  143. package/src/generator/builtin/whitespace.well +16 -0
  144. package/src/generator/generator.ts +401 -0
  145. package/src/generator/grammars/index.ts +2 -0
  146. package/src/generator/grammars/v1.ts +620 -0
  147. package/src/generator/grammars/v1.well +422 -0
  148. package/src/generator/grammars/v2.ts +701 -0
  149. package/src/generator/grammars/v2.well +413 -0
  150. package/src/generator/import-resolvers/auto.ts +12 -0
  151. package/src/generator/import-resolvers/browser.ts +13 -0
  152. package/src/generator/import-resolvers/filesystem.ts +18 -0
  153. package/src/generator/index.ts +3 -0
  154. package/src/generator/state.ts +89 -0
  155. package/src/generator/stringify/common.ts +90 -0
  156. package/src/generator/stringify/exports/javascript.ts +29 -0
  157. package/src/generator/stringify/exports/json.ts +5 -0
  158. package/src/generator/stringify/exports/registry.ts +20 -0
  159. package/src/generator/stringify/exports/typescript.ts +17 -0
  160. package/src/generator/stringify/grammar/v2.ts +223 -0
  161. package/src/generator/stringify/javascript.ts +94 -0
  162. package/src/index.ts +7 -6
  163. package/src/lexers/character-lexer.ts +2 -2
  164. package/src/lexers/stateful-lexer.ts +46 -203
  165. package/src/lexers/token-buffer.ts +3 -3
  166. package/src/parser/algorithms/cyk.ts +13 -12
  167. package/src/parser/algorithms/earley.ts +10 -10
  168. package/src/parser/algorithms/lrk/algorithm.ts +8 -7
  169. package/src/parser/algorithms/lrk/canonical-collection.ts +14 -14
  170. package/src/parser/algorithms/lrk/closure.ts +6 -6
  171. package/src/parser/algorithms/lrk/stack.ts +6 -6
  172. package/src/parser/algorithms/lrk/state.ts +5 -5
  173. package/src/parser/parse.ts +45 -0
  174. package/src/typings/ast.ts +148 -0
  175. package/src/typings/common.ts +2 -0
  176. package/src/typings/generator.ts +62 -0
  177. package/src/typings/index.ts +38 -0
  178. package/src/typings/runtime.ts +82 -0
  179. package/src/utility/format.ts +12 -0
  180. package/src/utility/general.ts +1 -2
  181. package/src/utility/index.ts +4 -1
  182. package/src/utility/lint.ts +5 -5
  183. package/src/utility/monarch.ts +34 -34
  184. package/src/utility/parsing.ts +30 -0
  185. package/src/utility/text-format.ts +7 -7
  186. package/.eslintrc.cjs +0 -14
  187. package/bootstrap.ts +0 -45
  188. package/build/compiler/builtin.json +0 -1
  189. package/build/compiler/compiler.d.ts +0 -50
  190. package/build/compiler/compiler.js +0 -249
  191. package/build/compiler/compiler.js.map +0 -1
  192. package/build/compiler/generator/artifacts/lr.js.map +0 -1
  193. package/build/compiler/generator/artifacts/standard.d.ts +0 -7
  194. package/build/compiler/generator/artifacts/standard.js +0 -28
  195. package/build/compiler/generator/artifacts/standard.js.map +0 -1
  196. package/build/compiler/generator/generator.d.ts +0 -24
  197. package/build/compiler/generator/generator.js +0 -217
  198. package/build/compiler/generator/generator.js.map +0 -1
  199. package/build/compiler/gwell.d.ts +0 -1112
  200. package/build/compiler/gwell.js +0 -576
  201. package/build/compiler/gwell.js.map +0 -1
  202. package/build/compiler/import-resolver.d.ts +0 -15
  203. package/build/compiler/import-resolver.js +0 -37
  204. package/build/compiler/import-resolver.js.map +0 -1
  205. package/build/compiler/index.d.ts +0 -2
  206. package/build/compiler/index.js +0 -19
  207. package/build/compiler/index.js.map +0 -1
  208. package/build/compiler/outputs/javascript.d.ts +0 -3
  209. package/build/compiler/outputs/javascript.js +0 -29
  210. package/build/compiler/outputs/javascript.js.map +0 -1
  211. package/build/compiler/outputs/json.d.ts +0 -2
  212. package/build/compiler/outputs/json.js +0 -8
  213. package/build/compiler/outputs/json.js.map +0 -1
  214. package/build/compiler/outputs/typescript.d.ts +0 -2
  215. package/build/compiler/outputs/typescript.js +0 -21
  216. package/build/compiler/outputs/typescript.js.map +0 -1
  217. package/build/parser/algorithms/lr.d.ts +0 -7
  218. package/build/parser/algorithms/lr.js +0 -108
  219. package/build/parser/algorithms/lr.js.map +0 -5
  220. package/build/parser/algorithms/lr0.d.ts +0 -7
  221. package/build/parser/algorithms/lr0.js +0 -156
  222. package/build/parser/algorithms/lr0.js.map +0 -1
  223. package/build/parser/parser.d.ts +0 -26
  224. package/build/parser/parser.js +0 -74
  225. package/build/parser/parser.js.map +0 -1
  226. package/build/typings.d.ts +0 -226
  227. package/build/typings.js +0 -3
  228. package/build/typings.js.map +0 -1
  229. package/src/compiler/builtin/json.gwell +0 -74
  230. package/src/compiler/builtin/number.gwell +0 -20
  231. package/src/compiler/builtin/string.gwell +0 -48
  232. package/src/compiler/builtin/whitespace.gwell +0 -10
  233. package/src/compiler/builtin.json +0 -1
  234. package/src/compiler/compiler.ts +0 -265
  235. package/src/compiler/generator/artifacts/standard.ts +0 -26
  236. package/src/compiler/generator/generator.ts +0 -237
  237. package/src/compiler/gwell.gwell +0 -294
  238. package/src/compiler/gwell.js +0 -578
  239. package/src/compiler/import-resolver.ts +0 -36
  240. package/src/compiler/index.ts +0 -2
  241. package/src/compiler/outputs/javascript.ts +0 -27
  242. package/src/compiler/outputs/json.ts +0 -5
  243. package/src/compiler/outputs/typescript.ts +0 -18
  244. package/src/parser/parser.ts +0 -77
  245. package/src/typings.ts +0 -248
  246. package/testing.ts +0 -18
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParserUtility = exports.Parser = exports.Parse = void 0;
4
- const character_lexer_1 = require("../lexers/character-lexer");
5
- const stateful_lexer_1 = require("../lexers/stateful-lexer");
6
- const token_buffer_1 = require("../lexers/token-buffer");
7
- const cyk_1 = require("./algorithms/cyk");
8
- const earley_1 = require("./algorithms/earley");
9
- const algorithm_1 = require("./algorithms/lrk/algorithm");
10
- const ParserRegistry = {
11
- earley: earley_1.Earley,
12
- cyk: cyk_1.CYK,
13
- lr0: algorithm_1.LRK
14
- };
15
- function Parse(language, input, options) {
16
- const i = new Parser(language, options);
17
- return i.run(input);
18
- }
19
- exports.Parse = Parse;
20
- class Parser {
21
- language;
22
- options;
23
- constructor(language, options = { algorithm: 'earley', parserOptions: {} }) {
24
- this.language = language;
25
- this.options = options;
26
- }
27
- run(input) {
28
- const tokenQueue = this.getTokenQueue();
29
- tokenQueue.feed(input);
30
- if (typeof this.options.algorithm == 'function')
31
- return this.options.algorithm({ ...this.language, tokens: tokenQueue, utility: ParserUtility }, this.options.parserOptions);
32
- return ParserRegistry[this.options.algorithm]({ ...this.language, tokens: tokenQueue, utility: ParserUtility }, this.options.parserOptions);
33
- }
34
- getTokenQueue() {
35
- const { lexer } = this.language;
36
- if (!lexer) {
37
- return new token_buffer_1.TokenBuffer(new character_lexer_1.CharacterLexer());
38
- }
39
- else if ("feed" in lexer && typeof lexer.feed == 'function') {
40
- return new token_buffer_1.TokenBuffer(lexer);
41
- }
42
- else if ('states' in lexer) {
43
- return new token_buffer_1.TokenBuffer(new stateful_lexer_1.StatefulLexer(lexer));
44
- }
45
- }
46
- }
47
- exports.Parser = Parser;
48
- class ParserUtility {
49
- static SymbolMatchesToken(symbol, token) {
50
- if (typeof symbol === 'string')
51
- throw 'Attempted to match token against non-terminal';
52
- if (typeof symbol == 'function')
53
- return symbol(token);
54
- if (!symbol)
55
- return;
56
- if ("test" in symbol)
57
- return symbol.test(token.value);
58
- if ("token" in symbol)
59
- return symbol.token === token.type || token.tag?.has(symbol.token);
60
- if ("literal" in symbol)
61
- return symbol.literal === token.value;
62
- }
63
- static SymbolIsTerminal(symbol) {
64
- return typeof symbol != 'string';
65
- }
66
- static PostProcess(rule, data, meta) {
67
- if (rule.postprocess) {
68
- return rule.postprocess({ rule, data, meta });
69
- }
70
- return data;
71
- }
72
- }
73
- exports.ParserUtility = ParserUtility;
74
- //# sourceMappingURL=parser.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser/parser.ts"],"names":[],"mappings":";;;AAAA,+DAA2D;AAC3D,6DAAyD;AACzD,yDAAqD;AAErD,0CAAuC;AACvC,gDAA6C;AAC7C,0DAAiD;AAEjD,MAAM,cAAc,GAAuC;IACvD,MAAM,EAAE,eAAM;IACd,GAAG,EAAE,SAAG;IACR,GAAG,EAAE,eAAG;CACX,CAAA;AAED,SAAgB,KAAK,CAAC,QAA4B,EAAE,KAAa,EAAE,OAAuB;IACtF,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACxC,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAHD,sBAGC;AAED,MAAa,MAAM;IAEK;IAAsC;IAA1D,YAAoB,QAA4B,EAAU,UAAyB,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,EAAE;QAAzG,aAAQ,GAAR,QAAQ,CAAoB;QAAU,YAAO,GAAP,OAAO,CAA4D;IAAI,CAAC;IAElI,GAAG,CAAC,KAAa;QACb,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACxC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,UAAU;YAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QAChI,OAAO,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAChJ,CAAC;IAEO,aAAa;QACjB,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,KAAK,EAAE;YACR,OAAO,IAAI,0BAAW,CAAC,IAAI,gCAAc,EAAE,CAAC,CAAC;SAChD;aAAM,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,UAAU,EAAE;YAC3D,OAAO,IAAI,0BAAW,CAAC,KAAK,CAAC,CAAC;SACjC;aAAM,IAAI,QAAQ,IAAI,KAAK,EAAE;YAC1B,OAAO,IAAI,0BAAW,CAAC,IAAI,8BAAa,CAAC,KAAK,CAAC,CAAC,CAAC;SACpD;IACL,CAAC;CACJ;AAtBD,wBAsBC;AAGD,MAAsB,aAAa;IAE/B,MAAM,CAAC,kBAAkB,CAAC,MAAyB,EAAE,KAAiB;QAClE,IAAI,OAAO,MAAM,KAAK,QAAQ;YAC1B,MAAM,+CAA+C,CAAC;QAC1D,IAAI,OAAO,MAAM,IAAI,UAAU;YAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM;YACP,OAAM;QACV,IAAI,MAAM,IAAI,MAAM;YAChB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,OAAO,IAAI,MAAM;YACjB,OAAO,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,IAAI,SAAS,IAAI,MAAM;YACnB,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,KAAK,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,MAAyB;QAC7C,OAAO,OAAO,MAAM,IAAI,QAAQ,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAiB,EAAE,IAAS,EAAE,IAAU;QACvD,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;SACjD;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA3BD,sCA2BC"}
@@ -1,226 +0,0 @@
1
- import { TokenBuffer } from "./lexers/token-buffer";
2
- import { ParserUtility } from "./parser/parser";
3
- export interface Dictionary<T> {
4
- [key: string]: T;
5
- }
6
- export interface CompileOptions {
7
- version?: string;
8
- noscript?: boolean;
9
- basedir?: string;
10
- resolver?: ImportResolverConstructor;
11
- resolverInstance?: ImportResolver;
12
- exportName?: string;
13
- template?: TemplateFormat;
14
- overrides?: Dictionary<string>;
15
- }
16
- export type TemplateFormat = '_default' | 'object' | 'json' | 'js' | 'javascript' | 'module' | 'esmodule' | 'esm' | 'ts' | 'typescript';
17
- export interface GrammarBuilderContext {
18
- alreadyCompiled: Set<string>;
19
- resolver: ImportResolver;
20
- uuids: Dictionary<number>;
21
- }
22
- export interface ImportResolver {
23
- path(path: string): string;
24
- body(path: string): Promise<string>;
25
- }
26
- export interface ImportResolverConstructor {
27
- new (basePath: string): ImportResolver;
28
- }
29
- export type PostProcessor = (payload: PostProcessorPayload) => any;
30
- interface PostProcessorPayload {
31
- data: any[];
32
- rule: GrammarRule;
33
- meta: any;
34
- }
35
- export type JavascriptDirective = {
36
- body: GrammarTypeJS;
37
- } | {
38
- head: GrammarTypeJS;
39
- };
40
- export interface ImportDirective {
41
- import: string;
42
- path?: boolean;
43
- alias?: string;
44
- }
45
- export interface ConfigDirective {
46
- config: Dictionary<any>;
47
- }
48
- export interface GrammarDirective {
49
- grammar: {
50
- config?: Dictionary<any>;
51
- rules: GrammarBuilderRule[];
52
- };
53
- }
54
- export interface LexerDirective {
55
- lexer: {
56
- start?: string;
57
- states: LexerStateDefinition[];
58
- };
59
- }
60
- export interface GrammarBuilderRule {
61
- name: string;
62
- expressions: GrammarBuilderExpression[];
63
- postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
64
- }
65
- export interface GrammarBuilderExpression {
66
- symbols: GrammarBuilderSymbol[];
67
- postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
68
- }
69
- export type GrammarBuilderSymbol = GrammarTypeRule | GrammarTypeRegex | GrammarTypeToken | GrammarTypeLiteral | GrammarBuilderSymbolRepeat | GrammarBuilderSymbolSubexpression;
70
- export interface GrammarBuilderSymbolSubexpression {
71
- subexpression: GrammarBuilderExpression[];
72
- }
73
- export interface GrammarBuilderSymbolRepeat {
74
- expression: GrammarBuilderSymbol;
75
- repeat: "+" | "*" | "?";
76
- }
77
- export interface GrammarTypeRule {
78
- rule: string;
79
- }
80
- export interface GrammarTypeRegex {
81
- regex: string;
82
- flags?: string;
83
- }
84
- export interface GrammarTypeToken {
85
- token: string;
86
- }
87
- export interface GrammarTypeLiteral {
88
- literal: string;
89
- insensitive?: boolean;
90
- }
91
- export type GrammarTypeBuiltIn = {
92
- builtin: string;
93
- };
94
- export type GrammarTypeTemplate = {
95
- template: string;
96
- };
97
- export type GrammarTypeJS = {
98
- js: string;
99
- };
100
- export type ParserAlgorithm = ((language: LanguageDefinition & {
101
- tokens: TokenBuffer;
102
- utility: ParserUtility;
103
- }, options?: any) => {
104
- results: any[];
105
- info?: any;
106
- });
107
- export type LanguageDirective = (JavascriptDirective | ImportDirective | ConfigDirective | GrammarDirective | LexerDirective);
108
- type GrammarRuleSymbolFunction = (data: LexerToken) => boolean;
109
- export interface GrammarRule {
110
- name: string;
111
- symbols: GrammarRuleSymbol[];
112
- postprocess?: PostProcessor;
113
- }
114
- export type GrammarRuleSymbol = string | RegExp | GrammarTypeLiteral | GrammarTypeToken | GrammarRuleSymbolFunction;
115
- export interface GeneratorGrammarRule {
116
- name: string;
117
- symbols: GeneratorGrammarSymbol[];
118
- postprocess?: GrammarTypeTemplate | GrammarTypeBuiltIn | GrammarTypeJS;
119
- }
120
- export type GeneratorGrammarSymbol = {
121
- alias?: string;
122
- } & (GrammarTypeRule | GrammarTypeRegex | GrammarTypeLiteral | GrammarTypeToken);
123
- export interface LanguageDefinition {
124
- lexer?: Lexer | LexerConfig;
125
- grammar: {
126
- start: string;
127
- rules: Dictionary<GrammarRule[]>;
128
- };
129
- lr?: {
130
- k: number;
131
- table: Dictionary<LRState>;
132
- };
133
- }
134
- export interface LRState {
135
- actions: Next[];
136
- goto: {
137
- [key: string]: string;
138
- };
139
- reduce?: GrammarRule;
140
- isFinal: boolean;
141
- }
142
- type Next = {
143
- symbol: GrammarRuleSymbol;
144
- next: string;
145
- };
146
- export interface TQRestorePoint {
147
- historyIndex: number;
148
- offset: number;
149
- }
150
- export interface Lexer {
151
- next(): LexerToken | undefined;
152
- feed(chunk?: string, state?: ReturnType<Lexer['state']>): void;
153
- state(): any;
154
- flush?(): void;
155
- }
156
- export interface LexerToken {
157
- type?: string | undefined;
158
- tag?: Set<string>;
159
- value: string;
160
- offset: number;
161
- line: number;
162
- column: number;
163
- }
164
- export interface LexerStatus {
165
- index: number;
166
- line: number;
167
- column: number;
168
- state: string;
169
- }
170
- export interface LexerStateDefinition {
171
- name: string;
172
- unmatched?: string;
173
- default?: string;
174
- rules: (LexerStateImportRule | LexerStateMatchRule)[];
175
- }
176
- export interface LexerStateImportRule {
177
- import: string[];
178
- }
179
- export interface LexerStateMatchRule {
180
- when: string | RegExp;
181
- type?: string;
182
- tag?: string[];
183
- pop?: number | 'all';
184
- before?: boolean;
185
- highlight?: string;
186
- open?: string;
187
- close?: string;
188
- embed?: string;
189
- unembed?: boolean;
190
- inset?: number;
191
- goto?: string;
192
- set?: string;
193
- }
194
- export interface ResolvedStateDefinition {
195
- name: string;
196
- unmatched?: string;
197
- rules: LexerStateMatchRule[];
198
- }
199
- export interface CompiledStateDefinition {
200
- regexp: RegExp;
201
- unmatched?: LexerStateMatchRule;
202
- rules: LexerStateMatchRule[];
203
- }
204
- export interface LexerConfig {
205
- start?: string;
206
- states: Dictionary<LexerStateDefinition>;
207
- }
208
- export interface GeneratorState {
209
- version: string;
210
- config: Dictionary<string>;
211
- head: string[];
212
- body: string[];
213
- lexer?: LexerConfig;
214
- grammar: {
215
- start: string;
216
- config: {
217
- postprocessorDefault?: GrammarTypeJS | GrammarTypeTemplate;
218
- postprocessorOverride?: GrammarTypeJS | GrammarTypeTemplate;
219
- };
220
- rules: Dictionary<GeneratorGrammarRule[]>;
221
- uuids: {
222
- [key: string]: number;
223
- };
224
- };
225
- }
226
- export {};
package/build/typings.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=typings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typings.js","sourceRoot":"","sources":["../src/typings.ts"],"names":[],"mappings":""}
@@ -1,74 +0,0 @@
1
- import * from whitespace;
2
-
3
- lexer: {{
4
- start: "json"
5
-
6
- json ->
7
- - import: whitespace
8
- - when: /-?(?:[0-9]|[1-9][0-9]+)(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\b/ tag: "number"
9
- - when: /"(?:\\["bfnrt\/\\]|\\u[a-fA-F0-9]{4}|[^"\\])*"/ tag: "string"
10
- - when: "{" tag: "{"
11
- - when: "}" tag: "}"
12
- - when: "[" tag: "["
13
- - when: "]" tag: "]"
14
- - when: "," tag: ","
15
- - when: ":" tag: ":"
16
- - when: "true" tag: "true"
17
- - when: "false" tag: "false"
18
- - when: "null" tag: "null"
19
- }}
20
-
21
- grammar: {{
22
- json -> _ (object | array) _ : {{ $1[0] }}
23
-
24
- object -> "{" _ "}" : {{ {} }}
25
- | "{" _ pair (_ "," _ pair)* _ "}" : ${ extractObject }
26
-
27
- array -> "[" _ "]" : {{ [] }}
28
- | "[" _ value (_ "," _ value)* _ "]" : ${ extractArray }
29
-
30
- value : {{ $0 }} ->
31
- object
32
- | array
33
- | number
34
- | string
35
- | "true" : {{ true }}
36
- | "false" : {{ false }}
37
- | "null" : {{ null }}
38
-
39
- number -> $number : {{ parseFloat($0.value) }}
40
-
41
- string -> $string : {{ JSON.parse($0.value) }}
42
-
43
- pair -> key:k _ ":" _ value:v : {{ [$k, $v] }}
44
-
45
- key -> string : {{ $0 }}
46
- }}
47
-
48
- head: ${
49
- function extractPair(kv, output) {
50
- if(kv[0]) { output[kv[0]] = kv[1]; }
51
- }
52
-
53
- function extractObject({data}) {
54
- let output = {};
55
-
56
- extractPair(data[2], output);
57
-
58
- for (let i in data[3]) {
59
- extractPair(data[3][i][3], output);
60
- }
61
-
62
- return output;
63
- }
64
-
65
- function extractArray({data}) {
66
- let output = [data[2]];
67
-
68
- for (let i in data[3]) {
69
- output.push(data[3][i][3]);
70
- }
71
-
72
- return output;
73
- }
74
- }
@@ -1,20 +0,0 @@
1
- grammar: {{
2
-
3
- unsigned_int ->
4
- /[0-9]/+ : {{ parseInt($0.join("")) }}
5
-
6
- int ->
7
- ("-"|"+")? /[0-9]/+ : {{ $0 ? parseInt($0[0]+$1.join("")) : parseInt($1.join("")) }}
8
-
9
- unsigned_decimal ->
10
- /[0-9]/+ ("." /[0-9]/+)? : {{ parseFloat($0.join("") + ($1 ? "."+$1[1].join("") : "")) }}
11
-
12
- decimal ->
13
- "-"? /[0-9]/+ ("." /[0-9]/+)? : {{ parseFloat( ($0 || "") + $1.join("") +($2 ? "."+$2[1].join("") : "")) }}
14
-
15
- percentage ->
16
- decimal "%" : {{ $0/100 }}
17
-
18
- jsonfloat ->
19
- "-"? /[0-9]/+ ("." /[0-9]/+)? (/[eE]/ /[+-]/? /[0-9]/+)? : {{ parseFloat( ($0 || "") + $1.join("") + ($2 ? "."+$2[1].join("") : "") + ($3 ? "e" + ($3[1] || "+") + $3[2].join("") : "")) }}
20
- }}
@@ -1,48 +0,0 @@
1
- lexer: {{
2
- string ->
3
- - import: singleQuoteString, doubleQuoteString
4
-
5
- doubleQuoteString ->
6
- - when: /"/ tag: "dquote" highlight:"string" goto: doubleQuoteStringEnd
7
-
8
- singleQuoteString ->
9
- - when: /'/ tag: "squote" highlight:"string" goto: singleQuoteStringEnd
10
-
11
- doubleQuoteStringEnd ->
12
- - when: /\\[\\\/bnrft]/ tag: "escaped" highlight:"constant"
13
- - when: /\\"/ tag: "quoteEscape"
14
- - when: /\\u[A-Fa-f\d]{4}/ tag: "escaped" highlight:"constant"
15
- - when: /\\./ tag:"badEscape"
16
- - when: /[^"\\]+/ tag: "string" highlight:"string"
17
- - when: "\"" tag: "dquote" highlight:"string" pop
18
-
19
- singleQuoteStringEnd ->
20
- - when: /\\[\\\/bnrft]/ tag: "escaped"
21
- - when: /\\'/ tag: "quoteEscape"
22
- - when: /\\u[A-Fa-f\d]{4}/ tag: "escaped"
23
- - when: /\\./ tag:"badEscape"
24
- - when: /[^'\\]+/ tag: "string" highlight:"string"
25
- - when: "'" tag: "squote" highlight:"string" pop
26
- }}
27
-
28
- grammar: {{
29
- string : {{ $0 }}
30
- -> singleQuoteString
31
- | doubleQuoteString
32
-
33
- doubleQuoteString
34
- -> $dquote stringInner $dquote : {{ $1 }}
35
- | $dquote $dquote : {{ '' }}
36
-
37
- singleQuoteString
38
- -> $squote stringInner $squote : {{ $1 }}
39
- | $squote $squote : {{ '' }}
40
-
41
- stringInner -> stringEscape : {{ $0 }}
42
- | $string : {{ $0.value }}
43
- | stringInner stringEscape : {{ $0 + $1 }}
44
- | stringInner $string : {{ $0 + $1.value }}
45
-
46
- stringEscape -> $escaped : {{ JSON.parse('"' +$0.value + '"') }}
47
- | $quoteEscape : {{ $0.value[1] }}
48
- }}
@@ -1,10 +0,0 @@
1
- lexer: {{
2
- start: "whitespace"
3
- whitespace ->
4
- - when: /\s+/ tag: "whitespace"
5
- }}
6
-
7
- grammar: {{
8
- _ -> $whitespace* : {{ null }}
9
- __ -> $whitespace+ : {{ null }}
10
- }}
@@ -1 +0,0 @@
1
- {"json":"import * from whitespace;\r\n\r\nlexer: {{\r\n start: \"json\"\r\n\r\n json ->\r\n - import: whitespace\r\n - when: /-?(?:[0-9]|[1-9][0-9]+)(?:\\.[0-9]+)?(?:[eE][-+]?[0-9]+)?\\b/ tag: \"number\"\r\n - when: /\"(?:\\\\[\"bfnrt\\/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\"\\\\])*\"/ tag: \"string\"\r\n - when: \"{\" tag: \"{\"\r\n - when: \"}\" tag: \"}\"\r\n - when: \"[\" tag: \"[\"\r\n - when: \"]\" tag: \"]\"\r\n - when: \",\" tag: \",\"\r\n - when: \":\" tag: \":\"\r\n - when: \"true\" tag: \"true\"\r\n - when: \"false\" tag: \"false\"\r\n - when: \"null\" tag: \"null\"\r\n}}\r\n\r\ngrammar: {{\r\n json -> _ (object | array) _ : {{ $1[0] }}\r\n\r\n object -> \"{\" _ \"}\" : {{ {} }}\r\n | \"{\" _ pair (_ \",\" _ pair)* _ \"}\" : ${ extractObject }\r\n\r\n array -> \"[\" _ \"]\" : {{ [] }}\r\n | \"[\" _ value (_ \",\" _ value)* _ \"]\" : ${ extractArray }\r\n\r\n value : {{ $0 }} ->\r\n object\r\n | array\r\n | number\r\n | string\r\n | \"true\" : {{ true }}\r\n | \"false\" : {{ false }}\r\n | \"null\" : {{ null }}\r\n\r\n number -> $number : {{ parseFloat($0.value) }}\r\n\r\n string -> $string : {{ JSON.parse($0.value) }}\r\n\r\n pair -> key:k _ \":\" _ value:v : {{ [$k, $v] }}\r\n\r\n key -> string : {{ $0 }}\r\n}}\r\n\r\nhead: ${\r\n function extractPair(kv, output) {\r\n if(kv[0]) { output[kv[0]] = kv[1]; }\r\n }\r\n\r\n function extractObject({data}) {\r\n let output = {};\r\n\r\n extractPair(data[2], output);\r\n\r\n for (let i in data[3]) {\r\n extractPair(data[3][i][3], output);\r\n }\r\n\r\n return output;\r\n }\r\n\r\n function extractArray({data}) {\r\n let output = [data[2]];\r\n\r\n for (let i in data[3]) {\r\n output.push(data[3][i][3]);\r\n }\r\n\r\n return output;\r\n }\r\n}\r\n","number":"grammar: {{\r\n\r\n unsigned_int -> \r\n /[0-9]/+ : {{ parseInt($0.join(\"\")) }}\r\n\r\n int -> \r\n (\"-\"|\"+\")? /[0-9]/+ : {{ $0 ? parseInt($0[0]+$1.join(\"\")) : parseInt($1.join(\"\")) }}\r\n\r\n unsigned_decimal -> \r\n /[0-9]/+ (\".\" /[0-9]/+)? : {{ parseFloat($0.join(\"\") + ($1 ? \".\"+$1[1].join(\"\") : \"\")) }}\r\n\r\n decimal -> \r\n \"-\"? /[0-9]/+ (\".\" /[0-9]/+)? : {{ parseFloat( ($0 || \"\") + $1.join(\"\") +($2 ? \".\"+$2[1].join(\"\") : \"\")) }}\r\n\r\n percentage -> \r\n decimal \"%\" : {{ $0/100 }}\r\n \r\n jsonfloat -> \r\n \"-\"? /[0-9]/+ (\".\" /[0-9]/+)? (/[eE]/ /[+-]/? /[0-9]/+)? : {{ parseFloat( ($0 || \"\") + $1.join(\"\") + ($2 ? \".\"+$2[1].join(\"\") : \"\") + ($3 ? \"e\" + ($3[1] || \"+\") + $3[2].join(\"\") : \"\")) }}\r\n}}","string":"lexer: {{\r\n string ->\r\n - import: singleQuoteString, doubleQuoteString\r\n\r\n doubleQuoteString ->\r\n - when: /\"/ tag: \"dquote\" highlight:\"string\" goto: doubleQuoteStringEnd \r\n\r\n singleQuoteString ->\r\n - when: /'/ tag: \"squote\" highlight:\"string\" goto: singleQuoteStringEnd \r\n\r\n doubleQuoteStringEnd ->\r\n - when: /\\\\[\\\\\\/bnrft]/ tag: \"escaped\" highlight:\"constant\"\r\n - when: /\\\\\"/ tag: \"quoteEscape\"\r\n - when: /\\\\u[A-Fa-f\\d]{4}/ tag: \"escaped\" highlight:\"constant\"\r\n - when: /\\\\./ tag:\"badEscape\"\r\n - when: /[^\"\\\\]+/ tag: \"string\" highlight:\"string\"\r\n - when: \"\\\"\" tag: \"dquote\" highlight:\"string\" pop\r\n\r\n singleQuoteStringEnd ->\r\n - when: /\\\\[\\\\\\/bnrft]/ tag: \"escaped\"\r\n - when: /\\\\'/ tag: \"quoteEscape\"\r\n - when: /\\\\u[A-Fa-f\\d]{4}/ tag: \"escaped\" \r\n - when: /\\\\./ tag:\"badEscape\"\r\n - when: /[^'\\\\]+/ tag: \"string\" highlight:\"string\"\r\n - when: \"'\" tag: \"squote\" highlight:\"string\" pop\r\n}}\r\n\r\ngrammar: {{\r\n string : {{ $0 }} \r\n -> singleQuoteString \r\n | doubleQuoteString \r\n\r\n doubleQuoteString \r\n -> $dquote stringInner $dquote : {{ $1 }}\r\n | $dquote $dquote : {{ '' }}\r\n \r\n singleQuoteString \r\n -> $squote stringInner $squote : {{ $1 }}\r\n | $squote $squote : {{ '' }}\r\n\r\n stringInner -> stringEscape : {{ $0 }}\r\n | $string : {{ $0.value }}\r\n | stringInner stringEscape : {{ $0 + $1 }}\r\n | stringInner $string : {{ $0 + $1.value }}\r\n \r\n stringEscape -> $escaped : {{ JSON.parse('\"' +$0.value + '\"') }}\r\n | $quoteEscape : {{ $0.value[1] }}\r\n}}","whitespace":"lexer: {{\r\n start: \"whitespace\"\r\n whitespace ->\r\n - when: /\\s+/ tag: \"whitespace\" \r\n}}\r\n\r\ngrammar: {{\r\n _ -> $whitespace* : {{ null }}\r\n __ -> $whitespace+ : {{ null }}\r\n}}"}