grammar-composer 0.1.0

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 (57) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +387 -0
  3. package/dist/Exports.d.ts +1 -0
  4. package/dist/Exports.js +2 -0
  5. package/dist/Exports.js.map +1 -0
  6. package/dist/Grammar.d.ts +62 -0
  7. package/dist/Grammar.js +376 -0
  8. package/dist/Grammar.js.map +1 -0
  9. package/dist/GrammarComposer.d.ts +61 -0
  10. package/dist/GrammarComposer.js +383 -0
  11. package/dist/GrammarComposer.js.map +1 -0
  12. package/dist/Grammars/JsonGrammar.d.ts +16 -0
  13. package/dist/Grammars/JsonGrammar.js +74 -0
  14. package/dist/Grammars/JsonGrammar.js.map +1 -0
  15. package/dist/Grammars/XmlGrammar.d.ts +13 -0
  16. package/dist/Grammars/XmlGrammar.js +74 -0
  17. package/dist/Grammars/XmlGrammar.js.map +1 -0
  18. package/dist/ParserTest.d.ts +1 -0
  19. package/dist/ParserTest.js +37 -0
  20. package/dist/ParserTest.js.map +1 -0
  21. package/dist/Test.d.ts +1 -0
  22. package/dist/Test.js +74 -0
  23. package/dist/Test.js.map +1 -0
  24. package/dist/TestData.d.ts +5 -0
  25. package/dist/TestData.js +466 -0
  26. package/dist/TestData.js.map +1 -0
  27. package/dist/TopDownParser.d.ts +13 -0
  28. package/dist/TopDownParser.js +229 -0
  29. package/dist/TopDownParser.js.map +1 -0
  30. package/dist/data/TestData.d.ts +5 -0
  31. package/dist/data/TestData.js +466 -0
  32. package/dist/data/TestData.js.map +1 -0
  33. package/dist/test-data/TestData.d.ts +5 -0
  34. package/dist/test-data/TestData.js +466 -0
  35. package/dist/test-data/TestData.js.map +1 -0
  36. package/dist/test-grammars/JsonGrammar.d.ts +17 -0
  37. package/dist/test-grammars/JsonGrammar.js +74 -0
  38. package/dist/test-grammars/JsonGrammar.js.map +1 -0
  39. package/dist/test-grammars/XmlGrammar.d.ts +14 -0
  40. package/dist/test-grammars/XmlGrammar.js +74 -0
  41. package/dist/test-grammars/XmlGrammar.js.map +1 -0
  42. package/dist/utilities/Timer.d.ts +13 -0
  43. package/dist/utilities/Timer.js +70 -0
  44. package/dist/utilities/Timer.js.map +1 -0
  45. package/dist/utilities/utilities.d.ts +8 -0
  46. package/dist/utilities/utilities.js +26 -0
  47. package/dist/utilities/utilities.js.map +1 -0
  48. package/package.json +40 -0
  49. package/src/GrammarComposer.ts +541 -0
  50. package/src/Test.ts +101 -0
  51. package/src/TopDownParser.ts +304 -0
  52. package/src/test-data/TestData.ts +470 -0
  53. package/src/test-grammars/JsonGrammar.ts +118 -0
  54. package/src/test-grammars/XmlGrammar.ts +141 -0
  55. package/src/utilities/Timer.ts +95 -0
  56. package/src/utilities/Utilities.ts +33 -0
  57. package/tsconfig.json +105 -0
