racc 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/README.ja.rdoc +0 -1
  3. data/README.rdoc +6 -7
  4. data/{rdoc → doc}/en/NEWS.en.rdoc +0 -0
  5. data/{rdoc → doc}/en/grammar.en.rdoc +27 -31
  6. data/doc/en/grammar2.en.rdoc +219 -0
  7. data/{rdoc → doc}/ja/NEWS.ja.rdoc +0 -0
  8. data/{rdoc → doc}/ja/command.ja.html +0 -0
  9. data/{rdoc → doc}/ja/debug.ja.rdoc +0 -0
  10. data/{rdoc → doc}/ja/grammar.ja.rdoc +0 -0
  11. data/{rdoc → doc}/ja/index.ja.html +0 -0
  12. data/{rdoc → doc}/ja/parser.ja.rdoc +0 -0
  13. data/{rdoc → doc}/ja/usage.ja.html +0 -0
  14. data/ext/racc/cparse/cparse.c +1 -1
  15. data/ext/racc/cparse/extconf.rb +1 -0
  16. data/lib/racc/info.rb +1 -1
  17. data/lib/racc/parser-text.rb +1 -1
  18. data/lib/racc/parser.rb +1 -1
  19. data/lib/racc/parserfilegenerator.rb +0 -44
  20. data/lib/racc/statetransitiontable.rb +2 -8
  21. metadata +15 -121
  22. data/Rakefile +0 -79
  23. data/ext/racc/com/headius/racc/Cparse.java +0 -849
  24. data/lib/racc/pre-setup +0 -13
  25. data/sample/array.y +0 -67
  26. data/sample/array2.y +0 -59
  27. data/sample/calc-ja.y +0 -66
  28. data/sample/calc.y +0 -65
  29. data/sample/conflict.y +0 -15
  30. data/sample/hash.y +0 -60
  31. data/sample/lalr.y +0 -17
  32. data/sample/lists.y +0 -57
  33. data/sample/syntax.y +0 -46
  34. data/sample/yyerr.y +0 -46
  35. data/test/assets/cadenza.y +0 -170
  36. data/test/assets/cast.y +0 -926
  37. data/test/assets/chk.y +0 -126
  38. data/test/assets/conf.y +0 -16
  39. data/test/assets/csspool.y +0 -729
  40. data/test/assets/digraph.y +0 -29
  41. data/test/assets/echk.y +0 -118
  42. data/test/assets/edtf.y +0 -583
  43. data/test/assets/err.y +0 -60
  44. data/test/assets/error_recovery.y +0 -35
  45. data/test/assets/expect.y +0 -7
  46. data/test/assets/firstline.y +0 -4
  47. data/test/assets/huia.y +0 -318
  48. data/test/assets/ichk.y +0 -102
  49. data/test/assets/intp.y +0 -546
  50. data/test/assets/journey.y +0 -47
  51. data/test/assets/liquor.y +0 -313
  52. data/test/assets/machete.y +0 -423
  53. data/test/assets/macruby.y +0 -2197
  54. data/test/assets/mailp.y +0 -437
  55. data/test/assets/mediacloth.y +0 -599
  56. data/test/assets/mof.y +0 -649
  57. data/test/assets/namae.y +0 -302
  58. data/test/assets/nasl.y +0 -626
  59. data/test/assets/newsyn.y +0 -25
  60. data/test/assets/noend.y +0 -4
  61. data/test/assets/nokogiri-css.y +0 -255
  62. data/test/assets/nonass.y +0 -41
  63. data/test/assets/normal.y +0 -27
  64. data/test/assets/norule.y +0 -4
  65. data/test/assets/nullbug1.y +0 -25
  66. data/test/assets/nullbug2.y +0 -15
  67. data/test/assets/opal.y +0 -1807
  68. data/test/assets/opt.y +0 -123
  69. data/test/assets/percent.y +0 -35
  70. data/test/assets/php_serialization.y +0 -98
  71. data/test/assets/recv.y +0 -97
  72. data/test/assets/riml.y +0 -665
  73. data/test/assets/rrconf.y +0 -14
  74. data/test/assets/ruby18.y +0 -1943
  75. data/test/assets/ruby19.y +0 -2174
  76. data/test/assets/ruby20.y +0 -2350
  77. data/test/assets/ruby21.y +0 -2359
  78. data/test/assets/ruby22.y +0 -2381
  79. data/test/assets/scan.y +0 -72
  80. data/test/assets/syntax.y +0 -50
  81. data/test/assets/tp_plus.y +0 -622
  82. data/test/assets/twowaysql.y +0 -278
  83. data/test/assets/unterm.y +0 -5
  84. data/test/assets/useless.y +0 -12
  85. data/test/assets/yyerr.y +0 -46
  86. data/test/bench.y +0 -36
  87. data/test/helper.rb +0 -115
  88. data/test/infini.y +0 -8
  89. data/test/regress/cadenza +0 -796
  90. data/test/regress/cast +0 -3428
  91. data/test/regress/csspool +0 -2314
  92. data/test/regress/edtf +0 -1794
  93. data/test/regress/huia +0 -1392
  94. data/test/regress/journey +0 -222
  95. data/test/regress/liquor +0 -885
  96. data/test/regress/machete +0 -833
  97. data/test/regress/mediacloth +0 -1463
  98. data/test/regress/mof +0 -1368
  99. data/test/regress/namae +0 -634
  100. data/test/regress/nasl +0 -2058
  101. data/test/regress/nokogiri-css +0 -836
  102. data/test/regress/opal +0 -6431
  103. data/test/regress/php_serialization +0 -336
  104. data/test/regress/riml +0 -3283
  105. data/test/regress/ruby18 +0 -6344
  106. data/test/regress/ruby22 +0 -7460
  107. data/test/regress/tp_plus +0 -1933
  108. data/test/regress/twowaysql +0 -556
  109. data/test/scandata/brace +0 -7
  110. data/test/scandata/gvar +0 -1
  111. data/test/scandata/normal +0 -4
  112. data/test/scandata/percent +0 -18
  113. data/test/scandata/slash +0 -10
  114. data/test/src.intp +0 -34
  115. data/test/start.y +0 -20
  116. data/test/test_chk_y.rb +0 -52
  117. data/test/test_grammar_file_parser.rb +0 -15
  118. data/test/test_racc_command.rb +0 -339
  119. data/test/test_scan_y.rb +0 -52
  120. data/test/testscanner.rb +0 -51
  121. data/web/racc.en.rhtml +0 -42
  122. data/web/racc.ja.rhtml +0 -51
