rley 0.8.03 → 0.8.05

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +28 -8
  3. data/CHANGELOG.md +10 -0
  4. data/examples/data_formats/JSON/README.md +34 -0
  5. data/examples/data_formats/JSON/sample01.json +3 -0
  6. data/examples/data_formats/JSON/sample01.svg +36 -0
  7. data/examples/data_formats/JSON/sample02.json +6 -0
  8. data/examples/data_formats/JSON/sample02.svg +128 -0
  9. data/examples/data_formats/JSON/sample03.json +88 -0
  10. data/examples/general/calc_iter1/README.md +26 -0
  11. data/examples/general/calc_iter2/README.md +55 -0
  12. data/examples/general/general_examples.md +37 -0
  13. data/examples/tokenizer/README.md +46 -0
  14. data/examples/tokenizer/loxxy_raw_scanner.rex +98 -0
  15. data/examples/tokenizer/loxxy_raw_scanner.rex.rb +256 -0
  16. data/examples/tokenizer/loxxy_tokenizer.rb +94 -0
  17. data/examples/tokenizer/run_tokenizer.rb +29 -0
  18. data/lib/rley/constants.rb +1 -1
  19. data/lib/rley/lexical/literal.rb +29 -0
  20. data/lib/rley/lexical/token.rb +7 -4
  21. data/lib/rley/syntax/base_grammar_builder.rb +0 -2
  22. data/lib/rley.rb +1 -1
  23. data/spec/rley/lexical/literal_spec.rb +33 -0
  24. data/spec/rley/lexical/token_spec.rb +15 -4
  25. data/spec/rley/notation/grammar_builder_spec.rb +2 -2
  26. data/spec/rley/parser/dangling_else_spec.rb +5 -7
  27. data/spec/rley/parser/gfg_chart_spec.rb +0 -1
  28. data/spec/rley/parser/gfg_earley_parser_spec.rb +131 -134
  29. data/spec/rley/parser/gfg_parsing_spec.rb +1 -2
  30. data/spec/rley/syntax/base_grammar_builder_spec.rb +7 -7
  31. data/spec/rley/syntax/grammar_spec.rb +6 -9
  32. metadata +19 -9
  33. data/lib/rley/parser/parse_tracer.rb +0 -103
  34. data/lib/rley/syntax/literal.rb +0 -20
  35. data/lib/rley/syntax/verbatim_symbol.rb +0 -27
  36. data/spec/rley/syntax/literal_spec.rb +0 -31
  37. data/spec/rley/syntax/verbatim_symbol_spec.rb +0 -38
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e3f429e3129dc66ab35ca8bba695b0788d710c6e61033a086d7b3c7c40af7cf
4
- data.tar.gz: eea709ac4554918cc690e27ebb8540418234b6b0706fd98390c6f8f5d603f868
3
+ metadata.gz: a94c23265bf2996856da4d4b1fc6f2749873626951d30bacec9f1ca7619d4d4f
4
+ data.tar.gz: fc6a6ae19388b532dc711915a9c33ffc455a602ea9e6a1ae13e53522bc0616d0
5
5
  SHA512:
6
- metadata.gz: bf936e0f984789b7c509b9bbd5078c787e79caef32120f4409b23225fe7589d1bdddf5e74e1467401acffb329461b0812c3bb46a9da4b651ae10c94fcd4a52e1
7
- data.tar.gz: 606e0e80bfedcd9915eff6b776a826b9032cef201febc07bfcbc1a027622606584bd83e9874a5f448637dd46f66592490c92138c874a07ae630d678e17b5982f
6
+ metadata.gz: 9b25f6a34e4e5603d4b88f5cf3220e998d9e0c38ffef204ebbf4a8eacaf57853c2bb9bc2bb5a3765440aaed41ee5a4883edadc533c6df0dc907b58457b085469
7
+ data.tar.gz: 57c3021f24eb5764fef2be6bdd58a9cda1c9b9343737c357d6c1e1862beceaf041ed9eee9fb625cf9acc9492bac0fcb6a6ac8cd9dc464dcf2096fccd5b51e6e9
data/.rubocop.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  AllCops:
2
2
  Exclude:
3
- - 'examples/**/*'
4
- - 'exp/**/*'
3
+ - 'exp/**/*'
5
4
 
6
5
  Gemspec/DateAssignment:
7
6
  Enabled: true
@@ -81,6 +80,9 @@ Layout/TrailingEmptyLines:
81
80
  Layout/TrailingWhitespace:
82
81
  Enabled: true
83
82
 
83
+ Lint/AmbiguousOperatorPrecedence:
84
+ Enabled: true
85
+
84
86
  Lint/AmbiguousAssignment:
85
87
  Enabled: true
86
88
 
@@ -105,6 +107,9 @@ Lint/EmptyClass:
105
107
  Lint/EmptyInPattern:
106
108
  Enabled: true
107
109
 
110
+ Lint/IncompatibleIoSelectWithFiberScheduler:
111
+ Enabled: true
112
+
108
113
  Lint/LambdaWithoutLiteralBlock:
109
114
  Enabled: true
110
115
 
@@ -126,6 +131,9 @@ Lint/RaiseException:
126
131
  Lint/RedundantDirGlobSort:
