antelope 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +25 -23
  3. data/.rspec +3 -3
  4. data/.travis.yml +10 -9
  5. data/.yardopts +7 -7
  6. data/CONTRIBUTING.md +38 -38
  7. data/GENERATORS.md +124 -124
  8. data/Gemfile +7 -7
  9. data/LICENSE.txt +22 -22
  10. data/README.md +104 -104
  11. data/Rakefile +2 -2
  12. data/TODO.md +58 -58
  13. data/antelope.gemspec +28 -28
  14. data/bin/antelope +7 -7
  15. data/examples/deterministic.ace +35 -35
  16. data/examples/example.ace +51 -50
  17. data/examples/example.err +192 -0
  18. data/examples/{example.output → example.inf} +384 -385
  19. data/examples/liquidscript.ace +233 -162
  20. data/examples/simple.ace +22 -22
  21. data/lib/antelope/ace/compiler.rb +334 -334
  22. data/lib/antelope/ace/errors.rb +48 -48
  23. data/lib/antelope/ace/grammar/generation.rb +80 -80
  24. data/lib/antelope/ace/grammar/loading.rb +53 -53
  25. data/lib/antelope/ace/grammar/precedences.rb +68 -65
  26. data/lib/antelope/ace/grammar/productions.rb +156 -150
  27. data/lib/antelope/ace/grammar/symbols.rb +66 -66
  28. data/lib/antelope/ace/grammar.rb +69 -69
  29. data/lib/antelope/ace/precedence.rb +61 -61
  30. data/lib/antelope/ace/production.rb +57 -57
  31. data/lib/antelope/ace/scanner/argument.rb +57 -57
  32. data/lib/antelope/ace/scanner/first.rb +89 -89
  33. data/lib/antelope/ace/scanner/second.rb +177 -177
  34. data/lib/antelope/ace/scanner/third.rb +27 -27
  35. data/lib/antelope/ace/scanner.rb +134 -134
  36. data/lib/antelope/ace/token/epsilon.rb +24 -24
  37. data/lib/antelope/ace/token/error.rb +26 -26
  38. data/lib/antelope/ace/token/nonterminal.rb +17 -17
  39. data/lib/antelope/ace/token/terminal.rb +17 -17
  40. data/lib/antelope/ace/token.rb +238 -238
  41. data/lib/antelope/ace.rb +53 -53
  42. data/lib/antelope/cli.rb +55 -55
  43. data/lib/antelope/errors.rb +8 -8
  44. data/lib/antelope/generation/constructor/first.rb +88 -88
  45. data/lib/antelope/generation/constructor/follow.rb +103 -103
  46. data/lib/antelope/generation/constructor/nullable.rb +64 -64
  47. data/lib/antelope/generation/constructor.rb +126 -126
  48. data/lib/antelope/generation/errors.rb +17 -17
  49. data/lib/antelope/generation/null.rb +13 -13
  50. data/lib/antelope/generation/recognizer/rule.rb +216 -216
  51. data/lib/antelope/generation/recognizer/state.rb +130 -130
  52. data/lib/antelope/generation/recognizer.rb +180 -180
  53. data/lib/antelope/generation/tableizer.rb +175 -154
  54. data/lib/antelope/generation.rb +15 -15
  55. data/lib/antelope/generator/base.rb +264 -264
  56. data/lib/antelope/generator/c.rb +11 -11
  57. data/lib/antelope/generator/c_header.rb +105 -105
  58. data/lib/antelope/generator/c_source.rb +39 -39
  59. data/lib/antelope/generator/error.rb +34 -0
  60. data/lib/antelope/generator/group.rb +57 -57
  61. data/lib/antelope/generator/html.rb +51 -0
  62. data/lib/antelope/generator/info.rb +47 -0
  63. data/lib/antelope/generator/null.rb +18 -18
  64. data/lib/antelope/generator/output.rb +17 -49
  65. data/lib/antelope/generator/ruby.rb +79 -79
  66. data/lib/antelope/generator/templates/c_header.ant +36 -36
  67. data/lib/antelope/generator/templates/c_source.ant +202 -202
  68. data/lib/antelope/generator/templates/error.ant +33 -0
  69. data/lib/antelope/generator/templates/html/antelope.css +1 -0
  70. data/lib/antelope/generator/templates/html/antelope.html +1 -0
  71. data/lib/antelope/generator/templates/html/antelope.js +1 -0
  72. data/lib/antelope/generator/templates/html/css.ant +53 -0
  73. data/lib/antelope/generator/templates/html/html.ant +82 -0
  74. data/lib/antelope/generator/templates/html/js.ant +9 -0
  75. data/lib/antelope/generator/templates/info.ant +53 -0
  76. data/lib/antelope/generator/templates/ruby.ant +178 -146
  77. data/lib/antelope/generator.rb +66 -63
  78. data/lib/antelope/template/compiler.rb +78 -78
  79. data/lib/antelope/template/errors.rb +9 -9
  80. data/lib/antelope/template/scanner.rb +109 -109
  81. data/lib/antelope/template.rb +65 -60
  82. data/lib/antelope/version.rb +6 -6
  83. data/lib/antelope.rb +13 -13
  84. data/optimizations.txt +42 -0
  85. data/spec/antelope/ace/compiler_spec.rb +60 -60
  86. data/spec/antelope/ace/scanner_spec.rb +27 -27
  87. data/spec/antelope/constructor_spec.rb +133 -136
  88. data/spec/antelope/template_spec.rb +50 -49
  89. data/spec/fixtures/simple.ace +22 -22
  90. data/spec/spec_helper.rb +39 -39
  91. data/spec/support/benchmark_helper.rb +5 -5
  92. data/spec/support/grammar_helper.rb +15 -15
  93. data/subl/Ace (Ruby).JSON-tmLanguage +94 -94
  94. data/subl/Ace (Ruby).tmLanguage +153 -153
  95. metadata +17 -6
  96. data/lib/antelope/generator/templates/output.ant +0 -68
