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
@@ -1,423 +0,0 @@
1
- # Copyright (c) 2011 SUSE
2
- #
3
- # Permission is hereby granted, free of charge, to any person
4
- # obtaining a copy of this software and associated documentation
5
- # files (the "Software"), to deal in the Software without
6
- # restriction, including without limitation the rights to use,
7
- # copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- # copies of the Software, and to permit persons to whom the
9
- # Software is furnished to do so, subject to the following
10
- # conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
- # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
- # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
- # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
- # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- # OTHER DEALINGS IN THE SOFTWARE.
23
-
24
- class Machete::Parser
25
-
26
- token NIL
27
- token TRUE
28
- token FALSE
29
- token INTEGER
30
- token SYMBOL
31
- token STRING
32
- token REGEXP
33
- token ANY
34
- token EVEN
35
- token ODD
36
- token METHOD_NAME
37
- token CLASS_NAME
38
-
39
- start expression
40
-
41
- rule
42
-
43
- expression : primary
44
- | expression "|" primary {
45
- result = if val[0].is_a?(ChoiceMatcher)
46
- ChoiceMatcher.new(val[0].alternatives << val[2])
47
- else
48
- ChoiceMatcher.new([val[0], val[2]])
49
- end
50
- }
51
-
52
- primary : node
53
- | array
54
- | literal
55
- | any
56
-
57
- node : CLASS_NAME {
58
- result = NodeMatcher.new(val[0].to_sym)
59
- }
60
- | CLASS_NAME "<" attrs ">" {
61
- result = NodeMatcher.new(val[0].to_sym, val[2])
62
- }
63
-
64
- attrs : attr
65
- | attrs "," attr { result = val[0].merge(val[2]) }
66
-
67
- attr : method_name "=" expression { result = { val[0].to_sym => val[2] } }
68
- | method_name "^=" SYMBOL {
69
- result = {
70
- val[0].to_sym => SymbolRegexpMatcher.new(
71
- Regexp.new("^" + Regexp.escape(symbol_value(val[2]).to_s))
72
- )
73
- }
74
- }
75
- | method_name "$=" SYMBOL {
76
- result = {
77
- val[0].to_sym => SymbolRegexpMatcher.new(
78
- Regexp.new(Regexp.escape(symbol_value(val[2]).to_s) + "$")
79
- )
80
- }
81
- }
82
- | method_name "*=" SYMBOL {
83
- result = {
84
- val[0].to_sym => SymbolRegexpMatcher.new(
85
- Regexp.new(Regexp.escape(symbol_value(val[2]).to_s))
86
- )
87
- }
88
- }
89
- | method_name "^=" STRING {
90
- result = {
91
- val[0].to_sym => StringRegexpMatcher.new(
92
- Regexp.new("^" + Regexp.escape(string_value(val[2])))
93
- )
94
- }
95
- }
96
- | method_name "$=" STRING {
97
- result = {
98
- val[0].to_sym => StringRegexpMatcher.new(
99
- Regexp.new(Regexp.escape(string_value(val[2])) + "$")
100
- )
101
- }
102
- }
103
- | method_name "*=" STRING {
104
- result = {
105
- val[0].to_sym => StringRegexpMatcher.new(
106
- Regexp.new(Regexp.escape(string_value(val[2])))
107
- )
108
- }
109
- }
110
- | method_name "*=" REGEXP {
111
- result = {
112
- val[0].to_sym => IndifferentRegexpMatcher.new(
113
- Regexp.new(regexp_value(val[2]))
114
- )
115
- }
116
- }
117
-
118
- # Hack to overcome the fact that some tokens will lex as simple tokens, not
119
- # METHOD_NAME tokens, and that "reserved words" will lex as separate kinds of
120
- # tokens.
121
- method_name : METHOD_NAME
122
- | NIL
123
- | TRUE
124
- | FALSE
125
- | ANY
126
- | EVEN
127
- | ODD
128
- | "*"
129
- | "+"
130
- | "<"
131
- | ">"
132
- | "^"
133
- | "|"
134
-
135
- array : "[" items_opt "]" { result = ArrayMatcher.new(val[1]) }
136
-
137
- items_opt : /* empty */ { result = [] }
138
- | items
139
-
140
- items : item { result = [val[0]] }
141
- | items "," item { result = val[0] << val[2] }
142
-
143
- item : expression
144
- | expression quantifier { result = Quantifier.new(val[0], *val[1]) }
145
-
146
- quantifier : "*" { result = [0, nil, 1] }
147
- | "+" { result = [1, nil, 1] }
148
- | "?" { result = [0, 1, 1] }
149
- | "{" INTEGER "}" {
150
- result = [integer_value(val[1]), integer_value(val[1]), 1]
151
- }
152
- | "{" INTEGER "," "}" {
153
- result = [integer_value(val[1]), nil, 1]
154
- }
155
- | "{" "," INTEGER "}" {
156
- result = [0, integer_value(val[2]), 1]
157
- }
158
- | "{" INTEGER "," INTEGER "}" {
159
- result = [integer_value(val[1]), integer_value(val[3]), 1]
160
- }
161
- | "{" EVEN "}" { result = [0, nil, 2] }
162
- | "{" ODD "}" { result = [1, nil, 2] }
163
-
164
- literal : NIL { result = LiteralMatcher.new(nil) }
165
- | TRUE { result = LiteralMatcher.new(true) }
166
- | FALSE { result = LiteralMatcher.new(false) }
167
- | INTEGER { result = LiteralMatcher.new(integer_value(val[0])) }
168
- | SYMBOL { result = LiteralMatcher.new(symbol_value(val[0])) }
169
- | STRING { result = LiteralMatcher.new(string_value(val[0])) }
170
- | REGEXP { result = LiteralMatcher.new(regexp_value(val[0])) }
171
-
172
- any : ANY { result = AnyMatcher.new }
173
-
174
- ---- inner
175
-
176
- include Matchers
177
-
178
- class SyntaxError < StandardError; end
179
-
180
- def parse(input)
181
- @input = input
182
- @pos = 0
183
-
184
- do_parse
185
- end
186
-
187
- private
188
-
189
- def integer_value(value)
190
- if value =~ /^0[bB]/
191
- value[2..-1].to_i(2)
192
- elsif value =~ /^0[oO]/
193
- value[2..-1].to_i(8)
194
- elsif value =~ /^0[dD]/
195
- value[2..-1].to_i(10)
196
- elsif value =~ /^0[xX]/
197
- value[2..-1].to_i(16)
198
- elsif value =~ /^0/
199
- value.to_i(8)
200
- else
201
- value.to_i
202
- end
203
- end
204
-
205
- def symbol_value(value)
206
- value[1..-1].to_sym
207
- end
208
-
209
- def string_value(value)
210
- quote = value[0..0]
211
- if quote == "'"
212
- value[1..-2].gsub("\\\\", "\\").gsub("\\'", "'")
213
- elsif quote == '"'
214
- value[1..-2].
215
- gsub("\\\\", "\\").
216
- gsub('\\"', '"').
217
- gsub("\\n", "\n").
218
- gsub("\\t", "\t").
219
- gsub("\\r", "\r").
220
- gsub("\\f", "\f").
221
- gsub("\\v", "\v").
222
- gsub("\\a", "\a").
223
- gsub("\\e", "\e").
224
- gsub("\\b", "\b").
225
- gsub("\\s", "\s").
226
- gsub(/\\([0-7]{1,3})/) { $1.to_i(8).chr }.
227
- gsub(/\\x([0-9a-fA-F]{1,2})/) { $1.to_i(16).chr }
228
- else
229
- raise "Unknown quote: #{quote.inspect}."
230
- end
231
- end
232
-
233
- REGEXP_OPTIONS = {
234
- 'i' => Regexp::IGNORECASE,
235
- 'm' => Regexp::MULTILINE,
236
- 'x' => Regexp::EXTENDED
237
- }
238
-
239
- def regexp_value(value)
240
- /\A\/(.*)\/([imx]*)\z/ =~ value
241
- pattern, options = $1, $2
242
-
243
- Regexp.new(pattern, options.chars.map { |ch| REGEXP_OPTIONS[ch] }.inject(:|))
244
- end
245
-
246
- # "^" needs to be here because if it were among operators recognized by
247
- # METHOD_NAME, "^=" would be recognized as two tokens.
248
- SIMPLE_TOKENS = [
249
- "|",
250
- "<",
251
- ">",
252
- ",",
253
- "=",
254
- "^=",
255
- "^",
256
- "$=",
257
- "[",
258
- "]",
259
- "*=",
260
- "*",
261
- "+",
262
- "?",
263
- "{",
264
- "}"
265
- ]
266
-
267
- COMPLEX_TOKENS = [
268
- [:NIL, /^nil/],
269
- [:TRUE, /^true/],
270
- [:FALSE, /^false/],
271
- # INTEGER needs to be before METHOD_NAME, otherwise e.g. "+1" would be
272
- # recognized as two tokens.
273
- [
274
- :INTEGER,
275
- /^
276
- [+-]? # sign
277
- (
278
- 0[bB][01]+(_[01]+)* # binary (prefixed)
279
- |
280
- 0[oO][0-7]+(_[0-7]+)* # octal (prefixed)
281
- |
282
- 0[dD]\d+(_\d+)* # decimal (prefixed)
283
- |
284
- 0[xX][0-9a-fA-F]+(_[0-9a-fA-F]+)* # hexadecimal (prefixed)
285
- |
286
- 0[0-7]*(_[0-7]+)* # octal (unprefixed)
287
- |
288
- [1-9]\d*(_\d+)* # decimal (unprefixed)
289
- )
290
- /x
291
- ],
292
- [
293
- :SYMBOL,
294
- /^
295
- :
296
- (
297
- # class name
298
- [A-Z][a-zA-Z0-9_]*
299
- |
300
- # regular method name
301
- [a-z_][a-zA-Z0-9_]*[?!=]?
302
- |
303
- # instance variable name
304
- @[a-zA-Z_][a-zA-Z0-9_]*
305
- |
306
- # class variable name
307
- @@[a-zA-Z_][a-zA-Z0-9_]*
308
- |
309
- # operator (sorted by length, then alphabetically)
310
- (<=>|===|\[\]=|\*\*|\+@|-@|<<|<=|==|=~|>=|>>|\[\]|[%&*+\-\/<>^`|~])
311
- )
312
- /x
313
- ],
314
- [
315
- :STRING,
316
- /^
317
- (
318
- ' # sinqle-quoted string
319
- (
320
- \\[\\'] # escape
321
- |
322
- [^'] # regular character
323
- )*
324
- '
325
- |
326
- " # double-quoted string
327
- (
328
- \\ # escape
329
- (
330
- [\\"ntrfvaebs] # one-character escape
331
- |
332
- [0-7]{1,3} # octal number escape
333
- |
334
- x[0-9a-fA-F]{1,2} # hexadecimal number escape
335
- )
336
- |
337
- [^"] # regular character
338
- )*
339
- "
340
- )
341
- /x
342
- ],
343
- [
344
- :REGEXP,
345
- /^
346
- \/
347
- (
348
- \\ # escape
349
- (
350
- [\\\/ntrfvaebs\(\)\[\]\{\}\-\.\?\*\+\|\^\$] # one-character escape
351
- |
352
- [0-7]{2,3} # octal number escape
353
- |
354
- x[0-9a-fA-F]{1,2} # hexadecimal number escape
355
- )
356
- |
357
- [^\/] # regular character
358
- )*
359
- \/
360
- [imx]*
361
- /x
362
- ],
363
- # ANY, EVEN and ODD need to be before METHOD_NAME, otherwise they would be
364
- # recognized as method names.
365
- [:ANY, /^any/],
366
- [:EVEN, /^even/],
367
- [:ODD, /^odd/],
368
- # We exclude "*", "+", "<", ">", "^" and "|" from method names since they are
369
- # lexed as simple tokens. This is because they have also other meanings in
370
- # Machette patterns beside Ruby method names.
371
- [
372
- :METHOD_NAME,
373
- /^
374
- (
375
- # regular name
376
- [a-z_][a-zA-Z0-9_]*[?!=]?
377
- |
378
- # operator (sorted by length, then alphabetically)
379
- (<=>|===|\[\]=|\*\*|\+@|-@|<<|<=|==|=~|>=|>>|\[\]|[%&\-\/`~])
380
- )
381
- /x
382
- ],
383
- [:CLASS_NAME, /^[A-Z][a-zA-Z0-9_]*/]
384
- ]
385
-
386
- def next_token
387
- skip_whitespace
388
-
389
- return false if remaining_input.empty?
390
-
391
- # Complex tokens need to be before simple tokens, otherwise e.g. "<<" would be
392
- # recognized as two tokens.
393
-
394
- COMPLEX_TOKENS.each do |type, regexp|
395
- if remaining_input =~ regexp
396
- @pos += $&.length
397
- return [type, $&]
398
- end
399
- end
400
-
401
- SIMPLE_TOKENS.each do |token|
402
- if remaining_input[0...token.length] == token
403
- @pos += token.length
404
- return [token, token]
405
- end
406
- end
407
-
408
- raise SyntaxError, "Unexpected character: #{remaining_input[0..0].inspect}."
409
- end
410
-
411
- def skip_whitespace
412
- if remaining_input =~ /\A^[ \t\r\n]+/
413
- @pos += $&.length
414
- end
415
- end
416
-
417
- def remaining_input
418
- @input[@pos..-1]
419
- end
420
-
421
- def on_error(error_token_id, error_value, value_stack)
422
- raise SyntaxError, "Unexpected token: #{error_value.inspect}."
423
- end