@@ -0,0 +1,470 @@
1
+ export const jsonSample1 = JSON.stringify([
2
+ {
3
+ "yo": 23,
4
+ "man": "hey"
5
+ }
6
+ ], undefined, 4)
7
+
8
+ export const jsonSample2 = JSON.stringify({
9
+ "web-app": {
10
+ "servlet": [
11
+ {
12
+ "servlet-name": "cofaxCDS",
13
+ "servlet-class": "org.cofax.cds.CDSServlet",
14
+ "init-param": {
15
+ "configGlossary:installationAt": "Philadelphia, PA",
16
+ "configGlossary:adminEmail": "ksm@pobox.com",
17
+ "configGlossary:poweredBy": "Cofax",
18
+ "configGlossary:poweredByIcon": "/images/cofax.gif",
19
+ "configGlossary:staticPath": "/content/static",
20
+ "templateProcessorClass": "org.cofax.WysiwygTemplate",
21
+ "templateLoaderClass": "org.cofax.FilesTemplateLoader",
22
+ "templatePath": "templates",
23
+ "templateOverridePath": "",
24
+ "defaultListTemplate": "listTemplate.htm",
25
+ "defaultFileTemplate": "articleTemplate.htm",
26
+ "useJSP": false,
27
+ "jspListTemplate": "listTemplate.jsp",
28
+ "jspFileTemplate": "articleTemplate.jsp",
29
+ "cachePackageTagsTrack": 200,
30
+ "cachePackageTagsStore": 200,
31
+ "cachePackageTagsRefresh": 60,
32
+ "cacheTemplatesTrack": 100,
33
+ "cacheTemplatesStore": 50,
34
+ "cacheTemplatesRefresh": 15,
35
+ "cachePagesTrack": 200,
36
+ "cachePagesStore": 100,
37
+ "cachePagesRefresh": 10,
38
+ "cachePagesDirtyRead": 10,
39
+ "searchEngineListTemplate": "forSearchEnginesList.htm",
40
+ "searchEngineFileTemplate": "forSearchEngines.htm",
41
+ "searchEngineRobotsDb": "WEB-INF/robots.db",
42
+ "useDataStore": true,
43
+ "dataStoreClass": "org.cofax.SqlDataStore",
44
+ "redirectionClass": "org.cofax.SqlRedirection",
45
+ "dataStoreName": "cofax",
46
+ "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
47
+ "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
48
+ "dataStoreUser": "sa",
49
+ "dataStorePassword": "dataStoreTestQuery",
50
+ "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
51
+ "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
52
+ "dataStoreInitConns": 10,
53
+ "dataStoreMaxConns": 100,
54
+ "dataStoreConnUsageLimit": 100,
55
+ "dataStoreLogLevel": "debug",
56
+ "maxUrlLength": 500
57
+ }
58
+ },
59
+ {
60
+ "servlet-name": "cofaxEmail",
61
+ "servlet-class": "org.cofax.cds.EmailServlet",
62
+ "init-param": {
63
+ "mailHost": "mail1",
64
+ "mailHostOverride": "mail2"
65
+ }
66
+ },
67
+ {
68
+ "servlet-name": "cofaxAdmin",
69
+ "servlet-class": "org.cofax.cds.AdminServlet"
70
+ },
71
+
72
+ {
73
+ "servlet-name": "fileServlet",
74
+ "servlet-class": "org.cofax.cds.FileServlet"
75
+ },
76
+ {
77
+ "servlet-name": "cofaxTools",
78
+ "servlet-class": "org.cofax.cms.CofaxToolsServlet",
79
+ "init-param": {
80
+ "templatePath": "toolstemplates/",
81
+ "log": 1,
82
+ "logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
83
+ "logMaxSize": "",
84
+ "dataLog": 1,
85
+ "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
86
+ "dataLogMaxSize": "",
87
+ "removePageCache": "/content/admin/remove?cache=pages&id=",
88
+ "removeTemplateCache": "/content/admin/remove?cache=templates&id=",
89
+ "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
90
+ "lookInContext": 1,
91
+ "adminGroupID": 4,
92
+ "betaServer": true
93
+ }
94
+ }],
95
+ "servlet-mapping": {
96
+ "cofaxCDS": "/",
97
+ "cofaxEmail": "/cofaxutil/aemail/*",
98
+ "cofaxAdmin": "/admin/*",
99
+ "fileServlet": "/static/*",
100
+ "cofaxTools": "/tools/*"
101
+ },
102
+
103
+ "taglib": {
104
+ "taglib-uri": "cofax.tld",
105
+ "taglib-location": "/WEB-INF/tlds/cofax.tld"
106
+ }
107
+ }
108
+ }, undefined, 4)
109
+
110
+ export const xmlSample1 = `
111
+
112
+ <menu>
113
+ <popup>
114
+ <test value='New'>
115
+ <!--<menuitem value="New" onclick="CreateNewDoc()" />-->
116
+ <menuitem value="Open" onclick="OpenDoc()" />
117
+ <menuitem value="Close" onclick="CloseDoc()" />
118
+ </popup>
119
+ </menu>`
120
+
121
+ export const xmlSample2 = `
122
+ <!DOCTYPE web-app
123
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
124
+ "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
125
+
126
+ <menu>
127
+ <header>Adobe SVG Viewer</header>
128
+ <item action="Open" id="Open">Open</item>
129
+ <item action="OpenNew" id="OpenNew">Open New</item>
130
+ <separator/>
131
+ <item action="ZoomIn" id="ZoomIn">Zoom In</item>
132
+ <item action="ZoomOut" id="ZoomOut">Zoom Out</item>
133
+ <item action="OriginalView" id="OriginalView">Original View</item>
134
+ <separator/>
135
+ <item action="Quality" id="Quality">Quality</item>
136
+ <item action="Pause" id="Pause">Pause</item>
137
+ <item action="Mute" id="Mute">Mute</item>
138
+ <separator/>
139
+ <item action="Find" id="Find">Find...</item>
140
+ <item action="FindAgain" id="FindAgain">Find Again</item>
141
+ <item action="Copy" id="Copy">Copy</item>
142
+ <item action="CopyAgain" id="CopyAgain">Copy Again</item>
143
+ <item action="CopySVG" id="CopySVG">Copy SVG</item>
144
+ <item action="ViewSVG" id="ViewSVG">View SVG</item>
145
+ <item action="ViewSource" id="ViewSource">View Source</item>
146
+ <item action="SaveAs" id="SaveAs">Save As</item>
147
+ <separator/>
148
+ <item action="Help" id="Help">Help</item>
149
+ <item action="About" id="About">About Adobe CVG Viewer...</item>
150
+ </menu>`
151
+
152
+ export const xmlSample3 = `
153
+ <!DOCTYPE web-app
154
+ PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
155
+ "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
156
+ <web-app>
157
+ <servlet>
158
+ <servlet-name>
159
+ cofaxCDS
160
+ </servlet-name>
161
+ <servlet-class>
162
+ org.cofax.cds.CDSServlet
163
+ </servlet-class>
164
+ <init-param>
165
+ <param-name>configGlossary:installationAt</param-name>
166
+ <param-value>Philadelphia, PA</param-value>
167
+ </init-param>
168
+ <init-param>
169
+ <param-name>configGlossary:adminEmail</param-name>
170
+ <param-value>ksm@pobox.com</param-value>
171
+ </init-param>
172
+ <init-param>
173
+ <param-name>configGlossary:poweredBy</param-name>
174
+ <param-value>Cofax</param-value>
175
+ </init-param>
176
+ <init-param>
177
+ <param-name>configGlossary:poweredByIcon</param-name>
178
+ <param-value>/images/cofax.gif</param-value>
179
+ </init-param>
180
+ <init-param>
181
+ <param-name>configGlossary:staticPath</param-name>
182
+ <param-value>/content/static</param-value>
183
+ </init-param>
184
+ <init-param>
185
+ <param-name>templateProcessorClass</param-name>
186
+ <param-value>org.cofax.WysiwygTemplate</param-value>
187
+ </init-param>
188
+ <init-param>
189
+ <param-name>templateLoaderClass</param-name>
190
+ <param-value>org.cofax.FilesTemplateLoader</param-value>
191
+ </init-param>
192
+ <init-param>
193
+ <param-name>templatePath</param-name>
194
+ <param-value>templates</param-value>
195
+ </init-param>
196
+ <init-param>
197
+ <param-name>templateOverridePath</param-name>
198
+ <param-value></param-value>
199
+ </init-param>
200
+ <init-param>
201
+ <param-name>defaultListTemplate</param-name>
202
+ <param-value>listTemplate.htm</param-value>
203
+ </init-param>
204
+ <init-param>
205
+ <param-name>defaultFileTemplate</param-name>
206
+ <param-value>articleTemplate.htm</param-value>
207
+ </init-param>
208
+ <init-param>
209
+ <param-name>useJSP</param-name>
210
+ <param-value>false</param-value>
211
+ </init-param>
212
+ <init-param>
213
+ <param-name>jspListTemplate</param-name>
214
+ <param-value>listTemplate.jsp</param-value>
215
+ </init-param>
216
+ <init-param>
217
+ <param-name>jspFileTemplate</param-name>
218
+ <param-value>articleTemplate.jsp</param-value>
219
+ </init-param>
220
+ <init-param>
221
+ <param-name>cachePackageTagsTrack</param-name>
222
+ <param-value>200</param-value>
223
+ </init-param>
224
+ <init-param>
225
+ <param-name>cachePackageTagsStore</param-name>
226
+ <param-value>200</param-value>
227
+ </init-param>
228
+ <init-param>
229
+ <param-name>cachePackageTagsRefresh</param-name>
230
+ <param-value>60</param-value>
231
+ </init-param>
232
+ <init-param>
233
+ <param-name>cacheTemplatesTrack</param-name>
234
+ <param-value>100</param-value>
235
+ </init-param>
236
+ <init-param>
237
+ <param-name>cacheTemplatesStore</param-name>
238
+ <param-value>50</param-value>
239
+ </init-param>
240
+ <init-param>
241
+ <param-name>cacheTemplatesRefresh</param-name>
242
+ <param-value>15</param-value>
243
+ </init-param>
244
+ <init-param>
245
+ <param-name>cachePagesTrack</param-name>
246
+ <param-value>200</param-value>
247
+ </init-param>
248
+ <init-param>
249
+ <param-name>cachePagesStore</param-name>
250
+ <param-value>100</param-value>
251
+ </init-param>
252
+ <init-param>
253
+ <param-name>cachePagesRefresh</param-name>
254
+ <param-value>10</param-value>
255
+ </init-param>
256
+ <init-param>
257
+ <param-name>cachePagesDirtyRead</param-name>
258
+ <param-value>10</param-value>
259
+ </init-param>
260
+ <init-param>
261
+ <param-name>searchEngineListTemplate</param-name>
262
+ <param-value>forSearchEnginesList.htm</param-value>
263
+ </init-param>
264
+ <init-param>
265
+ <param-name>searchEngineFileTemplate</param-name>
266
+ <param-value>forSearchEngines.htm</param-value>
267
+ </init-param>
268
+ <init-param>
269
+ <param-name>searchEngineRobotsDb</param-name>
270
+ <param-value>WEB-INF/robots.db</param-value>
271
+ </init-param>
272
+ <init-param>
273
+ <param-name>useDataStore</param-name>
274
+ <param-value>true</param-value>
275
+ </init-param>
276
+ <init-param>
277
+ <param-name>dataStoreClass</param-name>
278
+ <param-value>org.cofax.SqlDataStore</param-value>
279
+ </init-param>
280
+ <init-param>
281
+ <param-name>redirectionClass</param-name>
282
+ <param-value>org.cofax.SqlRedirection</param-value>
283
+ </init-param>
284
+ <init-param>
285
+ <param-name>dataStoreName</param-name>
286
+ <param-value>cofax</param-value>
287
+ </init-param>
288
+ <init-param>
289
+ <param-name>dataStoreDriver</param-name>
290
+ <param-value>com.microsoft.jdbc.sqlserver.SQLServerDriver</param-value>
291
+ </init-param>
292
+ <init-param>
293
+ <param-name>dataStoreUrl</param-name>
294
+ <param-value>jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon</param-value>
295
+ </init-param>
296
+ <init-param>
297
+ <param-name>dataStoreUser</param-name>
298
+ <param-value>sa</param-value>
299
+ </init-param>
300
+ <init-param>
301
+ <param-name>dataStorePassword</param-name>
302
+ <param-value></param-value>
303
+ </init-param>
304
+ <init-param>
305
+ <param-name>dataStoreTestQuery</param-name>
306
+ <param-value>SET NOCOUNT ON;select test='test';</param-value>
307
+ </init-param>
308
+ <init-param>
309
+ <param-name>dataStoreLogFile</param-name>
310
+ <param-value>/usr/local/tomcat/logs/datastore.log</param-value>
311
+ </init-param>
312
+ <init-param>
313
+ <param-name>dataStoreInitConns</param-name>
314
+ <param-value>10</param-value>
315
+ </init-param>
316
+ <init-param>
317
+ <param-name>dataStoreMaxConns</param-name>
318
+ <param-value>100</param-value>
319
+ </init-param>
320
+ <init-param>
321
+ <param-name>dataStoreConnUsageLimit</param-name>
322
+ <param-value>100</param-value>
323
+ </init-param>
324
+ <init-param>
325
+ <param-name>dataStoreLogLevel</param-name>
326
+ <param-value>debug</param-value>
327
+ </init-param>
328
+ <init-param>
329
+ <param-name>maxUrlLength</param-name>
330
+ <param-value>500</param-value>
331
+ </init-param>
332
+ </servlet>
333
+ <servlet>
334
+ <servlet-name>
335
+ cofaxEmail
336
+ </servlet-name>
337
+ <servlet-class>
338
+ org.cofax.cds.EmailServlet
339
+ </servlet-class>
340
+ <init-param>
341
+ <param-name>mailHost</param-name>
342
+ <param-value>mail1</param-value>
343
+ </init-param>
344
+ <init-param>
345
+ <param-name>mailHostOverride</param-name>
346
+ <param-value>mail2</param-value>
347
+ </init-param>
348
+ </servlet>
349
+ <servlet>
350
+ <servlet-name>
351
+ cofaxAdmin
352
+ </servlet-name>
353
+ <servlet-class>
354
+ org.cofax.cds.AdminServlet
355
+ </servlet-class>
356
+ </servlet>
357
+ <servlet>
358
+ <servlet-name>
359
+ fileServlet
360
+ </servlet-name>
361
+ <servlet-class>
362
+ org.cofax.cds.FileServlet
363
+ </servlet-class>
364
+ </servlet>
365
+ <servlet>
366
+ <servlet-name>
367
+ cofaxTools
368
+ </servlet-name>
369
+ <servlet-class>
370
+ org.cofax.cms.CofaxToolsServlet
371
+ </servlet-class>
372
+ <init-param>
373
+ <param-name>templatePath</param-name>
374
+ <param-value>toolstemplates/</param-value>
375
+ </init-param>
376
+ <init-param>
377
+ <param-name>log</param-name>
378
+ <param-value>1</param-value>
379
+ </init-param>
380
+ <init-param>
381
+ <param-name>logLocation</param-name>
382
+ <param-value>/usr/local/tomcat/logs/CofaxTools.log</param-value>
383
+ </init-param>
384
+ <init-param>
385
+ <param-name>logMaxSize</param-name>
386
+ <param-value></param-value>
387
+ </init-param>
388
+ <init-param>
389
+ <param-name>dataLog</param-name>
390
+ <param-value>1</param-value>
391
+ </init-param>
392
+ <init-param>
393
+ <param-name>dataLogLocation</param-name>
394
+ <param-value>/usr/local/tomcat/logs/dataLog.log</param-value>
395
+ </init-param>
396
+ <init-param>
397
+ <param-name>dataLogMaxSize</param-name>
398
+ <param-value></param-value>
399
+ </init-param>
400
+ <init-param>
401
+ <param-name>removePageCache</param-name>
402
+ <param-value>/content/admin/remove?cache=pages&id=</param-value>
403
+ </init-param>
404
+ <init-param>
405
+ <param-name>removeTemplateCache</param-name>
406
+ <param-value>/content/admin/remove?cache=templates&id=</param-value>
407
+ </init-param>
408
+ <init-param>
409
+ <param-name>fileTransferFolder</param-name>
410
+ <param-value>/usr/local/tomcat/webapps/content/fileTransferFolder</param-value>
411
+ </init-param>
412
+ <init-param>
413
+ <param-name>lookInContext</param-name>
414
+ <param-value>1</param-value>
415
+ </init-param>
416
+ <init-param>
417
+ <param-name>adminGroupID</param-name>
418
+ <param-value>4</param-value>
419
+ </init-param>
420
+ <init-param>
421
+ <param-name>betaServer</param-name>
422
+ <param-value>true</param-value>
423
+ </init-param>
424
+ </servlet>
425
+ <servlet-mapping>
426
+ <servlet-name>
427
+ cofaxCDS
428
+ </servlet-name>
429
+ <url-pattern>
430
+ /
431
+ </url-pattern>
432
+ </servlet-mapping>
433
+ <servlet-mapping>
434
+ <servlet-name>
435
+ cofaxEmail
436
+ </servlet-name>
437
+ <url-pattern>
438
+ /cofaxutil/aemail/*
439
+ </url-pattern>
440
+ </servlet-mapping>
441
+ <servlet-mapping>
442
+ <servlet-name>
443
+ cofaxAdmin
444
+ </servlet-name>
445
+ <url-pattern>
446
+ /admin/*
447
+ </url-pattern>
448
+ </servlet-mapping>
449
+ <servlet-mapping>
450
+ <servlet-name>
451
+ fileServlet
452
+ </servlet-name>
453
+ <url-pattern>
454
+ /static/*
455
+ </url-pattern>
456
+ </servlet-mapping>
457
+ <servlet-mapping>
458
+ <servlet-name>
459
+ cofaxTools
460
+ </servlet-name>
461
+ <url-pattern>
462
+ /tools/*
463
+ </url-pattern>
464
+ </servlet-mapping>
465
+ <taglib>
466
+ <taglib-uri>cofax.tld</taglib-uri>
467
+ <taglib-location>/WEB-INF/tlds/cofax.tld</taglib-location>
468
+ </taglib>
469
+ </web-app>
470
+ `
@@ -0,0 +1,118 @@
1
+ import * as G from "../GrammarComposer.js"
2
+ import * as R from 'regexp-composer'
3
+
4
+ export class JsonGrammar {
5
+ expression = () => G.anyOf(
6
+ this.stringLiteral,
7
+ this.numberLiteral,
8
+ this.booleanLiteral,
9
+ this.nullLiteral,
10
+ this.objectExpression,
11
+ this.arrayExpression
12
+ )
13
+
14
+ objectExpression = () => [
15
+ this.openingCurlyBrace,
16
+
17
+ G.possibly([
18
+ this.objectPropertyExpression,
19
+ G.zeroOrMore([this.comma, this.objectPropertyExpression])
20
+ ]),
21
+
22
+ this.closingCurlyBrace,
23
+ ]
24
+
25
+ objectPropertyExpression = () => [
26
+ this.stringLiteral,
27
+ this.colons,
28
+ this.expression,
29
+ ]
30
+
31
+ arrayExpression = () => [
32
+ this.openingSquareBracket,
33
+
34
+ G.possibly([
35
+ this.expression,
36
+ G.zeroOrMore([this.comma, this.expression])
37
+ ]),
38
+
39
+ this.closingSquareBracket
40
+ ]
41
+
42
+ openingCurlyBrace = createPatternWithClearedWhitespace('{')
43
+ closingCurlyBrace = createPatternWithClearedWhitespace('}')
44
+
45
+ openingSquareBracket = createPatternWithClearedWhitespace('[')
46
+ closingSquareBracket = createPatternWithClearedWhitespace(']')
47
+
48
+ comma = createPatternWithClearedWhitespace(',')
49
+ colons = createPatternWithClearedWhitespace(':')
50
+
51
+ stringLiteral = G.pattern([
52
+ zeroOrMoreWhitespace,
53
+
54
+ '"',
55
+
56
+ R.matches(
57
+ R.captureAs('value',
58
+ R.zeroOrMoreNonGreedy(R.anyChar)
59
+ ),
60
+ {
61
+ ifNotPrecededBy: '\\'
62
+ }
63
+ ),
64
+
65
+ '"',
66
+
67
+ zeroOrMoreWhitespace,
68
+ ])
69
+
70
+ numberLiteral = G.pattern([
71
+ zeroOrMoreWhitespace,
72
+
73
+ R.captureAs('value', [
74
+ R.possibly('-'), // Sign
75
+ R.anyOf(
76
+ '0', // Zero only
77
+ [
78
+ R.charRange('1', '9'), // First digit
79
+ R.zeroOrMore(R.digit), // Next digits
80
+ ]
81
+ ),
82
+ R.possibly(['.', R.oneOrMore(R.digit)]), // Decimal value
83
+ R.possibly([R.anyOf('e', 'E'), R.anyOf('+', '-'), R.oneOrMore(R.digit)]), // Exponent
84
+ ]),
85
+
86
+ zeroOrMoreWhitespace,
87
+ ])
88
+
89
+ booleanLiteral = G.pattern([
90
+ zeroOrMoreWhitespace,
91
+
92
+ R.captureAs('value',
93
+ R.anyOf('true', 'false')
94
+ ),
95
+
96
+ zeroOrMoreWhitespace,
97
+ ])
98
+
99
+ nullLiteral = G.pattern([
100
+ zeroOrMoreWhitespace,
101
+
102
+ 'null',
103
+
104
+ zeroOrMoreWhitespace,
105
+ ])
106
+ }
107
+
108
+ function createPatternWithClearedWhitespace(str: string) {
109
+ return G.pattern([
110
+ zeroOrMoreWhitespace,
111
+
112
+ str,
113
+
114
+ zeroOrMoreWhitespace
115
+ ])
116
+ }
117
+
118
+ const zeroOrMoreWhitespace = R.zeroOrMore(R.whitespace)