127
132
  Enabled: true
128
133
 
134
+ Lint/RequireRelativeSelfPath:
135
+ Enabled: true
136
+
129
137
  Lint/RescueException:
130
138
  Enabled: true
131
139
 
@@ -213,6 +221,9 @@ Naming/MethodName:
213
221
  Naming/VariableName:
214
222
  Enabled: false
215
223
 
224
+ Security/IoMethods:
225
+ Enabled: true
226
+
216
227
  Style/Alias:
217
228
  Enabled: true
218
229
 
@@ -293,9 +304,9 @@ Style/InverseMethods:
293
304
 
294
305
  Style/MissingRespondToMissing:
295
306
  Enabled: false
296
-
307
+
297
308
  Style/MultilineInPatternThen:
298
- Enabled: true
309
+ Enabled: true
299
310
 
300
311
  Style/NegatedIfElseCondition:
301
312
  Enabled: true
@@ -306,11 +317,17 @@ Style/Next:
306
317
  Style/NilLambda:
307
318
  Enabled: true
308
319
 
320
+ Style/NumberedParameters:
321
+ Enabled: true
322
+
323
+ Style/NumberedParametersLimit:
324
+ Enabled: true
325
+
309
326
  Style/NumericLiterals:
310
327
  Enabled: false
311
-
328
+
312
329
  Style/QuotedSymbols:
313
- Enabled: true
330
+ Enabled: true
314
331
 
315
332
  Style/RaiseArgs:
316
333
  Enabled: true
@@ -323,15 +340,18 @@ Style/RedundantReturn:
323
340
 
324
341
  Style/RedundantSelf:
325
342
  Enabled: true
326
-
343
+
327
344
  Style/RedundantSelfAssignmentBranch:
328
- Enabled: true
345
+ Enabled: true
329
346
 
330
347
  Style/RegexpLiteral:
331
348
  Enabled: false
332
349
 
333
350
  Style/PercentLiteralDelimiters:
334
351
  Enabled: false
352
+
353
+ Style/SelectByRegexp:
354
+ Enabled: true
335
355
 
336
356
  Style/StderrPuts:
337
357
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 0.8.05 / 2021-10-04
2
+ - Added example of generated scanner. Unused class removal, code re-styling to please `Rubocop`
3
+
4
+ * [NEW] Folder `example\tokenizer` contains an example with a scanner that was generated.
5
+ * [NEW] Class `Rley::Lexical::Literal` a specialization of Token class for literal tokens.
6
+ * [CHANGE] File `.rubocp.yml` updated to take into account new 1.21 and 1.22 cops.
7
+ * [DELETED] Class `Rley::Parser::ParserTracer` this class was no more in use.
8
+ * [DELETED] Class `Rley::Syntax::Literal` this class was unused.
9
+ * [DELETED] Class `Rley::Syntax::VerbatimSymbol` this class was unused.
10
+
1
11
  ### 0.8.03 / 2021-08-27
2
12
  - Added missing method in `ASTBaseBuilder` class
3
13
 