@@ -1,162 +1,233 @@
1
- %require "~> 0.1"
2
- %generator "ruby"
3
-
4
- %define api.push-pull pull
5
- %define panic-mode true
6
- %define ruby.error-class {SyntaxError}
7
-
8
- %terminal REGEX
9
- %terminal DIRECTIVE
10
- %terminal IDENTIFIER
11
- %terminal KEYWORD
12
- %terminal NUMBER
13
- %terminal SSTRING
14
- %terminal ACTION
15
- %terminal BINOP
16
- %terminal PREUNOP
17
- %terminal UNOP
18
- %terminal HEREDOC
19
- %terminal HEREDOC_REF
20
- %terminal IHEREDOC
21
- %terminal IHEREDOC_REF
22
- %terminal IHEREDOC_BEGIN
23
- %terminal ISTRING
24
- %terminal ISTRING_BEGIN
25
- %terminal CLASS "class"
26
- %terminal MODULE "module"
27
- %terminal IF "if"
28
- %terminal UNLESS "unless"
29
- %terminal ELSIF "elsif"
30
- %terminal ELSE "else"
31
- %terminal FOR "for"
32
- %terminal WHILE "while"
33
- %terminal TRY "try"
34
- %terminal CATCH "catch"
35
- %terminal FINALLY "finally"
36
- %terminal RETURN "return"
37
- %terminal IN "in"
38
- %terminal ARROW "->"
39
- %terminal EQUAL "="
40
- %terminal LBRACE "{"
41
- %terminal LPAREN "("
42
- %terminal LBRACK "["
43
- %terminal RBRACE "}"
44
- %terminal RPAREN ")"
45
- %terminal RBRACK "]"
46
- %terminal COLON ":"
47
- %terminal RANGE ".."
48
- %terminal ERANGE "..."
49
- %terminal PROP "."
50
- %terminal COMMA ","
51
- %terminal MINUS "-"
52
- %terminal PLUS "+"
53
- %terminal NEWLINE "\n"
54
-
55
- %null.data left LPAREN LBRACK BINOP MINUS PLUS
56
- %null.data right EQUAL PROP RANGE ERANGE UNOP
57
-
58
- %%
59
-
60
- main: expressions.maybe
61
-
62
- expressions.maybe: expressions
63
- | nothing
64
-
65
- expressions: expressions block
66
- | block
67
-
68
- block: LBRACE expressions RBRACE
69
- | expression
70
-
71
- expression: conditional
72
- | class
73
- | module
74
- | loop
75
- | action
76
- | exception
77
- | directive
78
- | vexpression
79
-
80
- vexpression: NUMBER
81
- | IDENTIFIER
82
- | ISTRING
83
- | SSTRING
84
- | KEYWORD
85
- | REGEX
86
- | NEWLINE
87
- | interpolation
88
- | PLUS vexpression
89
- | MINUS vexpression
90
- | object
91
- | array
92
- | function
93
- | PREUNOP vexpression
94
- | UNOP vexpression
95
- | HEREDOC_REF
96
- | IHEREDOC_REF
97
- | heredoc
98
- | vexpression LPAREN vexpression.parameters.maybe RPAREN
99
- | vexpression EQUAL vexpression
100
- | vexpression PROP IDENTIFIER
101
- | vexpression LBRACK vexpression RBRACK
102
- | vexpression RANGE vexpression
103
- | vexpression ERANGE vexpression
104
- | vexpression BINOP vexpression
105
- | vexpression MINUS vexpression
106
- | vexpression PLUS vexpression
107
- | vexpression UNOP
108
-
109
- vexpression.parameters.maybe: vexpression.parameters
110
- | nothing
111
-
112
- vexpression.parameters: vexpression.parameters COMMA vexpression
113
- | vexpression
114
-
115
- object: LBRACE RBRACE
116
- array: LBRACK RBRACK
117
- function: LPAREN RPAREN ARROW
118
- heredoc: HEREDOC
119
- | IHEREDOC
120
-
121
- interpolation: interpolation.string
122
- | interpolation.heredoc
123
-
124
- interpolation.heredoc: IHEREDOC_BEGIN vexpression interpolation.heredoc.finish
125
- interpolation.heredoc.finish: interpolation.heredoc
126
- | IHEREDOC
127
-
128
- interpolation.string: ISTRING_BEGIN vexpression interpolation.string.finish
129
- interpolation.string.finish: interpolation.string
130
- | ISTRING
131
-
132
- conditional: IF LPAREN vexpression RPAREN block conditional.continue
133
- | UNLESS LPAREN vexpression RPAREN block
134
-
135
- conditional.continue: ELSIF LPAREN vexpression RPAREN block conditional.continue
136
- | ELSE block
137
-
138
- class: CLASS IDENTIFIER RBRACE LBRACE
139
- module: MODULE IDENTIFIER RBRACE LBRACE
140
-
141
- loop: WHILE LPAREN vexpression RPAREN block
142
- | FOR LPAREN IDENTIFIER IN vexpression RPAREN block
143
- | FOR LPAREN vexpression RPAREN block
144
-
145
- action: RETURN
146
- | ACTION
147
-
148
- exception: TRY block exception.catch.maybe exception.finally.maybe
149
- exception.catch.maybe: exception.catch
150
- | nothing
151
- exception.finally.maybe: exception.finally
152
- | nothing
153
- exception.catch: CATCH exception.catch.possible block
154
- exception.catch.possible: LPAREN IDENTIFIER RPAREN
155
- | LPAREN RPAREN
156
- | nothing
157
-
158
- exception.finally: FINALLY block
159
-
160
- directive: COLON LBRACK expressions RBRACK
161
-
162
- %%
1
+ %require "~> 0.1"
2
+ %generator "ruby"
3
+
4
+ %define api.push-pull pull
5
+ %define panic-mode true
6
+ %define ruby.error-class {SyntaxError}
7
+
8
+ %terminal REGEX
9
+ %terminal DIRECTIVE
10
+ %terminal IDENTIFIER
11
+ %terminal KEYWORD
12
+ %terminal NUMBER
13
+ %terminal SSTRING
14
+ %terminal ACTION
15
+ %terminal BINOP
16
+ %terminal PREUNOP
17
+ %terminal UNOP
18
+ %terminal HEREDOC
19
+ %terminal HEREDOC_REF
20
+ %terminal IHEREDOC
21
+ %terminal IHEREDOC_REF
22
+ %terminal IHEREDOC_BEGIN
23
+ %terminal ISTRING
24
+ %terminal ISTRING_BEGIN
25
+ %terminal CLASS "class"
26
+ %terminal MODULE "module"
27
+ %terminal IF "if"
28
+ %terminal UNLESS "unless"
29
+ %terminal ELSIF "elsif"
30
+ %terminal ELSE "else"
31
+ %terminal FOR "for"
32
+ %terminal WHILE "while"
33
+ %terminal TRY "try"
34
+ %terminal CATCH "catch"
35
+ %terminal FINALLY "finally"
36
+ %terminal RETURN "return"
37
+ %terminal IN "in"
38
+ %terminal ARROW "->"
39
+ %terminal EQUAL "="
40
+ %terminal LBRACE "{"
41
+ %terminal LPAREN "("
42
+ %terminal LBRACK "["
43
+ %terminal RBRACE "}"
44
+ %terminal RPAREN ")"
45
+ %terminal RBRACK "]"
46
+ %terminal COLON ":"
47
+ %terminal RANGE ".."
48
+ %terminal ERANGE "..."
49
+ %terminal PROP "."
50
+ %terminal COMMA ","
51
+ %terminal MINUS "-"
52
+ %terminal PLUS "+"
53
+ %terminal NEWLINE "\n"
54
+
55
+ %nonassoc FIX
56
+ %nonassoc LBRACK LPAREN
57
+ %right UNOP PROP
58
+ %left RANGE ERANGE
59
+ %left BINOP PLUS MINUS
60
+ %right EQUAL
61
+
62
+ %null.data left LPAREN LBRACK BINOP MINUS PLUS
63
+ %null.data right EQUAL PROP RANGE ERANGE UNOP
64
+
65
+ %%
66
+
67
+ main: expressions.maybe
68
+
69
+ expressions.maybe: expressions
70
+ | %empty { nil }
71
+
72
+ expressions: expressions expression { |a, b| a << b }
73
+ | expression { |a| [a] }
74
+
75
+ block: LBRACE expressions.maybe RBRACE { |_, a, _| [:block, a] }
76
+
77
+ block_or_vexpression: block
78
+ | vexpression
79
+
80
+ expression: conditional
81
+ | class
82
+ | module
83
+ | loop
84
+ | action
85
+ | exception
86
+ | directive
87
+ | vexpression
88
+ | NEWLINE { nil }
89
+ | vvexpression EQUAL vexpression { |a, _, b| [:set, a, b] }
90
+
91
+ vexpression: NUMBER
92
+ | ISTRING
93
+ | SSTRING
94
+ | KEYWORD
95
+ | REGEX
96
+ | interpolation
97
+ | PLUS vexpression { |_, a| [:pos, a] }
98
+ | MINUS vexpression { |_, a| [:neg, a] }
99
+ | object
100
+ | array
101
+ | function
102
+ | PREUNOP vexpression { |a, b| [:unop, a, b] }
103
+ | UNOP vexpression { |a, b| [:unop, a, b] }
104
+ | HEREDOC_REF
105
+ | IHEREDOC_REF
106
+ | LPAREN vexpression RPAREN { |_, a, _| a }
107
+ | heredoc
108
+ | vexpression LPAREN vexpression.parameters.maybe RPAREN
109
+ { |a, _, b, _| [:call, a, b] }
110
+ | vexpression RANGE vexpression
111
+ { |a, _, b| [:range, a, b] }
112
+ | vexpression ERANGE vexpression
113
+ { |a, _, b| [:erange, a, b] }
114
+ | vexpression BINOP vexpression
115
+ { |a, b, c| [:binop, a, b, c] }
116
+ | vexpression MINUS vexpression
117
+ { |a, b, c| [:binop, a, b, c] }
118
+ | vexpression PLUS vexpression
119
+ { |a, b, c| [:plus, a, b, c] }
120
+ | vexpression UNOP
121
+ { |a, b| [:unop, a, b] }
122
+ | vvexpression
123
+
124
+ vvexpression: vexpression PROP IDENTIFIER
125
+ { |a, _, b| [:prop, a, b] }
126
+ | vexpression LBRACK vexpression RBRACK
127
+ { |a, _, b| [:access, a, b] }
128
+ | IDENTIFIER
129
+
130
+ vexpression.parameters.maybe: vexpression.parameters
131
+ | %empty
132
+
133
+ vexpression.parameters: vexpression.parameters COMMA vexpression
134
+ { |a, _, b| a << b }
135
+ | vexpression { |*a| a }
136
+
137
+ object: LBRACE RBRACE { [:object] }
138
+ array: LBRACK RBRACK { [:array] }
139
+ function: ARROW function.arguments.maybe block
140
+ { |_, a, b| [:func, a, b] }
141
+ heredoc: HEREDOC
142
+ | IHEREDOC
143
+
144
+ function.arguments.maybe: LPAREN function.arguments.body.maybe RPAREN
145
+ { |_, a, _| a }
146
+ | %empty { nil }
147
+
148
+ function.arguments.body.maybe: function.arguments.body
149
+ | %empty { nil }
150
+ function.arguments.body: function.arguments.body COMMA IDENTIFIER
151
+ { |a, _, b| a << b }
152
+ | IDENTIFIER { |a| [a] }
153
+
154
+ interpolation: interpolation.string
155
+ | interpolation.heredoc
156
+
157
+ interpolation.heredoc: IHEREDOC_BEGIN vexpression interpolation.heredoc.finish
158
+ interpolation.heredoc.finish: interpolation.heredoc
159
+ | IHEREDOC
160
+
161
+ interpolation.string: ISTRING_BEGIN vexpression interpolation.string.finish
162
+ interpolation.string.finish: interpolation.string
163
+ | ISTRING
164
+
165
+ conditional: IF LPAREN vexpression RPAREN block
166
+ conditional.continue.maybe
167
+ { |_, _, a, _, b, c| [:if, a, b, c] }
168
+ | UNLESS LPAREN vexpression RPAREN block
169
+ { |_, _, a, _, b| [:unless, a, b] }
170
+
171
+ conditional.continue.maybe: conditional.continue
172
+ | %empty { nil }
173
+
174
+ conditional.continue: ELSIF LPAREN vexpression RPAREN block
175
+ conditional.continue.maybe
176
+ { |_, _, a, _, b, c| [:elsif, a, b, c] }
177
+ | ELSE block { |_, a| [:else, a] }
178
+
179
+ class: CLASS IDENTIFIER LBRACE class.definition.parts.maybe RBRACE
180
+ { |_, a, _, b, _| [:class, a, b] }
181
+ module: MODULE IDENTIFIER LBRACE module.definition.parts.maybe RBRACE
182
+ { |_, a, _, b, _| [:module, a, b] }
183
+
184
+ class.definition.parts.maybe: class.definition.parts
185
+ | %empty { nil }
186
+ class.definition.parts: class.definition.parts class.definition.part
187
+ { |a, b| a << b }
188
+ | class.definition.part { |a| [a] }
189
+ class.definition.part: IDENTIFIER COLON vexpression
190
+ { |a, _, b| [:inst, a, b] }
191
+ | IDENTIFIER PROP IDENTIFIER COLON vexpression
192
+ { |a, _, b, _, c| [:class, a, b, c] }
193
+ | module
194
+ | class
195
+
196
+ module.definition.parts.maybe: module.definition.parts
197
+ | %empty { nil }
198
+ module.definition.parts: module.definition.parts
199
+ module.definition.part
200
+ { |a, b| a << b }
201
+ | module.definition.part { |a| [a] }
202
+ module.definition.part: IDENTIFIER COLON vexpression
203
+ { |a, _, b| [:inst, a, b] }
204
+
205
+ loop: WHILE LPAREN vexpression RPAREN block
206
+ { |_, _, a, _, b| [:while, a, b] }
207
+ | FOR LPAREN IDENTIFIER IN vexpression RPAREN block
208
+ { |_, _, a, _, b, _, c| [:forin, a, b, c] }
209
+ | FOR LPAREN vexpression RPAREN block
210
+ { |_, _, a, _, b| [:for, a, b] }
211
+
212
+ action: RETURN vexpression { |_, a| [:return, a] }
213
+ | ACTION
214
+
215
+ exception: TRY LBRACE expressions.maybe RBRACE exception.catch.maybe
216
+ exception.finally.maybe
217
+ { |_, _, a, _, b, c| [:try, a, b, c] }
218
+ exception.catch.maybe: exception.catch
219
+ | %empty { nil }
220
+ exception.finally.maybe: exception.finally
221
+ | %empty { nil }
222
+ exception.catch: CATCH exception.catch.possible block
223
+ { |_, a, b| [:catch, a, b] }
224
+ exception.catch.possible: LPAREN IDENTIFIER RPAREN { |_, a, _| a }
225
+ | LPAREN RPAREN { nil }
226
+ | %empty { nil }
227
+
228
+ exception.finally: FINALLY block { |_, a| [:finally, a ] }
229
+
230
+ directive: COLON LBRACK expressions RBRACK
231
+ { |_, _, a, _| [:directive, a] }
232
+
233
+ %%
data/examples/simple.ace CHANGED
@@ -1,22 +1,22 @@
1
- %require "~> 0.1"
2
- %generator "ruby"
3
-
4
- %terminal IDENT
5
- %terminal STAR "*"
6
- %terminal EQUALS "="
7
-
8
- %%
9
-
10
- e: l EQUALS r
11
- | r
12
-
13
- l: IDENT
14
- | STAR r
15
-
16
- r: l
17
-
18
- %%
19
-
20
- class SimpleParser < Antelope::Parser
21
- %{write}
22
- end
1
+ %require "~> 0.1"
2
+ %generator "ruby"
3
+
4
+ %terminal IDENT
5
+ %terminal STAR "*"
6
+ %terminal EQUALS "="
7
+
8
+ %%
9
+
10
+ e: l EQUALS r
11
+ | r
12
+
13
+ l: IDENT
14
+ | STAR r
15
+
16
+ r: l
17
+
18
+ %%
19
+
20
+ class SimpleParser < Antelope::Parser
21
+ %{write}
22
+ end