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/liquor.y DELETED
@@ -1,313 +0,0 @@
1
- # Copyright (c) 2012-2013 Peter Zotov <whitequark@whitequark.org>
2
- # 2012 Yaroslav Markin <yaroslav@markin.net>
3
- # 2012 Nate Gadgibalaev <nat@xnsv.ru>
4
- #
5
- # MIT License
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining
8
- # a copy of this software and associated documentation files (the
9
- # "Software"), to deal in the Software without restriction, including
10
- # without limitation the rights to use, copy, modify, merge, publish,
11
- # distribute, sublicense, and/or sell copies of the Software, and to
12
- # permit persons to whom the Software is furnished to do so, subject to
13
- # the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be
16
- # included in all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
-
26
- class Liquor::Parser
27
- token comma dot endtag ident integer keyword lblock lblock2 lbracket
28
- linterp lparen op_div op_eq op_gt op_geq op_lt op_leq op_minus
29
- op_mod op_mul op_neq op_not op_plus pipe plaintext rblock
30
- rbracket rinterp rparen string tag_ident
31
-
32
- prechigh
33
- left dot
34
- nonassoc op_uminus op_not
35
- left op_mul op_div op_mod
36
- left op_plus op_minus
37
- left op_eq op_neq op_lt op_leq op_gt op_geq
38
- left op_and
39
- left op_or
40
- preclow
41
-
42
- expect 15
43
-
44
- start block
45
-
46
- rule
47
- block: /* empty */
48
- { result = [] }
49
- | plaintext block
50
- { result = [ val[0], *val[1] ] }
51
- | interp block
52
- { result = [ val[0], *val[1] ] }
53
- | tag block
54
- { result = [ val[0], *val[1] ] }
55
-
56
- interp:
57
- linterp expr rinterp
58
- { result = [ :interp, retag(val), val[1] ] }
59
- | linterp filter_chain rinterp
60
- { result = [ :interp, retag(val), val[1] ] }
61
-
62
- primary_expr:
63
- ident
64
- | lparen expr rparen
65
- { result = [ val[1][0], retag(val), *val[1][2..-1] ] }
66
-
67
- expr:
68
- integer
69
- | string
70
- | tuple
71
- | ident function_args
72
- { result = [ :call, retag(val), val[0], val[1] ] }
73
- | expr lbracket expr rbracket
74
- { result = [ :index, retag(val), val[0], val[2] ] }
75
- | expr dot ident function_args
76
- { result = [ :external, retag(val), val[0], val[2], val[3] ] }
77
- | expr dot ident
78
- { result = [ :external, retag(val), val[0], val[2], nil ] }
79
- | op_minus expr =op_uminus
80
- { result = [ :uminus, retag(val), val[1] ] }
81
- | op_not expr
82
- { result = [ :not, retag(val), val[1] ] }
83
- | expr op_mul expr
84
- { result = [ :mul, retag(val), val[0], val[2] ] }
85
- | expr op_div expr
86
- { result = [ :div, retag(val), val[0], val[2] ] }
87
- | expr op_mod expr
88
- { result = [ :mod, retag(val), val[0], val[2] ] }
89
- | expr op_plus expr
90
- { result = [ :plus, retag(val), val[0], val[2] ] }
91
- | expr op_minus expr
92
- { result = [ :minus, retag(val), val[0], val[2] ] }
93
- | expr op_eq expr
94
- { result = [ :eq, retag(val), val[0], val[2] ] }
95
- | expr op_neq expr
96
- { result = [ :neq, retag(val), val[0], val[2] ] }
97
- | expr op_lt expr
98
- { result = [ :lt, retag(val), val[0], val[2] ] }
99
- | expr op_leq expr
100
- { result = [ :leq, retag(val), val[0], val[2] ] }
101
- | expr op_gt expr
102
- { result = [ :gt, retag(val), val[0], val[2] ] }
103
- | expr op_geq expr
104
- { result = [ :geq, retag(val), val[0], val[2] ] }
105
- | expr op_and expr
106
- { result = [ :and, retag(val), val[0], val[2] ] }
107
- | expr op_or expr
108
- { result = [ :or, retag(val), val[0], val[2] ] }
109
- | primary_expr
110
-
111
- tuple:
112
- lbracket tuple_content rbracket
113
- { result = [ :tuple, retag(val), val[1].compact ] }
114
-
115
- tuple_content:
116
- expr comma tuple_content
117
- { result = [ val[0], *val[2] ] }
118
- | expr
119
- { result = [ val[0] ] }
120
- | /* empty */
121
- { result = [ ] }
122
-
123
- function_args:
124
- lparen function_args_inside rparen
125
- { result = [ :args, retag(val), *val[1] ] }
126
-
127
- function_args_inside:
128
- expr function_keywords
129
- { result = [ val[0], val[1][2] ] }
130
- | function_keywords
131
- { result = [ nil, val[0][2] ] }
132
-
133
- function_keywords:
134
- keyword expr function_keywords
135
- { name = val[0][2].to_sym
136
- tail = val[2][2]
137
- loc = retag([ val[0], val[1] ])
138
-
139
- if tail.include? name
140
- @errors << SyntaxError.new("duplicate keyword argument `#{val[0][2]}'",
141
- tail[name][1])
142
- end
143
-
144
- hash = {
145
- name => [ val[1][0], loc, *val[1][2..-1] ]
146
- }.merge(tail)
147
-
148
- result = [ :keywords, retag([ loc, val[2] ]), hash ]
149
- }
150
- | /* empty */
151
- { result = [ :keywords, nil, {} ] }
152
-
153
- filter_chain:
154
- expr pipe filter_chain_cont
155
- { result = [ val[0], *val[2] ].
156
- reduce { |tree, node| node[3][2] = tree; node }
157
- }
158
-
159
- filter_chain_cont:
160
- filter_call pipe filter_chain_cont
161
- { result = [ val[0], *val[2] ] }
162
- | filter_call
163
- { result = [ val[0] ] }
164
-
165
- filter_call:
166
- ident function_keywords
167
- { ident_loc = val[0][1]
168
- empty_args_loc = { line: ident_loc[:line],
169
- start: ident_loc[:end] + 1,
170
- end: ident_loc[:end] + 1, }
171
- result = [ :call, val[0][1], val[0],
172
- [ :args, val[1][1] || empty_args_loc, nil, val[1][2] ] ]
173
- }
174
-
175
- tag:
176
- lblock ident expr tag_first_cont
177
- { result = [ :tag, retag(val), val[1], val[2], *reduce_tag_args(val[3][2]) ] }
178
- | lblock ident tag_first_cont
179
- { result = [ :tag, retag(val), val[1], nil, *reduce_tag_args(val[2][2]) ] }
180
-
181
- # Racc cannot do lookahead across rules. I had to add states
182
- # explicitly to avoid S/R conflicts. You are not expected to
183
- # understand this.
184
-
185
- tag_first_cont:
186
- rblock
187
- { result = [ :cont, retag(val), [] ] }
188
- | keyword tag_first_cont2
189
- { result = [ :cont, retag(val), [ val[0], *val[1][2] ] ] }
190
-
191
- tag_first_cont2:
192
- rblock block lblock2 tag_next_cont
193
- { result = [ :cont2, val[0][1], [ [:block, val[0][1], val[1] ], *val[3] ] ] }
194
- | expr tag_first_cont
195
- { result = [ :cont2, retag(val), [ val[0], *val[1][2] ] ] }
196
-
197
- tag_next_cont:
198
- endtag rblock
199
- { result = [] }
200
- | keyword tag_next_cont2
201
- { result = [ val[0], *val[1] ] }
202
-
203
- tag_next_cont2:
204
- rblock block lblock2 tag_next_cont
205
- { result = [ [:block, val[0][1], val[1] ], *val[3] ] }
206
- | expr keyword tag_next_cont3
207
- { result = [ val[0], val[1], *val[2] ] }
208
-
209
- tag_next_cont3:
210
- rblock block lblock2 tag_next_cont
211
- { result = [ [:block, val[0][1], val[1] ], *val[3] ] }
212
- | expr tag_next_cont
213
- { result = [ val[0], *val[1] ] }
214
-
215
- ---- inner
216
- attr_reader :errors, :ast
217
-
218
- def initialize(tags={})
219
- super()
220
-
221
- @errors = []
222
- @ast = nil
223
- @tags = tags
224
- end
225
-
226
- def success?
227
- @errors.empty?
228
- end
229
-
230
- def parse(string, name='(code)')
231
- @errors.clear
232
- @name = name
233
- @ast = nil
234
-
235
- begin
236
- @stream = Lexer.lex(string, @name, @tags)
237
- @ast = do_parse
238
- rescue Liquor::SyntaxError => e
239
- @errors << e
240
- end
241
-
242
- success?
243
- end
244
-
245
- def next_token
246
- tok = @stream.shift
247
- [ tok[0], tok ] if tok
248
- end
249
-
250
- TOKEN_NAME_MAP = {
251
- :comma => ',',
252
- :dot => '.',
253
- :lblock => '{%',
254
- :rblock => '%}',
255
- :linterp => '{{',
256
- :rinterp => '}}',
257
- :lbracket => '[',
258
- :rbracket => ']',
259
- :lparen => '(',
260
- :rparen => ')',
261
- :pipe => '|',
262
- :op_not => '!',
263
- :op_mul => '*',
264
- :op_div => '/',
265
- :op_mod => '%',
266
- :op_plus => '+',
267
- :op_minus => '-',
268
- :op_eq => '==',
269
- :op_neq => '!=',
270
- :op_lt => '<',
271
- :op_leq => '<=',
272
- :op_gt => '>',
273
- :op_geq => '>=',
274
- :keyword => 'keyword argument name',
275
- :kwarg => 'keyword argument',
276
- :ident => 'identifier',
277
- }
278
-
279
- def on_error(error_token_id, error_token, value_stack)
280
- if token_to_str(error_token_id) == "$end"
281
- raise Liquor::SyntaxError.new("unexpected end of program", {
282
- file: @name
283
- })
284
- else
285
- type, (loc, value) = error_token
286
- type = TOKEN_NAME_MAP[type] || type
287
-
288
- raise Liquor::SyntaxError.new("unexpected token `#{type}'", loc)
289
- end
290
- end
291
-
292
- def retag(nodes)
293
- loc = nodes.map { |node| node[1] }.compact
294
- first, *, last = loc
295
- return first if last.nil?
296
-
297
- {
298
- file: first[:file],
299
- line: first[:line],
300
- start: first[:start],
301
- end: last[:end],
302
- }
303
- end
304
-
305
- def reduce_tag_args(list)
306
- list.each_slice(2).reduce([]) { |args, (k, v)|
307
- if v[0] == :block
308
- args << [ :blockarg, retag([ k, v ]), k, v[2] || [] ]
309
- else
310
- args << [ :kwarg, retag([ k, v ]), k, v ]
311
- end
312
- }
313
- end