data/test/assets/huia.y DELETED
@@ -1,318 +0,0 @@
1
- # Copyright (c) 2014 James Harton
2
- #
3
- # MIT License
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining
6
- # a copy of this software and associated documentation files (the
7
- # "Software"), to deal in the Software without restriction, including
8
- # without limitation the rights to use, copy, modify, merge, publish,
9
- # distribute, sublicense, and/or sell copies of the Software, and to
10
- # permit persons to whom the Software is furnished to do so, subject to
11
- # the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be
14
- # included in all copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- class Huia::Parser
25
-
26
- token
27
- IDENTIFIER EQUAL PLUS MINUS ASTERISK FWD_SLASH COLON FLOAT INTEGER STRING
28
- EXPO INDENT OUTDENT OPAREN CPAREN DOT SIGNATURE NL EOF PIPE COMMA NIL TRUE
29
- FALSE EQUALITY CALL SELF CONSTANT CHAR DOUBLE_TICK_STRING
30
- DOUBLE_TICK_STRING_END INTERPOLATE_START INTERPOLATE_END BOX LSQUARE
31
- RSQUARE FACES LFACE RFACE BANG TILDE RETURN NOT_EQUALITY OR AND GT LT
32
- GTE LTE AT
33
-
34
- prechigh
35
- left EXPO
36
- left BANG TILDE
37
- left ASTERISK FWD_SLASH PERCENT
38
- left PLUS MINUS
39
-
40
- right EQUAL
41
- preclow
42
-
43
- rule
44
- statements: statement
45
- | statements statement { return scope }
46
-
47
- statement: expr eol { return scope.append val[0] }
48
- | expr { return scope.append val[0] }
49
- | eol { return scope }
50
-
51
- eol: NL | EOF
52
- nlq: NL |
53
-
54
- expr: literal
55
- | grouped_expr
56
- | binary_op
57
- | unary_op
58
- | method_call
59
- | constant
60
- | variable
61
- | array
62
- | hash
63
- | return
64
-
65
- return: return_expr
66
- | return_nil
67
- return_expr: RETURN expr { return n(:Return, val[1]) }
68
- return_nil: RETURN { return n(:Return, n(:Nil)) }
69
-
70
- array: empty_array
71
- | array_list
72
-
73
- empty_array: BOX { return n :Array }
74
-
75
- array_list: LSQUARE array_items RSQUARE { return val[1] }
76
- array_items: expr { return n :Array, [val[0]] }
77
- | array_items COMMA expr { val[0].append(val[2]); return val[0] }
78
-
79
- hash: empty_hash
80
- | hash_list
81
- empty_hash: FACES { return n :Hash }
82
- hash_list: LFACE hash_items RFACE { return val[1] }
83
- hash_items: hash_item { return n :Hash, val[0] }
84
- | hash_items COMMA hash_item { val[0].append(val[2]); return val[0] }
85
- hash_item: expr COLON expr { return n :HashItem, val[0], val[2] }
86
-
87
- constant: CONSTANT { return constant val[0] }
88
-
89
- indented: indented_w_stmts
90
- | indented_w_expr
91
- | indented_wo_stmts
92
- indented_w_stmts: indent statements outdent { return val[0] }
93
- indented_w_expr: indent expr outdent { return val[0].append(val[1]) }
94
- indented_wo_stmts: indent outdent { return val[0] }
95
- outdent: OUTDENT { return pop_scope }
96
-
97
-
98
- indent_w_args: indent_pipe indent_args PIPE nlq INDENT { return val[0] }
99
- indent_pipe: PIPE { return push_scope }
100
- indent_wo_args: INDENT { return push_scope }
101
- indent: indent_w_args
102
- | indent_wo_args
103
-
104
- indent_args: indent_arg
105
- | indent_args COMMA indent_arg
106
- indent_arg: arg_var { return scope.add_argument val[0] }
107
- | arg_var EQUAL expr { return n :Assignment, val[0], val[2] }
108
- arg_var: IDENTIFIER { return n :Variable, val[0] }
109
-
110
- method_call: method_call_on_object
111
- | method_call_on_self
112
- | method_call_on_closure
113
- method_call_on_object: expr DOT call_signature { return n :MethodCall, val[0], val[2] }
114
- | expr DOT IDENTIFIER { return n :MethodCall, val[0], n(:CallSignature, val[2]) }
115
- method_call_on_self: call_signature { return n :MethodCall, scope_instance, val[0] }
116
-
117
- method_call_on_closure: AT call_signature { return n :MethodCall, this_closure, val[1] }
118
- | AT IDENTIFIER { return n :MethodCall, this_closure, n(:CallSignature, val[1]) }
119
-
120
- call_signature: call_arguments
121
- | call_simple_name
122
- call_simple_name: CALL { return n :CallSignature, val[0] }
123
- call_argument: SIGNATURE call_passed_arg { return n :CallSignature, val[0], [val[1]] }
124
- call_passed_arg: call_passed_simple
125
- | call_passed_indented
126
- call_passed_simple: expr
127
- | expr NL
128
- call_passed_indented: indented
129
- | indented NL
130
- call_arguments: call_argument { return val[0] }
131
- | call_arguments call_argument { return val[0].concat_signature val[1] }
132
-
133
- grouped_expr: OPAREN expr CPAREN { return n :Expression, val[1] }
134
-
135
- variable: IDENTIFIER { return allocate_local val[0] }
136
-
137
- binary_op: assignment
138
- | addition
139
- | subtraction
140
- | multiplication
141
- | division
142
- | exponentiation
143
- | modulo
144
- | equality
145
- | not_equality
146
- | logical_or
147
- | logical_and
148
- | greater_than
149
- | less_than
150
- | greater_or_eq
151
- | less_or_eq
152
-
153
- assignment: IDENTIFIER EQUAL expr { return allocate_local_assignment val[0], val[2] }
154
- addition: expr PLUS expr { return binary val[0], val[2], 'plus:' }
155
- subtraction: expr MINUS expr { return binary val[0], val[2], 'minus:' }
156
- multiplication: expr ASTERISK expr { return binary val[0], val[2], 'multiplyBy:' }
157
- division: expr FWD_SLASH expr { return binary val[0], val[2], 'divideBy:' }
158
- exponentiation: expr EXPO expr { return binary val[0], val[2], 'toThePowerOf:' }
159
- modulo: expr PERCENT expr { return binary val[0], val[2], 'moduloOf:' }
160
- equality: expr EQUALITY expr { return binary val[0], val[2], 'isEqualTo:' }
161
- not_equality: expr NOT_EQUALITY expr { return binary val[0], val[2], 'isNotEqualTo:' }
162
- logical_or: expr OR expr { return binary val[0], val[2], 'logicalOr:' }
163
- logical_and: expr AND expr { return binary val[0], val[2], 'logicalAnd:' }
164
- greater_than: expr GT expr { return binary val[0], val[2], 'isGreaterThan:' }
165
- less_than: expr LT expr { return binary val[0], val[2], 'isLessThan:' }
166
- greater_or_eq: expr GTE expr { return binary val[0], val[2], 'isGreaterOrEqualTo:' }
167
- less_or_eq: expr LTE expr { return binary val[0], val[2], 'isLessOrEqualTo:' }
168
-
169
- unary_op: unary_not
170
- | unary_plus
171
- | unary_minus
172
- | unary_complement
173
-
174
- unary_not: BANG expr { return unary val[1], 'unaryNot' }
175
- unary_plus: PLUS expr { return unary val[1], 'unaryPlus' }
176
- unary_minus: MINUS expr { return unary val[1], 'unaryMinus' }
177
- unary_complement: TILDE expr { return unary val[1], 'unaryComplement' }
178
-
179
- literal: integer
180
- | float
181
- | string
182
- | nil
183
- | true
184
- | false
185
- | self
186
-
187
- float: FLOAT { return n :Float, val[0] }
188
- integer: INTEGER { return n :Integer, val[0] }
189
- nil: NIL { return n :Nil }
190
- true: TRUE { return n :True }
191
- false: FALSE { return n :False }
192
- self: SELF { return n :Self }
193
-
194
- string: STRING { return n :String, val[0] }
195
- | interpolated_string
196
- | empty_string
197
-
198
- interpolated_string: DOUBLE_TICK_STRING interpolated_string_contents DOUBLE_TICK_STRING_END { return val[1] }
199
- interpolation: INTERPOLATE_START expr INTERPOLATE_END { return val[1] }
200
- interpolated_string_contents: interpolated_string_chunk { return n :InterpolatedString, val[0] }
201
- | interpolated_string_contents interpolated_string_chunk { val[0].append(val[1]); return val[0] }
202
- interpolated_string_chunk: chars { return val[0] }
203
- | interpolation { return to_string(val[0]) }
204
- empty_string: DOUBLE_TICK_STRING DOUBLE_TICK_STRING_END { return n :String, '' }
205
-
206
- chars: CHAR { return n :String, val[0] }
207
- | chars CHAR { val[0].append(val[1]); return val[0] }
208
- end
209
-
210
- ---- inner
211
-
212
- attr_accessor :lexer, :scopes, :state
213
-
214
- def initialize lexer
215
- @lexer = lexer
216
- @state = []
217
- @scopes = []
218
- push_scope
219
- end
220
-
221
- def ast
222
- @ast ||= do_parse
223
- @scopes.first
224
- end
225
-
226
- def on_error t, val, vstack
227
- line = lexer.line
228
- col = lexer.column
229
- message = "Unexpected #{token_to_str t} at #{lexer.filename} line #{line}:#{col}:\n\n"
230
-
231
- start = line - 5 > 0 ? line - 5 : 0
232
- i_size = line.to_s.size
233
- (start..(start + 5)).each do |i|
234
- message << sprintf("\t%#{i_size}d: %s\n", i, lexer.get_line(i))
235
- message << "\t#{' ' * i_size} #{'-' * (col - 1)}^\n" if i == line
236
- end
237
-
238
- raise SyntaxError, message
239
- end
240
-
241
- def next_token
242
- nt = lexer.next_computed_token
243
- # just use a state stack for now, we'll have to do something
244
- # more sophisticated soon.
245
- if nt && nt.first == :state
246
- if nt.last
247
- state.push << nt.last
248
- else
249
- state.pop
250
- end
251
- next_token
252
- else
253
- nt
254
- end
255
- end
256
-
257
- def push_scope
258
- new_scope = Huia::AST::Scope.new scope
259
- new_scope.file = lexer.filename
260
- new_scope.line = lexer.line
261
- new_scope.column = lexer.column
262
- scopes.push new_scope
263
- new_scope
264
- end
265
-
266
- def pop_scope
267
- scopes.pop
268
- end
269
-
270
- def scope
271
- scopes.last
272
- end
273
-
274
- def binary left, right, method
275
- node(:MethodCall, left, node(:CallSignature, method, [right]))
276
- end
277
-
278
- def unary left, method
279
- node(:MethodCall, left, node(:CallSignature, method))
280
- end
281
-
282
- def node type, *args
283
- Huia::AST.const_get(type).new(*args).tap do |n|
284
- n.file = lexer.filename
285
- n.line = lexer.line
286
- n.column = lexer.column
287
- end
288
- end
289
- alias n node
290
-
291
- def allocate_local name
292
- node(:Variable, name).tap do |n|
293
- scope.allocate_local n
294
- end
295
- end
296
-
297
- def allocate_local_assignment name, value
298
- node(:Assignment, name, value).tap do |n|
299
- scope.allocate_local n
300
- end
301
- end
302
-
303
- def this_closure
304
- allocate_local('@')
305
- end
306
-
307
- def scope_instance
308
- node(:ScopeInstance, scope)
309
- end
310
-
311
- def constant name
312
- return scope_instance if name == 'self'
313
- node(:Constant, name)
314
- end
315
-
316
- def to_string expr
317
- node(:MethodCall, expr, node(:CallSignature, 'toString'))
318
- end
data/test/assets/ichk.y DELETED
@@ -1,102 +0,0 @@
1
- class Calculator
2
-
3
- prechigh
4
- left '*' '/'
5
- left '+' '-'
6
- preclow
7
-
8
- convert
9
- NUMBER 'Number'
10
- end
11
-
12
- rule
13
-
14
- target : exp
15
- | /* none */ { result = 0 }
16
-
17
- exp : exp '+' exp { result += val[2]; a = 'plus' }
18
- | exp '-' exp { result -= val[2]; a = "string test" }
19
- | exp '*' exp { result *= val[2] }
20
- | exp '/' exp { result /= val[2] }
21
- | '(' { $emb = true } exp ')'
22
- {
23
- raise 'must not happen' unless $emb
24
- result = val[2]
25
- }
26
- | '-' NUMBER { result = -val[1] }
27
- | NUMBER
28
-
29
- ----header
30
-
31
- class Number
32
- end
33
-
34
- ----inner
35
-
36
- def initialize
37
- @racc_debug_out = $stdout
38
- @yydebug = false
39
- end
40
-
41
- def validate(expected, src)
42
- result = parse(src)
43
- unless result == expected
44
- raise "test #{@test_number} fail"
45
- end
46
- @test_number += 1
47
- end
48
-
49
- def parse(src)
50
- @src = src
51
- @test_number = 1
52
- yyparse self, :scan
53
- end
54
-
55
- def scan(&block)
56
- @src.each(&block)
57
- end
58
-
59
- ----footer
60
-
61
- calc = Calculator.new
62
-
63
- calc.validate(9, [[Number, 9], nil])
64
-
65
- calc.validate(-3,
66
- [[Number, 5],
67
- ['*', '*'],
68
- [Number, 1],
69
- ['-', '*'],
70
- [Number, 1],
71
- ['*', '*'],
72
- [Number, 8],
73
- nil])
74
-
75
- calc.validate(-1,
76
- [[Number, 5],
77
- ['+', '+'],
78
- [Number, 2],
79
- ['-', '-'],
80
- [Number, 5],
81
- ['+', '+'],
82
- [Number, 2],
83
- ['-', '-'],
84
- [Number, 5],
85
- nil])
86
-
87
- calc.validate(-4,
88
- [['-', 'UMINUS'],
89
- [Number, 4],
90
- nil])
91
-
92
- calc.validate(40,
93
- [[Number, 7],
94
- ['*', '*'],
95
- ['(', '('],
96
- [Number, 4],
97
- ['+', '+'],
98
- [Number, 3],
99
- [')', ')'],
100
- ['-', '-'],
101
- [Number, 9],
102
- nil])