@@ -0,0 +1,34 @@
1
+ ## Demo JSON parser
2
+
3
+ ### Source files
4
+ This sample project consists of the following files:
5
+ - **cli_opt.rb** containing the utility class `CLIOptions` that retrieves the
6
+ command-line options.
7
+
8
+ - **json_ast_builder.rb** containing the class `JSONASTBuilder` that creates
9
+ the abstract syntax trees (AST) representation for a given parse result.
10
+
11
+ - **json_ast_nodes.rb** containing the node classs for implementing the AST.
12
+ The nodes are augmented with methods that allow the re-use of some formatters
13
+ designed initially for CST (Concrete Syntax Tree). The nodes have a 'to_ruby'
14
+ method that enable a conversion of the input JSON text into Ruby representation.
15
+
16
+ - **JSON_demo.rb** a demo command-line program.
17
+ It parses the JSON file specified in the command-line and outputs the parse tree
18
+ into different formats. For more details, run the command-line: `JSON_demo.rb --help`
19
+
20
+ - **JSON_grammar.rb** implementing the class `JSONGrammar`.
21
+ The grammar is a list of (production) rules that specifies the syntax of JSON data.
22
+ A little examination of the grammar will reveal interesting grammar features such as:
23
+ * Recursive rules (e.g. terminal in left-side of rule also appears in right-hand side)
24
+
25
+ - **JSON_lexer.rb** implementing the class `JSONLexer`.
26
+ The purpose of the lexer is to break the JSON source text into a sequence of tokens.
27
+
28
+ - **JSON_parser.rb** implementing a `JSONParser` class.
29
+ The parser processes the tokens stream from the lexer and delivers its results
30
+
31
+
32
+ - sample0x.json files of various degree of complexity.
33
+
34
+ - sample0x.svg files that are syntax tree diagrams obtained by feeding [RSyntaxTree](http://yohasebe.com/rsyntaxtree/) with the output of JSON_demo.rb. Remark: the website works best with not too complex parse trees.
@@ -0,0 +1,3 @@
1
+ {
2
+ "name" : "John Doe"
3
+ }
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg width="469.5" height="502" version="1.1" xmlns="http://www.w3.org/2000/svg">
5
+ <text style='fill: green; font-size: 16px;' x='296.53125' y='490'> John Doe</text>
6
+ <text style='fill: green; font-size: 16px;' x='109.53125' y='424'> name</text>
7
+ <text style='fill: green; font-size: 16px;' x='221.2421875' y='424'> :</text>
8
+ <text style='fill: blue; font-size: 16px;' x='309.3828125' y='424'>string</text>
9
+ <polygon style='fill: white; stroke: black; stroke-width:1;' points='361 467 297 467 329 431' />
10
+ <text style='fill: blue; font-size: 16px;' x='109.796875' y='358'>string</text>
11
+ <line style='stroke:black; stroke-width:1;' x1='130' y1='401' x2='130' y2='365' />
12
+ <text style='fill: blue; font-size: 16px;' x='164.796875' y='358'>name-separator</text>
13
+ <line style='stroke:black; stroke-width:1;' x1='223' y1='401' x2='223' y2='365' />
14
+ <text style='fill: blue; font-size: 16px;' x='309.75' y='358'>value</text>
15
+ <line style='stroke:black; stroke-width:1;' x1='329' y1='401' x2='329' y2='365' />
16
+ <text style='fill: green; font-size: 16px;' x='46.5078125' y='292'> {</text>
17
+ <text style='fill: blue; font-size: 16px;' x='198.40234375' y='292'>member</text>
18
+ <line style='stroke:black; stroke-width:1;' x1='130' y1='335' x2='229' y2='299' />
19
+ <line style='stroke:black; stroke-width:1;' x1='223' y1='335' x2='229' y2='299' />
20
+ <line style='stroke:black; stroke-width:1;' x1='329' y1='335' x2='229' y2='299' />
21
+ <text style='fill: green; font-size: 16px;' x='412.4375' y='292'> }</text>
22
+ <text style='fill: blue; font-size: 16px;' x='5.0' y='226'>begin-object</text>
23
+ <line style='stroke:black; stroke-width:1;' x1='50' y1='269' x2='50' y2='233' />
24
+ <text style='fill: blue; font-size: 16px;' x='185.58984375' y='226'>member-list</text>
25
+ <line style='stroke:black; stroke-width:1;' x1='229' y1='269' x2='229' y2='233' />
26
+ <text style='fill: blue; font-size: 16px;' x='376.96875' y='226'>end-object</text>
27
+ <line style='stroke:black; stroke-width:1;' x1='416' y1='269' x2='416' y2='233' />
28
+ <text style='fill: blue; font-size: 16px;' x='209.984375' y='160'>object</text>
29
+ <line style='stroke:black; stroke-width:1;' x1='50' y1='203' x2='233' y2='167' />
30
+ <line style='stroke:black; stroke-width:1;' x1='229' y1='203' x2='233' y2='167' />
31
+ <line style='stroke:black; stroke-width:1;' x1='416' y1='203' x2='233' y2='167' />
32
+ <text style='fill: blue; font-size: 16px;' x='213.25' y='94'>value</text>
33
+ <line style='stroke:black; stroke-width:1;' x1='233' y1='137' x2='233' y2='101' />
34
+ <text style='fill: blue; font-size: 16px;' x='197.03125' y='28'>JSON-text</text>
35
+ <line style='stroke:black; stroke-width:1;' x1='233' y1='71' x2='233' y2='35' />
36
+ </svg>
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": 1,
3
+ "name": "A green door",
4
+ "price": 12.50,
5
+ "tags": ["home", "green"]
6
+ }
@@ -0,0 +1,128 @@
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
3
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg width="2060.15625" height="766" version="1.1" xmlns="http://www.w3.org/2000/svg">
5
+ <text style='fill: green; font-size: 16px;' x='1597.078125' y='754'> home</text>
6
+ <text style='fill: green; font-size: 16px;' x='320.75' y='688'> 1</text>
7
+ <text style='fill: blue; font-size: 16px;' x='1597.265625' y='688'>string</text>
8
+ <line style='stroke:black; stroke-width:1;' x1='1617' y1='731' x2='1617' y2='695' />
9
+ <text style='fill: green; font-size: 16px;' x='1825.0' y='688'> green</text>
10
+ <text style='fill: green; font-size: 16px;' x='122.84375' y='622'> id</text>
11
+ <text style='fill: green; font-size: 16px;' x='220.7109375' y='622'> :</text>
12
+ <text style='fill: blue; font-size: 16px;' x='296.0' y='622'>number</text>
13
+ <line style='stroke:black; stroke-width:1;' x1='325' y1='665' x2='325' y2='629' />
14
+ <text style='fill: green; font-size: 16px;' x='685.109375' y='622'> A green door</text>
15
+ <text style='fill: blue; font-size: 16px;' x='1597.6328125' y='622'>value</text>
16
+ <line style='stroke:black; stroke-width:1;' x1='1617' y1='665' x2='1617' y2='629' />
17
+ <text style='fill: green; font-size: 16px;' x='1750.75' y='622'> ,</text>
18
+ <text style='fill: blue; font-size: 16px;' x='1825.984375' y='622'>string</text>
19
+ <line style='stroke:black; stroke-width:1;' x1='1846' y1='665' x2='1846' y2='629' />
20
+ <text style='fill: blue; font-size: 16px;' x='109.53125' y='556'>string</text>
21
+ <line style='stroke:black; stroke-width:1;' x1='129' y1='599' x2='129' y2='563' />
22
+ <text style='fill: blue; font-size: 16px;' x='164.265625' y='556'>name-separator</text>
23
+ <line style='stroke:black; stroke-width:1;' x1='223' y1='599' x2='223' y2='563' />
24
+ <text style='fill: blue; font-size: 16px;' x='305.0546875' y='556'>value</text>
25
+ <line style='stroke:black; stroke-width:1;' x1='325' y1='599' x2='325' y2='563' />
26
+ <text style='fill: green; font-size: 16px;' x='498.109375' y='556'> name</text>
27
+ <text style='fill: green; font-size: 16px;' x='609.8203125' y='556'> :</text>
28
+ <text style='fill: blue; font-size: 16px;' x='712.2421875' y='556'>string</text>
29
+ <polygon style='fill: white; stroke: black; stroke-width:1;' points='779 599 686 599 732 563' />
30
+ <text style='fill: green; font-size: 16px;' x='1119.0078125' y='556'> 12.50</text>
31
+ <text style='fill: green; font-size: 16px;' x='1538.2578125' y='556'> [</text>
32
+ <text style='fill: blue; font-size: 16px;' x='1575.671875' y='556'>array-items</text>
33
+ <line style='stroke:black; stroke-width:1;' x1='1617' y1='599' x2='1617' y2='563' />
34
+ <text style='fill: blue; font-size: 16px;' x='1695.0' y='556'>value-separator</text>
35
+ <line style='stroke:black; stroke-width:1;' x1='1752' y1='599' x2='1752' y2='563' />
36
+ <text style='fill: blue; font-size: 16px;' x='1826.3515625' y='556'>value</text>
37
+ <line style='stroke:black; stroke-width:1;' x1='1846' y1='599' x2='1846' y2='563' />
38
+ <text style='fill: green; font-size: 16px;' x='1914.8671875' y='556'> ]</text>
39
+ <text style='fill: blue; font-size: 16px;' x='195.921875' y='490'>member</text>
40
+ <line style='stroke:black; stroke-width:1;' x1='129' y1='533' x2='227' y2='497' />
41
+ <line style='stroke:black; stroke-width:1;' x1='223' y1='533' x2='227' y2='497' />
42
+ <line style='stroke:black; stroke-width:1;' x1='325' y1='533' x2='227' y2='497' />
43
+ <text style='fill: green; font-size: 16px;' x='423.859375' y='490'> ,</text>
44
+ <text style='fill: blue; font-size: 16px;' x='498.375' y='490'>string</text>
45
+ <line style='stroke:black; stroke-width:1;' x1='518' y1='533' x2='518' y2='497' />
46
+ <text style='fill: blue; font-size: 16px;' x='553.375' y='490'>name-separator</text>
47
+ <line style='stroke:black; stroke-width:1;' x1='612' y1='533' x2='612' y2='497' />
48
+ <text style='fill: blue; font-size: 16px;' x='712.609375' y='490'>value</text>
49
+ <line style='stroke:black; stroke-width:1;' x1='732' y1='533' x2='732' y2='497' />
50
+ <text style='fill: green; font-size: 16px;' x='926.921875' y='490'> price</text>
51
+ <text style='fill: green; font-size: 16px;' x='1035.2890625' y='490'> :</text>
52
+ <text style='fill: blue; font-size: 16px;' x='1110.578125' y='490'>number</text>
53
+ <line style='stroke:black; stroke-width:1;' x1='1139' y1='533' x2='1139' y2='497' />
54
+ <text style='fill: blue; font-size: 16px;' x='1499.15625' y='490'>begin-array</text>
55
+ <line style='stroke:black; stroke-width:1;' x1='1541' y1='533' x2='1541' y2='497' />
56
+ <text style='fill: blue; font-size: 16px;' x='1690.03125' y='490'>array-items</text>
57
+ <line style='stroke:black; stroke-width:1;' x1='1617' y1='533' x2='1731' y2='497' />
58
+ <line style='stroke:black; stroke-width:1;' x1='1752' y1='533' x2='1731' y2='497' />
59
+ <line style='stroke:black; stroke-width:1;' x1='1846' y1='533' x2='1731' y2='497' />
60
+ <text style='fill: blue; font-size: 16px;' x='1881.703125' y='490'>end-array</text>
61
+ <line style='stroke:black; stroke-width:1;' x1='1917' y1='533' x2='1917' y2='497' />
62
+ <text style='fill: blue; font-size: 16px;' x='183.109375' y='424'>member-list</text>
63
+ <line style='stroke:black; stroke-width:1;' x1='227' y1='467' x2='227' y2='431' />
64
+ <text style='fill: blue; font-size: 16px;' x='368.109375' y='424'>value-separator</text>
65
+ <line style='stroke:black; stroke-width:1;' x1='426' y1='467' x2='426' y2='431' />
66
+ <text style='fill: blue; font-size: 16px;' x='594.12109375' y='424'>member</text>
67
+ <line style='stroke:black; stroke-width:1;' x1='518' y1='467' x2='625' y2='431' />
68
+ <line style='stroke:black; stroke-width:1;' x1='612' y1='467' x2='625' y2='431' />
69
+ <line style='stroke:black; stroke-width:1;' x1='732' y1='467' x2='625' y2='431' />
70
+ <text style='fill: green; font-size: 16px;' x='849.859375' y='424'> ,</text>
71
+ <text style='fill: blue; font-size: 16px;' x='924.109375' y='424'>string</text>
72
+ <line style='stroke:black; stroke-width:1;' x1='944' y1='467' x2='944' y2='431' />
73
+ <text style='fill: blue; font-size: 16px;' x='978.84375' y='424'>name-separator</text>
74
+ <line style='stroke:black; stroke-width:1;' x1='1037' y1='467' x2='1037' y2='431' />
75
+ <text style='fill: blue; font-size: 16px;' x='1119.6328125' y='424'>value</text>
76
+ <line style='stroke:black; stroke-width:1;' x1='1139' y1='467' x2='1139' y2='431' />
77
+ <text style='fill: green; font-size: 16px;' x='1317.6875' y='424'> tags</text>
78
+ <text style='fill: green; font-size: 16px;' x='1423.8671875' y='424'> :</text>
79
+ <text style='fill: blue; font-size: 16px;' x='1709.4296875' y='424'>array</text>
80
+ <line style='stroke:black; stroke-width:1;' x1='1541' y1='467' x2='1729' y2='431' />
81
+ <line style='stroke:black; stroke-width:1;' x1='1731' y1='467' x2='1729' y2='431' />
82
+ <line style='stroke:black; stroke-width:1;' x1='1917' y1='467' x2='1729' y2='431' />
83
+ <text style='fill: blue; font-size: 16px;' x='382.208984375' y='358'>member-list</text>
84
+ <line style='stroke:black; stroke-width:1;' x1='227' y1='401' x2='426' y2='365' />
85
+ <line style='stroke:black; stroke-width:1;' x1='426' y1='401' x2='426' y2='365' />
86
+ <line style='stroke:black; stroke-width:1;' x1='625' y1='401' x2='426' y2='365' />
87
+ <text style='fill: blue; font-size: 16px;' x='794.109375' y='358'>value-separator</text>
88
+ <line style='stroke:black; stroke-width:1;' x1='852' y1='401' x2='852' y2='365' />
89
+ <text style='fill: blue; font-size: 16px;' x='1010.5' y='358'>member</text>
90
+ <line style='stroke:black; stroke-width:1;' x1='944' y1='401' x2='1042' y2='365' />
91
+ <line style='stroke:black; stroke-width:1;' x1='1037' y1='401' x2='1042' y2='365' />
92
+ <line style='stroke:black; stroke-width:1;' x1='1139' y1='401' x2='1042' y2='365' />
93
+ <text style='fill: green; font-size: 16px;' x='1238.4375' y='358'> ,</text>
94
+ <text style='fill: blue; font-size: 16px;' x='1312.6875' y='358'>string</text>
95
+ <line style='stroke:black; stroke-width:1;' x1='1333' y1='401' x2='1333' y2='365' />
96
+ <text style='fill: blue; font-size: 16px;' x='1367.421875' y='358'>name-separator</text>
97
+ <line style='stroke:black; stroke-width:1;' x1='1426' y1='401' x2='1426' y2='365' />
98
+ <text style='fill: blue; font-size: 16px;' x='1709.390625' y='358'>value</text>
99
+ <line style='stroke:black; stroke-width:1;' x1='1729' y1='401' x2='1729' y2='365' />
100
+ <text style='fill: green; font-size: 16px;' x='46.5078125' y='292'> {</text>
101
+ <text style='fill: blue; font-size: 16px;' x='689.9482421875' y='292'>member-list</text>
102
+ <line style='stroke:black; stroke-width:1;' x1='426' y1='335' x2='734' y2='299' />
103
+ <line style='stroke:black; stroke-width:1;' x1='852' y1='335' x2='734' y2='299' />
104
+ <line style='stroke:black; stroke-width:1;' x1='1042' y1='335' x2='734' y2='299' />
105
+ <text style='fill: blue; font-size: 16px;' x='1182.6875' y='292'>value-separator</text>
106
+ <line style='stroke:black; stroke-width:1;' x1='1240' y1='335' x2='1240' y2='299' />
107
+ <text style='fill: blue; font-size: 16px;' x='1499.66796875' y='292'>member</text>
108
+ <line style='stroke:black; stroke-width:1;' x1='1333' y1='335' x2='1531' y2='299' />
109
+ <line style='stroke:black; stroke-width:1;' x1='1426' y1='335' x2='1531' y2='299' />
110
+ <line style='stroke:black; stroke-width:1;' x1='1729' y1='335' x2='1531' y2='299' />
111
+ <text style='fill: green; font-size: 16px;' x='2003.09375' y='292'> }</text>
112
+ <text style='fill: blue; font-size: 16px;' x='5.0' y='226'>begin-object</text>
113
+ <line style='stroke:black; stroke-width:1;' x1='50' y1='269' x2='50' y2='233' />
114
+ <text style='fill: blue; font-size: 16px;' x='1088.40185546875' y='226'>member-list</text>
115
+ <line style='stroke:black; stroke-width:1;' x1='734' y1='269' x2='1132' y2='233' />
116
+ <line style='stroke:black; stroke-width:1;' x1='1240' y1='269' x2='1132' y2='233' />
117
+ <line style='stroke:black; stroke-width:1;' x1='1531' y1='269' x2='1132' y2='233' />
118
+ <text style='fill: blue; font-size: 16px;' x='1967.625' y='226'>end-object</text>
119
+ <line style='stroke:black; stroke-width:1;' x1='2006' y1='269' x2='2006' y2='233' />
120
+ <text style='fill: blue; font-size: 16px;' x='1005.3125' y='160'>object</text>
121
+ <line style='stroke:black; stroke-width:1;' x1='50' y1='203' x2='1028' y2='167' />
122
+ <line style='stroke:black; stroke-width:1;' x1='1132' y1='203' x2='1028' y2='167' />
123
+ <line style='stroke:black; stroke-width:1;' x1='2006' y1='203' x2='1028' y2='167' />
124
+ <text style='fill: blue; font-size: 16px;' x='1008.578125' y='94'>value</text>
125
+ <line style='stroke:black; stroke-width:1;' x1='1028' y1='137' x2='1028' y2='101' />
126
+ <text style='fill: blue; font-size: 16px;' x='992.359375' y='28'>JSON-text</text>
127
+ <line style='stroke:black; stroke-width:1;' x1='1028' y1='71' x2='1028' y2='35' />
128
+ </svg>
@@ -0,0 +1,88 @@
1
+ {"web-app": {
2
+ "servlet": [
3
+ {
4
+ "servlet-name": "cofaxCDS",
5
+ "servlet-class": "org.cofax.cds.CDSServlet",
6
+ "init-param": {
7
+ "configGlossary:installationAt": "Philadelphia, PA",
8
+ "configGlossary:adminEmail": "ksm@pobox.com",
9
+ "configGlossary:poweredBy": "Cofax",
10
+ "configGlossary:poweredByIcon": "/images/cofax.gif",
11
+ "configGlossary:staticPath": "/content/static",
12
+ "templateProcessorClass": "org.cofax.WysiwygTemplate",
13
+ "templateLoaderClass": "org.cofax.FilesTemplateLoader",
14
+ "templatePath": "templates",
15
+ "templateOverridePath": "",
16
+ "defaultListTemplate": "listTemplate.htm",
17
+ "defaultFileTemplate": "articleTemplate.htm",
18
+ "useJSP": false,
19
+ "jspListTemplate": "listTemplate.jsp",
20
+ "jspFileTemplate": "articleTemplate.jsp",
21
+ "cachePackageTagsTrack": 200,
22
+ "cachePackageTagsStore": 200,
23
+ "cachePackageTagsRefresh": 60,
24
+ "cacheTemplatesTrack": 100,
25
+ "cacheTemplatesStore": 50,
26
+ "cacheTemplatesRefresh": 15,
27
+ "cachePagesTrack": 200,
28
+ "cachePagesStore": 100,
29
+ "cachePagesRefresh": 10,
30
+ "cachePagesDirtyRead": 10,
31
+ "searchEngineListTemplate": "forSearchEnginesList.htm",
32
+ "searchEngineFileTemplate": "forSearchEngines.htm",
33
+ "searchEngineRobotsDb": "WEB-INF/robots.db",
34
+ "useDataStore": true,
35
+ "dataStoreClass": "org.cofax.SqlDataStore",
36
+ "redirectionClass": "org.cofax.SqlRedirection",
37
+ "dataStoreName": "cofax",
38
+ "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver",
39
+ "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon",
40
+ "dataStoreUser": "sa",
41
+ "dataStorePassword": "dataStoreTestQuery",
42
+ "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';",
43
+ "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log",
44
+ "dataStoreInitConns": 10,
45
+ "dataStoreMaxConns": 100,
46
+ "dataStoreConnUsageLimit": 100,
47
+ "dataStoreLogLevel": "debug",
48
+ "maxUrlLength": 500}},
49
+ {
50
+ "servlet-name": "cofaxEmail",
51
+ "servlet-class": "org.cofax.cds.EmailServlet",
52
+ "init-param": {
53
+ "mailHost": "mail1",
54
+ "mailHostOverride": "mail2"}},
55
+ {
56
+ "servlet-name": "cofaxAdmin",
57
+ "servlet-class": "org.cofax.cds.AdminServlet"},
58
+
59
+ {
60
+ "servlet-name": "fileServlet",
61
+ "servlet-class": "org.cofax.cds.FileServlet"},
62
+ {
63
+ "servlet-name": "cofaxTools",
64
+ "servlet-class": "org.cofax.cms.CofaxToolsServlet",
65
+ "init-param": {
66
+ "templatePath": "toolstemplates/",
67
+ "log": 1,
68
+ "logLocation": "/usr/local/tomcat/logs/CofaxTools.log",
69
+ "logMaxSize": "",
70
+ "dataLog": 1,
71
+ "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log",
72
+ "dataLogMaxSize": "",
73
+ "removePageCache": "/content/admin/remove?cache=pages&id=",
74
+ "removeTemplateCache": "/content/admin/remove?cache=templates&id=",
75
+ "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder",
76
+ "lookInContext": 1,
77
+ "adminGroupID": 4,
78
+ "betaServer": true}}],
79
+ "servlet-mapping": {
80
+ "cofaxCDS": "/",
81
+ "cofaxEmail": "/cofaxutil/aemail/*",
82
+ "cofaxAdmin": "/admin/*",
83
+ "fileServlet": "/static/*",
84
+ "cofaxTools": "/tools/*"},
85
+
86
+ "taglib": {
87
+ "taglib-uri": "cofax.tld",
88
+ "taglib-location": "/WEB-INF/tlds/cofax.tld"}}}
@@ -0,0 +1,26 @@
1
+ ## Demo calculator (iteration 1)
2
+
3
+ ### Source files
4
+ This sample project consists of the following files:
5
+ - **calc_ast_builder.rb** containing the class `CalcASTBuilder` that creates
6
+ the abstract syntax trees (AST) representation for a given parse result.
7
+
8
+ - **calc_ast_nodes.rb** containing the node classes for implementing the AST.
9
+ The nodes have a 'interpret' method that computes of the numeric value of the
10
+ node.
11
+
12
+ - **calc_demo.rb** a demo command-line program.
13
+ It parses the expression in the command-line and outputs the numeric result
14
+ For more details, run the command-line: `calc_demo.rb`
15
+
16
+ - **calc_grammar.rb** implementing the class `CalcGrammar`.
17
+ The grammar is a list of (production) rules that specifies the syntax of math
18
+ expression. A little examination of the grammar will reveal interesting
19
+ grammar features such as:
20
+ * Recursive rules (e.g. terminal in left-side of rule also appears in right-hand side)
21
+
22
+ - **calc_lexer.rb** implementing the class `CalcLexer`.
23
+ The purpose of the lexer is to break the math expression into a sequence of tokens.
24
+
25
+ - **calc_parser.rb** implementing a `CalcParser` class.
26
+ The parser processes the tokens stream from the lexer and delivers its results
@@ -0,0 +1,55 @@
1
+ ## Demo calculator (iteration 2)
2
+ Compared to the first iteration, this calculator supports:
3
+ - the exponentiation operator '**',
4
+ - the unary '-' operator (sign change),
5
+ - the PI and E constants,
6
+ - and several functions from Ruby's Math module.
7
+
8
+
9
+ It also prints out:
10
+ - The Concrete Syntax Tree (CST), a complete but verbose parse tree representation
11
+ - The Abstract Syntax Tree (AST), a customized parse tree representation that is more
12
+ convenient for further processing (here calculation.).
13
+
14
+ BUILT-IN OPERATORS AND FUNCTIONS
15
+ ---------------------------------
16
+ Operators: `+`, `-`, `*`, `/`, `**`
17
+ Numeric constants: `PI` (= 3.14159...), `E` (= 2.71828...)
18
+ Functions from Ruby's Math module:
19
+ `sqrt` (square root), `cbrt` (cubic root),
20
+ `exp` (exponential), `ln` (natural or neperian logarithm), `log10` (logarithm in base 10)
21
+ Trigonometric functions: `sin`, `cos`, `tan`
22
+ Inverse trigonometric functions: `asin`, `acos`, `atan`
23
+
24
+
25
+ ### Source files
26
+ This sample project consists of the following files:
27
+ - **calc_ast_builder.rb** containing the class `CalcASTBuilder` that creates
28
+ the abstract syntax trees (AST) representation for a given parse result.
29
+
30
+ - **calc_ast_nodes.rb** containing the node classes for implementing the AST.
31
+ The nodes have a 'interpret' method that computes of the numeric value of the
32
+ node.
33
+
34
+ - **calc_demo.rb** a demo command-line program.
35
+ It parses the expression in the command-line and outputs the numeric result
36
+ For more details, run the command-line: `calc_demo.rb`
37
+
38
+ - **calc_grammar.rb** implementing the class `CalcGrammar`.
39
+ The grammar is a list of (production) rules that specifies the syntax of math
40
+ expression. A little examination of the grammar will reveal interesting
41
+ grammar features such as:
42
+ * Recursive rules (e.g. terminal in left-side of rule also appears in right-hand side)
43
+
44
+ - **calc_lexer.rb** implementing the class `CalcLexer`.
45
+ The purpose of the lexer is to break the math expression into a sequence of tokens.
46
+
47
+ - **calc_parser.rb** implementing a `CalcParser` class.
48
+ The parser processes the tokens stream from the lexer and delivers its results
49
+
50
+ - **sample_result.txt** a sample text containing the output of calculator for the expression:
51
+ 2 * 3 + (1 + 3 ** 2). It illustrates the huge difference in size and nesting between the CST
52
+ (Concrete Syntax Tree) and the AST (Abstract Syntax Tree) representations. The generation of CSTs
53
+ comes out-of-the-box with **Rley**. Creating ASTs requires customization. Here, the class for the
54
+ AST nodes of the AST are defined in the **calc_ast_nodes.rb** and the methods for assembling the
55
+ AST from the grammar rules are implemented in the `CalcASTBuilder` class.
@@ -0,0 +1,37 @@
1
+ ## Directory contents
2
+ This directory contains a number sample projects and short demos.
3
+
4
+ - [calc_iter1](#demo-calculators)
5
+ - [calc_iter2](#demo-calculators)
6
+ - [SPPF](#Shared-Packed-Parse-Forest)
7
+ - [SRL](#Simple-Regex-Language)
8
+ - [left.rb](#recursive-rules)
9
+ - [right.rb](#recursive-rules)
10
+
11
+
12
+ ### Demo calculators
13
+ Two command-line tools that parse basic math expressions
14
+ and calculate their numeric values.
15
+
16
+ There are two variants of the calculator:
17
+ - **Iteration 1**. A simple calculator program that handles expressions with the
18
+ 4 basic arithmetic operators: + - * and /
19
+ - **Iteration 2**. A significantly more elaborated calculator that adds:
20
+ support for the exponentiation operator and the unary minus (sign change),
21
+ PI and E constants,
22
+ trigonometric functions, inverse trigonometric functions,
23
+ square root, exponential and natural logarithm functions.
24
+
25
+ As a bonus, the iteration 2 calculator prints out:
26
+ - The Concrete Syntax Tree (**CST**), a complete but verbose parse tree representation
27
+ - The Abstract Syntax Tree (**AST**), a customized parse tree representation that is simpler
28
+ for further processing (i.e. calculation, execution,...).
29
+
30
+ Although these calculators are demo apps (read: they lack robust error handling and user friendly
31
+ error reporting), great care was taken about their modularity.
32
+
33
+ ### Shared Packed Parse Forest
34
+ This directory will contain code showing how to use and manipulate SPPFs.
35
+
36
+ ### Recursive rules
37
+ The files `left.rb` and `right.rb` show how to define left- and right-recursive rules respectively. These examples were used to benchmark the parsing. Although `Rley` can handle right-recursive rules, one should avoid deeply-nested right-recursive rule calls. The reason is that in these situations the number of possible parse states increases rapidly and affects severely the parsing speed. There are optimization techniques addressing the issue e.g. [Leo's optimization](http://www.sciencedirect.com/science/article/pii/030439759190180A) that may eventually be implemented in Rley provided that they don't put limits on the NLP capabilities. Here is another link about [Leo's optimization](http://loup-vaillant.fr/tutorials/earley-parsing/right-recursion)
@@ -0,0 +1,46 @@
1
+ Integrating a scanner generated with `oedipus_lex` gem with a Rley parser.
2
+ ===
3
+
4
+ This folder contains a demo tokenizer for the `Lox` programming language.
5
+ While tokenizers from other examples were handwritten, this one was generated with a tool.
6
+
7
+ The resulting tokenizer consists of two classes:
8
+ - The generated `LoxxyRawScanner` class (file: `loxxy_raw_scanner.rex.rb`).
9
+ - The handwritten `LoxxyTokenizer` class. Its purpose is explained later (file: `loxxy_tokenizer.rb`).
10
+
11
+ ## How was the scanner class generated?
12
+
13
+ The `LoxxyRawScanner` class was generated from the specification file `loxxy_raw_scanner.rex`.
14
+ This file has a format that can be read by the `oedipus lex`gem (the 'scanner generator').
15
+ The scanner generator then generates a Ruby class that implements a scanner.
16
+
17
+ The generation process is controled with a `Rakefile`.
18
+ Assuming that the gem is already installed, launch the following command line in this folder:
19
+ ```ruby
20
+ rake tokenizer
21
+ ```
22
+
23
+ Rake script should display the following message:
24
+ ```ruby
25
+ Generating loxxy_raw_scanner.rex.rb from loxxy_raw_scanner.rex
26
+ ```
27
+
28
+ ## How to install `oedipus_lex`?
29
+ Use the standard installation step:
30
+ ```ruby
31
+ gem install oedipus_lex
32
+ ```
33
+
34
+ ## Why the `oedipus_lex` scanner generator?
35
+ This gem was created as a companion to the `Racc` parser (part of Ruby's standard library).
36
+ But the code it produces has no dependency towards a specific parser,
37
+ so that it can used for building scanners for Rley parsers.
38
+
39
+ ## What is the purpose of the`LoxxyTokenizer` class?
40
+ If the scanner can be generated, why do we need to handcode another class?
41
+ There were two reasons:
42
+ - First, `rex` files use particular syntax a domain-specific language (DSL). So I tend to minimize its use.
43
+ Without the flexbility of Ruby, handling keywords directly in the `rex` can become cumbersone.
44
+ - Second, the `LoxxyTokenizer` class acts as an Adapter between the parser-neutral generated scanner and the expectations of a Rley parser.
45
+ For instance, Rley expects the tokenizer to deliver a sequence of `Rley::Lexical::Token` instances.
46
+ In addition, that class performs some convertion methods that are better implemented directly in Ruby.