racc 1.5.2-java → 1.6.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.ja.rdoc +0 -1
  3. data/README.rdoc +9 -14
  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/cparse-jruby.jar +0 -0
  17. data/lib/racc/grammar.rb +3 -3
  18. data/lib/racc/grammarfileparser.rb +2 -2
  19. data/lib/racc/info.rb +1 -1
  20. data/lib/racc/parser-text.rb +2 -2
  21. data/lib/racc/parser.rb +2 -2
  22. data/lib/racc/parserfilegenerator.rb +0 -44
  23. data/lib/racc/statetransitiontable.rb +3 -9
  24. metadata +15 -121
  25. data/Rakefile +0 -79
  26. data/ext/racc/com/headius/racc/Cparse.java +0 -849
  27. data/lib/racc/pre-setup +0 -13
  28. data/sample/array.y +0 -67
  29. data/sample/array2.y +0 -59
  30. data/sample/calc-ja.y +0 -66
  31. data/sample/calc.y +0 -65
  32. data/sample/conflict.y +0 -15
  33. data/sample/hash.y +0 -60
  34. data/sample/lalr.y +0 -17
  35. data/sample/lists.y +0 -57
  36. data/sample/syntax.y +0 -46
  37. data/sample/yyerr.y +0 -46
  38. data/test/assets/cadenza.y +0 -170
  39. data/test/assets/cast.y +0 -926
  40. data/test/assets/chk.y +0 -126
  41. data/test/assets/conf.y +0 -16
  42. data/test/assets/csspool.y +0 -729
  43. data/test/assets/digraph.y +0 -29
  44. data/test/assets/echk.y +0 -118
  45. data/test/assets/edtf.y +0 -583
  46. data/test/assets/err.y +0 -60
  47. data/test/assets/error_recovery.y +0 -35
  48. data/test/assets/expect.y +0 -7
  49. data/test/assets/firstline.y +0 -4
  50. data/test/assets/huia.y +0 -318
  51. data/test/assets/ichk.y +0 -102
  52. data/test/assets/intp.y +0 -546
  53. data/test/assets/journey.y +0 -47
  54. data/test/assets/liquor.y +0 -313
  55. data/test/assets/machete.y +0 -423
  56. data/test/assets/macruby.y +0 -2197
  57. data/test/assets/mailp.y +0 -437
  58. data/test/assets/mediacloth.y +0 -599
  59. data/test/assets/mof.y +0 -649
  60. data/test/assets/namae.y +0 -302
  61. data/test/assets/nasl.y +0 -626
  62. data/test/assets/newsyn.y +0 -25
  63. data/test/assets/noend.y +0 -4
  64. data/test/assets/nokogiri-css.y +0 -255
  65. data/test/assets/nonass.y +0 -41
  66. data/test/assets/normal.y +0 -27
  67. data/test/assets/norule.y +0 -4
  68. data/test/assets/nullbug1.y +0 -25
  69. data/test/assets/nullbug2.y +0 -15
  70. data/test/assets/opal.y +0 -1807
  71. data/test/assets/opt.y +0 -123
  72. data/test/assets/percent.y +0 -35
  73. data/test/assets/php_serialization.y +0 -98
  74. data/test/assets/recv.y +0 -97
  75. data/test/assets/riml.y +0 -665
  76. data/test/assets/rrconf.y +0 -14
  77. data/test/assets/ruby18.y +0 -1943
  78. data/test/assets/ruby19.y +0 -2174
  79. data/test/assets/ruby20.y +0 -2350
  80. data/test/assets/ruby21.y +0 -2359
  81. data/test/assets/ruby22.y +0 -2381
  82. data/test/assets/scan.y +0 -72
  83. data/test/assets/syntax.y +0 -50
  84. data/test/assets/tp_plus.y +0 -622
  85. data/test/assets/twowaysql.y +0 -278
  86. data/test/assets/unterm.y +0 -5
  87. data/test/assets/useless.y +0 -12
  88. data/test/assets/yyerr.y +0 -46
  89. data/test/bench.y +0 -36
  90. data/test/helper.rb +0 -115
  91. data/test/infini.y +0 -8
  92. data/test/regress/cadenza +0 -796
  93. data/test/regress/cast +0 -3428
  94. data/test/regress/csspool +0 -2314
  95. data/test/regress/edtf +0 -1794
  96. data/test/regress/huia +0 -1392
  97. data/test/regress/journey +0 -222
  98. data/test/regress/liquor +0 -885
  99. data/test/regress/machete +0 -833
  100. data/test/regress/mediacloth +0 -1463
  101. data/test/regress/mof +0 -1368
  102. data/test/regress/namae +0 -634
  103. data/test/regress/nasl +0 -2058
  104. data/test/regress/nokogiri-css +0 -836
  105. data/test/regress/opal +0 -6431
  106. data/test/regress/php_serialization +0 -336
  107. data/test/regress/riml +0 -3283
  108. data/test/regress/ruby18 +0 -6344
  109. data/test/regress/ruby22 +0 -7460
  110. data/test/regress/tp_plus +0 -1933
  111. data/test/regress/twowaysql +0 -556
  112. data/test/scandata/brace +0 -7
  113. data/test/scandata/gvar +0 -1
  114. data/test/scandata/normal +0 -4
  115. data/test/scandata/percent +0 -18
  116. data/test/scandata/slash +0 -10
  117. data/test/src.intp +0 -34
  118. data/test/start.y +0 -20
  119. data/test/test_chk_y.rb +0 -52
  120. data/test/test_grammar_file_parser.rb +0 -15
  121. data/test/test_racc_command.rb +0 -339
  122. data/test/test_scan_y.rb +0 -52
  123. data/test/testscanner.rb +0 -51
  124. data/web/racc.en.rhtml +0 -42
  125. 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