racc 1.4.14-java → 1.4.15-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.
- checksums.yaml +5 -5
- data/Manifest.txt +50 -0
- data/ext/racc/com/headius/racc/Cparse.java +66 -23
- data/ext/racc/cparse.c +1 -1
- data/ext/racc/depend +1 -1
- data/lib/racc/cparse-jruby.jar +0 -0
- data/lib/racc/info.rb +2 -2
- data/test/assets/bibtex.y +141 -0
- data/test/assets/cadenza.y +170 -0
- data/test/assets/cast.y +926 -0
- data/test/assets/csspool.y +729 -0
- data/test/assets/edtf.y +583 -0
- data/test/assets/huia.y +318 -0
- data/test/assets/journey.y +47 -0
- data/test/assets/liquor.y +313 -0
- data/test/assets/machete.y +423 -0
- data/test/assets/macruby.y +2197 -0
- data/test/assets/mediacloth.y +599 -0
- data/test/assets/mof.y +649 -0
- data/test/assets/namae.y +302 -0
- data/test/assets/nasl.y +626 -0
- data/test/assets/nokogiri-css.y +255 -0
- data/test/assets/opal.y +1807 -0
- data/test/assets/php_serialization.y +98 -0
- data/test/assets/rdblockparser.y +576 -0
- data/test/assets/rdinlineparser.y +561 -0
- data/test/assets/riml.y +665 -0
- data/test/assets/ruby18.y +1943 -0
- data/test/assets/ruby19.y +2174 -0
- data/test/assets/ruby20.y +2350 -0
- data/test/assets/ruby21.y +2359 -0
- data/test/assets/ruby22.y +2381 -0
- data/test/assets/tp_plus.y +622 -0
- data/test/assets/twowaysql.y +278 -0
- data/test/helper.rb +50 -34
- data/test/regress/bibtex +474 -0
- data/test/regress/cadenza +796 -0
- data/test/regress/cast +3425 -0
- data/test/regress/csspool +2318 -0
- data/test/regress/edtf +1794 -0
- data/test/regress/huia +1392 -0
- data/test/regress/journey +222 -0
- data/test/regress/liquor +885 -0
- data/test/regress/machete +833 -0
- data/test/regress/mediacloth +1463 -0
- data/test/regress/mof +1368 -0
- data/test/regress/namae +634 -0
- data/test/regress/nasl +2058 -0
- data/test/regress/nokogiri-css +836 -0
- data/test/regress/opal +6429 -0
- data/test/regress/php_serialization +336 -0
- data/test/regress/rdblockparser +1061 -0
- data/test/regress/rdinlineparser +1243 -0
- data/test/regress/riml +3297 -0
- data/test/regress/ruby18 +6351 -0
- data/test/regress/ruby22 +7456 -0
- data/test/regress/tp_plus +1933 -0
- data/test/regress/twowaysql +556 -0
- data/test/test_racc_command.rb +177 -0
- metadata +80 -25
- data/.gemtest +0 -0
@@ -0,0 +1,278 @@
|
|
1
|
+
# Copyright 2008-2015 Takuto Wada
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
class TwoWaySQL::Parser
|
16
|
+
|
17
|
+
rule
|
18
|
+
|
19
|
+
sql : stmt_list
|
20
|
+
{
|
21
|
+
result = RootNode.new( val[0] )
|
22
|
+
}
|
23
|
+
|
24
|
+
stmt_list :
|
25
|
+
{
|
26
|
+
result = []
|
27
|
+
}
|
28
|
+
| stmt_list stmt
|
29
|
+
{
|
30
|
+
result.push val[1]
|
31
|
+
}
|
32
|
+
|
33
|
+
stmt : primary
|
34
|
+
| if_stmt
|
35
|
+
| begin_stmt
|
36
|
+
|
37
|
+
begin_stmt : BEGIN stmt_list END
|
38
|
+
{
|
39
|
+
result = BeginNode.new( val[1] )
|
40
|
+
}
|
41
|
+
|
42
|
+
if_stmt : IF sub_stmt else_stmt END
|
43
|
+
{
|
44
|
+
result = IfNode.new( val[0][1], val[1], val[2] )
|
45
|
+
}
|
46
|
+
|
47
|
+
else_stmt : ELSE sub_stmt
|
48
|
+
{
|
49
|
+
result = val[1]
|
50
|
+
}
|
51
|
+
|
|
52
|
+
{
|
53
|
+
result = nil
|
54
|
+
}
|
55
|
+
|
56
|
+
sub_stmt : and_stmt
|
57
|
+
| or_stmt
|
58
|
+
| stmt_list
|
59
|
+
|
60
|
+
and_stmt : AND stmt_list
|
61
|
+
{
|
62
|
+
result = SubStatementNode.new( val[0][1], val[1] )
|
63
|
+
}
|
64
|
+
|
65
|
+
or_stmt : OR stmt_list
|
66
|
+
{
|
67
|
+
result = SubStatementNode.new( val[0][1], val[1] )
|
68
|
+
}
|
69
|
+
|
70
|
+
primary : IDENT
|
71
|
+
{
|
72
|
+
result = LiteralNode.new( val[0][1] )
|
73
|
+
}
|
74
|
+
| STRING_LITERAL
|
75
|
+
{
|
76
|
+
result = LiteralNode.new( val[0][1] )
|
77
|
+
}
|
78
|
+
| AND
|
79
|
+
{
|
80
|
+
result = LiteralNode.new( val[0][1] )
|
81
|
+
}
|
82
|
+
| OR
|
83
|
+
{
|
84
|
+
result = LiteralNode.new( val[0][1] )
|
85
|
+
}
|
86
|
+
| SPACES
|
87
|
+
{
|
88
|
+
result = WhiteSpaceNode.new( val[0][1], @preserve_space )
|
89
|
+
}
|
90
|
+
| COMMA
|
91
|
+
{
|
92
|
+
result = LiteralNode.new( val[0][1] )
|
93
|
+
}
|
94
|
+
| LPAREN
|
95
|
+
{
|
96
|
+
result = LiteralNode.new( val[0][1] )
|
97
|
+
}
|
98
|
+
| RPAREN
|
99
|
+
{
|
100
|
+
result = LiteralNode.new( val[0][1] )
|
101
|
+
}
|
102
|
+
| QUESTION
|
103
|
+
{
|
104
|
+
@num_questions += 1
|
105
|
+
result = QuestionNode.new( @num_questions )
|
106
|
+
}
|
107
|
+
| ACTUAL_COMMENT
|
108
|
+
{
|
109
|
+
result = ActualCommentNode.new( val[0][1] , val[0][2] )
|
110
|
+
}
|
111
|
+
| bind_var
|
112
|
+
| embed_var
|
113
|
+
|
114
|
+
bind_var : BIND_VARIABLE STRING_LITERAL
|
115
|
+
{
|
116
|
+
result = BindVariableNode.new( val[0][1] )
|
117
|
+
}
|
118
|
+
| BIND_VARIABLE SPACES STRING_LITERAL
|
119
|
+
{
|
120
|
+
result = BindVariableNode.new( val[0][1] )
|
121
|
+
}
|
122
|
+
| BIND_VARIABLE IDENT
|
123
|
+
{
|
124
|
+
result = BindVariableNode.new( val[0][1] )
|
125
|
+
}
|
126
|
+
| BIND_VARIABLE SPACES IDENT
|
127
|
+
{
|
128
|
+
result = BindVariableNode.new( val[0][1] )
|
129
|
+
}
|
130
|
+
| PAREN_BIND_VARIABLE
|
131
|
+
{
|
132
|
+
result = ParenBindVariableNode.new( val[0][1] )
|
133
|
+
}
|
134
|
+
|
135
|
+
embed_var : EMBED_VARIABLE IDENT
|
136
|
+
{
|
137
|
+
result = EmbedVariableNode.new( val[0][1] )
|
138
|
+
}
|
139
|
+
| EMBED_VARIABLE SPACES IDENT
|
140
|
+
{
|
141
|
+
result = EmbedVariableNode.new( val[0][1] )
|
142
|
+
}
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
---- inner
|
148
|
+
|
149
|
+
require 'strscan'
|
150
|
+
|
151
|
+
def initialize(opts={})
|
152
|
+
opts = {
|
153
|
+
:debug => false,
|
154
|
+
:preserve_space => true,
|
155
|
+
:preserve_comment => false
|
156
|
+
}.merge(opts)
|
157
|
+
@yydebug = opts[:debug]
|
158
|
+
@preserve_space = opts[:preserve_space]
|
159
|
+
@preserve_comment = opts[:preserve_comment]
|
160
|
+
@num_questions = 0
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
PAREN_EXAMPLE = '\([^\)]+\)'
|
165
|
+
BEGIN_BIND_VARIABLE = '(\/|\#)\*([^\*]+)\*\1'
|
166
|
+
BIND_VARIABLE_PATTERN = /\A#{BEGIN_BIND_VARIABLE}\s*/
|
167
|
+
PAREN_BIND_VARIABLE_PATTERN = /\A#{BEGIN_BIND_VARIABLE}\s*#{PAREN_EXAMPLE}/
|
168
|
+
EMBED_VARIABLE_PATTERN = /\A(\/|\#)\*\$([^\*]+)\*\1\s*/
|
169
|
+
|
170
|
+
CONDITIONAL_PATTERN = /\A(\/|\#)\*(IF)\s+([^\*]+)\s*\*\1/
|
171
|
+
BEGIN_END_PATTERN = /\A(\/|\#)\*(BEGIN|END)\s*\*\1/
|
172
|
+
STRING_LITERAL_PATTERN = /\A(\'(?:[^\']+|\'\')*\')/ ## quoted string
|
173
|
+
SPLIT_TOKEN_PATTERN = /\A(\S+?)(?=\s*(?:(?:\/|\#)\*|-{2,}|\(|\)|\,))/ ## stop on delimiters --,/*,#*,',',(,)
|
174
|
+
LITERAL_PATTERN = /\A([^;\s]+)/
|
175
|
+
SPACES_PATTERN = /\A(\s+)/
|
176
|
+
QUESTION_PATTERN = /\A\?/
|
177
|
+
COMMA_PATTERN = /\A\,/
|
178
|
+
LPAREN_PATTERN = /\A\(/
|
179
|
+
RPAREN_PATTERN = /\A\)/
|
180
|
+
ACTUAL_COMMENT_PATTERN = /\A(\/|\#)\*(\s{1,}(?:.*?))\*\1/m ## start with spaces
|
181
|
+
SEMICOLON_AT_INPUT_END_PATTERN = /\A\;\s*\Z/
|
182
|
+
UNMATCHED_COMMENT_START_PATTERN = /\A(?:(?:\/|\#)\*)/
|
183
|
+
|
184
|
+
#TODO: remove trailing spaces for S2Dao compatibility, but this spec sometimes causes SQL bugs...
|
185
|
+
ELSE_PATTERN = /\A\-{2,}\s*ELSE\s*/
|
186
|
+
AND_PATTERN = /\A(\ *AND)\b/i
|
187
|
+
OR_PATTERN = /\A(\ *OR)\b/i
|
188
|
+
|
189
|
+
|
190
|
+
def parse( io )
|
191
|
+
@q = []
|
192
|
+
io.each_line(nil) do |whole|
|
193
|
+
@s = StringScanner.new(whole)
|
194
|
+
end
|
195
|
+
scan_str
|
196
|
+
|
197
|
+
# @q.push [ false, nil ]
|
198
|
+
@q.push [ false, [@s.pos, nil] ]
|
199
|
+
|
200
|
+
## call racc's private parse method
|
201
|
+
do_parse
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
## called by racc
|
206
|
+
def next_token
|
207
|
+
@q.shift
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
def scan_str
|
212
|
+
until @s.eos? do
|
213
|
+
case
|
214
|
+
when @s.scan(AND_PATTERN)
|
215
|
+
@q.push [ :AND, [@s.pos, @s[1]] ]
|
216
|
+
when @s.scan(OR_PATTERN)
|
217
|
+
@q.push [ :OR, [@s.pos, @s[1]] ]
|
218
|
+
when @s.scan(SPACES_PATTERN)
|
219
|
+
@q.push [ :SPACES, [@s.pos, @s[1]] ]
|
220
|
+
when @s.scan(QUESTION_PATTERN)
|
221
|
+
@q.push [ :QUESTION, [@s.pos, nil] ]
|
222
|
+
when @s.scan(COMMA_PATTERN)
|
223
|
+
@q.push [ :COMMA, [@s.pos, ','] ]
|
224
|
+
when @s.scan(LPAREN_PATTERN)
|
225
|
+
@q.push [ :LPAREN, [@s.pos, '('] ]
|
226
|
+
when @s.scan(RPAREN_PATTERN)
|
227
|
+
@q.push [ :RPAREN, [@s.pos, ')'] ]
|
228
|
+
when @s.scan(ELSE_PATTERN)
|
229
|
+
@q.push [ :ELSE, [@s.pos, nil] ]
|
230
|
+
when @s.scan(ACTUAL_COMMENT_PATTERN)
|
231
|
+
@q.push [ :ACTUAL_COMMENT, [@s.pos, @s[1], @s[2]] ] if @preserve_comment
|
232
|
+
when @s.scan(BEGIN_END_PATTERN)
|
233
|
+
@q.push [ @s[2].intern, [@s.pos, nil] ]
|
234
|
+
when @s.scan(CONDITIONAL_PATTERN)
|
235
|
+
@q.push [ @s[2].intern, [@s.pos, @s[3]] ]
|
236
|
+
when @s.scan(EMBED_VARIABLE_PATTERN)
|
237
|
+
@q.push [ :EMBED_VARIABLE, [@s.pos, @s[2]] ]
|
238
|
+
when @s.scan(PAREN_BIND_VARIABLE_PATTERN)
|
239
|
+
@q.push [ :PAREN_BIND_VARIABLE, [@s.pos, @s[2]] ]
|
240
|
+
when @s.scan(BIND_VARIABLE_PATTERN)
|
241
|
+
@q.push [ :BIND_VARIABLE, [@s.pos, @s[2]] ]
|
242
|
+
when @s.scan(STRING_LITERAL_PATTERN)
|
243
|
+
@q.push [ :STRING_LITERAL, [@s.pos, @s[1]] ]
|
244
|
+
when @s.scan(SPLIT_TOKEN_PATTERN)
|
245
|
+
@q.push [ :IDENT, [@s.pos, @s[1]] ]
|
246
|
+
when @s.scan(UNMATCHED_COMMENT_START_PATTERN) ## unmatched comment start, '/*','#*'
|
247
|
+
raise Racc::ParseError, "unmatched comment. line:[#{line_no(@s.pos)}], str:[#{@s.rest}]"
|
248
|
+
when @s.scan(LITERAL_PATTERN) ## other string token
|
249
|
+
@q.push [ :IDENT, [@s.pos, @s[1]] ]
|
250
|
+
when @s.scan(SEMICOLON_AT_INPUT_END_PATTERN)
|
251
|
+
#drop semicolon at input end
|
252
|
+
else
|
253
|
+
raise Racc::ParseError, "syntax error at or near line:[#{line_no(@s.pos)}], str:[#{@s.rest}]"
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
## override racc's default on_error method
|
260
|
+
def on_error(t, v, vstack)
|
261
|
+
## cursor in value-stack is an array of two items,
|
262
|
+
## that have position value as 0th item. like [731, "ctx[:limit] "]
|
263
|
+
cursor = vstack.find do |tokens|
|
264
|
+
tokens.size == 2 and tokens[0].kind_of?(Fixnum)
|
265
|
+
end
|
266
|
+
pos = cursor[0]
|
267
|
+
line = line_no(pos)
|
268
|
+
rest = @s.string[pos .. -1]
|
269
|
+
raise Racc::ParseError, "syntax error at or near line:[#{line}], str:[#{rest}]"
|
270
|
+
end
|
271
|
+
|
272
|
+
|
273
|
+
def line_no(pos)
|
274
|
+
lines = 0
|
275
|
+
scanned = @s.string[0..(pos)]
|
276
|
+
scanned.each_line { lines += 1 }
|
277
|
+
lines
|
278
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
$VERBOSE = true
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "racc/static"
|
4
|
+
require "fileutils"
|
5
|
+
require "tempfile"
|
6
|
+
require "timeout"
|
7
7
|
|
8
8
|
module Racc
|
9
9
|
class TestCase < MiniTest::Unit::TestCase
|
10
|
-
PROJECT_DIR = File.expand_path(File.join(File.dirname(__FILE__),
|
10
|
+
PROJECT_DIR = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
11
11
|
|
12
|
-
TEST_DIR = File.join(PROJECT_DIR,
|
12
|
+
TEST_DIR = File.join(PROJECT_DIR, "test")
|
13
13
|
|
14
|
-
RACC
|
15
|
-
OUT_DIR
|
16
|
-
TAB_DIR
|
17
|
-
LOG_DIR
|
18
|
-
ERR_DIR
|
19
|
-
ASSET_DIR = File.join(TEST_DIR,
|
14
|
+
RACC = File.join(PROJECT_DIR, "bin", "racc")
|
15
|
+
OUT_DIR = File.join(TEST_DIR, "out")
|
16
|
+
TAB_DIR = File.join(TEST_DIR, "tab") # generated parsers go here
|
17
|
+
LOG_DIR = File.join(TEST_DIR, "log")
|
18
|
+
ERR_DIR = File.join(TEST_DIR, "err")
|
19
|
+
ASSET_DIR = File.join(TEST_DIR, "assets") # test grammars
|
20
|
+
REGRESS_DIR = File.join(TEST_DIR, "regress") # known-good generated outputs
|
20
21
|
|
21
22
|
INC = [
|
22
|
-
File.join(PROJECT_DIR,
|
23
|
-
File.join(PROJECT_DIR,
|
24
|
-
].join(
|
23
|
+
File.join(PROJECT_DIR, "lib"),
|
24
|
+
File.join(PROJECT_DIR, "ext"),
|
25
|
+
].join(":")
|
25
26
|
|
26
27
|
def setup
|
27
28
|
[OUT_DIR, TAB_DIR, LOG_DIR, ERR_DIR].each do |dir|
|
@@ -35,21 +36,21 @@ module Racc
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
38
|
-
def assert_compile
|
39
|
-
|
39
|
+
def assert_compile(asset, args = [])
|
40
|
+
file = File.basename(asset, ".y")
|
40
41
|
args = ([args].flatten) + [
|
41
|
-
"#{ASSET_DIR}/#{
|
42
|
-
|
43
|
-
"-O#{OUT_DIR}/#{
|
44
|
-
"-o#{TAB_DIR}/#{
|
42
|
+
"#{ASSET_DIR}/#{file}.y",
|
43
|
+
"-Do",
|
44
|
+
"-O#{OUT_DIR}/#{file}",
|
45
|
+
"-o#{TAB_DIR}/#{file}",
|
45
46
|
]
|
46
|
-
racc "#{args.join(
|
47
|
+
racc "#{args.join(" ")}"
|
47
48
|
end
|
48
49
|
|
49
|
-
def assert_debugfile
|
50
|
-
|
50
|
+
def assert_debugfile(asset, ok)
|
51
|
+
file = File.basename(asset, ".y")
|
51
52
|
Dir.chdir(TEST_DIR) do
|
52
|
-
File.foreach("log/#{
|
53
|
+
File.foreach("log/#{file}.y") do |line|
|
53
54
|
line.strip!
|
54
55
|
case line
|
55
56
|
when /sr/ then assert_equal "sr#{ok[0]}", line
|
@@ -58,27 +59,42 @@ module Racc
|
|
58
59
|
when /ur/ then assert_equal "ur#{ok[3]}", line
|
59
60
|
when /ex/ then assert_equal "ex#{ok[4]}", line
|
60
61
|
else
|
61
|
-
raise TestFailed,
|
62
|
+
raise TestFailed, "racc outputs unknown debug report???"
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
67
|
-
def assert_exec
|
68
|
-
file = File.basename(
|
68
|
+
def assert_exec(asset)
|
69
|
+
file = File.basename(asset, ".y")
|
69
70
|
Dir.chdir(TEST_DIR) do
|
70
|
-
ruby("
|
71
|
+
ruby("#{TAB_DIR}/#{file}")
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
74
|
-
def
|
75
|
+
def strip_version(source)
|
76
|
+
source.sub(/This file is automatically generated by Racc \d+\.\d+\.\d+/, "")
|
77
|
+
end
|
78
|
+
|
79
|
+
def assert_output_unchanged(asset)
|
80
|
+
file = File.basename(asset, ".y")
|
81
|
+
|
82
|
+
expected = File.read("#{REGRESS_DIR}/#{file}")
|
83
|
+
actual = File.read("#{TAB_DIR}/#{file}")
|
84
|
+
result = (strip_version(expected) == strip_version(actual))
|
85
|
+
|
86
|
+
assert(result, "Output of test/assets/#{file}.y differed from " \
|
87
|
+
"expectation. Try compiling it and diff with test/regress/#{file}.")
|
88
|
+
end
|
89
|
+
|
90
|
+
def racc(arg)
|
75
91
|
ruby "-S #{RACC} #{arg}"
|
76
92
|
end
|
77
93
|
|
78
|
-
def ruby
|
94
|
+
def ruby(arg)
|
79
95
|
Dir.chdir(TEST_DIR) do
|
80
|
-
Tempfile.open
|
81
|
-
cmd = "#{ENV[
|
96
|
+
Tempfile.open "test" do |io|
|
97
|
+
cmd = "#{ENV["_"] || Gem.ruby} -I #{INC} #{arg} 2>#{io.path}"
|
82
98
|
result = system(cmd)
|
83
99
|
assert(result, io.read)
|
84
100
|
end
|
data/test/regress/bibtex
ADDED
@@ -0,0 +1,474 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.14
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
require 'bibtex/lexer'
|
10
|
+
|
11
|
+
module BibTeX
|
12
|
+
class Parser < Racc::Parser
|
13
|
+
|
14
|
+
module_eval(<<'...end bibtex.y/module_eval...', 'bibtex.y', 89)
|
15
|
+
|
16
|
+
attr_reader :lexer, :options
|
17
|
+
|
18
|
+
@defaults = {
|
19
|
+
:include => [:errors],
|
20
|
+
:allow_missing_keys => false,
|
21
|
+
:debug => false
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
class << self
|
25
|
+
attr_reader :defaults
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(options = {})
|
29
|
+
@options = Parser.defaults.merge(options)
|
30
|
+
@lexer = Lexer.new(@options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse(input)
|
34
|
+
@yydebug = debug?
|
35
|
+
|
36
|
+
lexer.analyse(input)
|
37
|
+
do_parse
|
38
|
+
#yyparse(@lexer,:each)
|
39
|
+
end
|
40
|
+
|
41
|
+
def next_token
|
42
|
+
lexer.next_token
|
43
|
+
end
|
44
|
+
|
45
|
+
def debug?
|
46
|
+
options[:debug] || ENV['DEBUG']
|
47
|
+
end
|
48
|
+
|
49
|
+
def allow_missing_keys?
|
50
|
+
options[:allow_missing_keys]
|
51
|
+
end
|
52
|
+
|
53
|
+
def missing_key
|
54
|
+
unless allow_missing_keys?
|
55
|
+
raise ParseError, "Failed to parse BibTeX entry: cite-key missing"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def on_error(tid, val, vstack)
|
60
|
+
message =
|
61
|
+
"Failed to parse BibTeX on value #{val.inspect} (#{token_to_str(tid) || '?'}) #{ vstack.inspect}"
|
62
|
+
|
63
|
+
BibTeX.log.error message
|
64
|
+
raise ParseError, message
|
65
|
+
end
|
66
|
+
|
67
|
+
# -*- racc -*-
|
68
|
+
...end bibtex.y/module_eval...
|
69
|
+
##### State transition tables begin ###
|
70
|
+
|
71
|
+
racc_action_table = [
|
72
|
+
14, 33, 38, 26, 32, 33, 48, 18, 32, 15,
|
73
|
+
34, 42, 16, 37, 34, 33, 33, 29, 32, 32,
|
74
|
+
52, 46, 4, 4, 34, 34, 6, 6, 26, 5,
|
75
|
+
5, 24, 43, 44, 47, 54, 44, 44, 7, 19,
|
76
|
+
20, 21, 22, 27, 29, 36, 39, 41 ]
|
77
|
+
|
78
|
+
racc_action_check = [
|
79
|
+
4, 44, 23, 38, 44, 21, 38, 4, 21, 4,
|
80
|
+
44, 28, 4, 23, 21, 47, 39, 33, 47, 39,
|
81
|
+
39, 35, 0, 2, 47, 39, 0, 2, 17, 0,
|
82
|
+
2, 17, 30, 30, 36, 45, 50, 55, 1, 7,
|
83
|
+
14, 15, 16, 18, 20, 22, 26, 27 ]
|
84
|
+
|
85
|
+
racc_action_pointer = [
|
86
|
+
20, 38, 21, nil, -4, nil, nil, 39, nil, nil,
|
87
|
+
nil, nil, nil, nil, 32, 33, 34, 17, 35, nil,
|
88
|
+
39, -3, 34, -1, nil, nil, 39, 37, -3, nil,
|
89
|
+
18, nil, nil, 12, nil, 7, 27, nil, -8, 8,
|
90
|
+
nil, nil, nil, nil, -7, 21, nil, 7, nil, nil,
|
91
|
+
21, nil, nil, nil, nil, 22 ]
|
92
|
+
|
93
|
+
racc_action_default = [
|
94
|
+
-1, -34, -2, -3, -34, -6, -7, -34, -4, -5,
|
95
|
+
-8, -9, -10, -11, -34, -34, -34, -34, -34, 56,
|
96
|
+
-13, -34, -34, -34, -25, -29, -34, -27, -34, -14,
|
97
|
+
-34, -18, -20, -13, -22, -34, -34, -23, -34, -34,
|
98
|
+
-26, -28, -12, -15, -34, -34, -16, -34, -24, -30,
|
99
|
+
-32, -31, -33, -19, -21, -17 ]
|
100
|
+
|
101
|
+
racc_goto_table = [
|
102
|
+
30, 25, 28, 3, 11, 8, 12, 13, 35, 53,
|
103
|
+
17, 23, 40, 1, 51, 45, 2, 9, 50, 10,
|
104
|
+
nil, nil, 49, nil, nil, nil, 55 ]
|
105
|
+
|
106
|
+
racc_goto_check = [
|
107
|
+
10, 16, 9, 3, 6, 3, 7, 8, 11, 12,
|
108
|
+
13, 14, 15, 1, 17, 9, 2, 4, 10, 5,
|
109
|
+
nil, nil, 16, nil, nil, nil, 10 ]
|
110
|
+
|
111
|
+
racc_goto_pointer = [
|
112
|
+
nil, 13, 16, 3, 13, 15, 0, 2, 3, -18,
|
113
|
+
-21, -14, -35, 6, -6, -15, -16, -25 ]
|
114
|
+
|
115
|
+
racc_goto_default = [
|
116
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
117
|
+
nil, nil, 31, nil, nil, nil, nil, nil ]
|
118
|
+
|
119
|
+
racc_reduce_table = [
|
120
|
+
0, 0, :racc_error,
|
121
|
+
0, 19, :_reduce_1,
|
122
|
+
1, 19, :_reduce_2,
|
123
|
+
1, 20, :_reduce_3,
|
124
|
+
2, 20, :_reduce_4,
|
125
|
+
2, 21, :_reduce_5,
|
126
|
+
1, 21, :_reduce_6,
|
127
|
+
1, 21, :_reduce_7,
|
128
|
+
1, 22, :_reduce_8,
|
129
|
+
1, 22, :_reduce_9,
|
130
|
+
1, 22, :_reduce_10,
|
131
|
+
1, 22, :_reduce_11,
|
132
|
+
4, 23, :_reduce_12,
|
133
|
+
0, 27, :_reduce_13,
|
134
|
+
1, 27, :_reduce_14,
|
135
|
+
4, 25, :_reduce_15,
|
136
|
+
4, 24, :_reduce_16,
|
137
|
+
3, 29, :_reduce_17,
|
138
|
+
1, 28, :_reduce_18,
|
139
|
+
3, 28, :_reduce_19,
|
140
|
+
1, 30, :_reduce_20,
|
141
|
+
3, 30, :_reduce_21,
|
142
|
+
1, 30, :_reduce_22,
|
143
|
+
3, 26, :_reduce_23,
|
144
|
+
4, 26, :_reduce_24,
|
145
|
+
2, 26, :_reduce_25,
|
146
|
+
3, 31, :_reduce_26,
|
147
|
+
0, 33, :_reduce_27,
|
148
|
+
1, 33, :_reduce_none,
|
149
|
+
1, 32, :_reduce_29,
|
150
|
+
3, 32, :_reduce_30,
|
151
|
+
3, 34, :_reduce_31,
|
152
|
+
1, 35, :_reduce_32,
|
153
|
+
1, 35, :_reduce_33 ]
|
154
|
+
|
155
|
+
racc_reduce_n = 34
|
156
|
+
|
157
|
+
racc_shift_n = 56
|
158
|
+
|
159
|
+
racc_token_table = {
|
160
|
+
false => 0,
|
161
|
+
:error => 1,
|
162
|
+
:AT => 2,
|
163
|
+
:COMMA => 3,
|
164
|
+
:COMMENT => 4,
|
165
|
+
:CONTENT => 5,
|
166
|
+
:ERROR => 6,
|
167
|
+
:EQ => 7,
|
168
|
+
:LBRACE => 8,
|
169
|
+
:META_CONTENT => 9,
|
170
|
+
:KEY => 10,
|
171
|
+
:NAME => 11,
|
172
|
+
:NUMBER => 12,
|
173
|
+
:PREAMBLE => 13,
|
174
|
+
:RBRACE => 14,
|
175
|
+
:SHARP => 15,
|
176
|
+
:STRING => 16,
|
177
|
+
:STRING_LITERAL => 17 }
|
178
|
+
|
179
|
+
racc_nt_base = 18
|
180
|
+
|
181
|
+
racc_use_result_var = true
|
182
|
+
|
183
|
+
Racc_arg = [
|
184
|
+
racc_action_table,
|
185
|
+
racc_action_check,
|
186
|
+
racc_action_default,
|
187
|
+
racc_action_pointer,
|
188
|
+
racc_goto_table,
|
189
|
+
racc_goto_check,
|
190
|
+
racc_goto_default,
|
191
|
+
racc_goto_pointer,
|
192
|
+
racc_nt_base,
|
193
|
+
racc_reduce_table,
|
194
|
+
racc_token_table,
|
195
|
+
racc_shift_n,
|
196
|
+
racc_reduce_n,
|
197
|
+
racc_use_result_var ]
|
198
|
+
|
199
|
+
Racc_token_to_s_table = [
|
200
|
+
"$end",
|
201
|
+
"error",
|
202
|
+
"AT",
|
203
|
+
"COMMA",
|
204
|
+
"COMMENT",
|
205
|
+
"CONTENT",
|
206
|
+
"ERROR",
|
207
|
+
"EQ",
|
208
|
+
"LBRACE",
|
209
|
+
"META_CONTENT",
|
210
|
+
"KEY",
|
211
|
+
"NAME",
|
212
|
+
"NUMBER",
|
213
|
+
"PREAMBLE",
|
214
|
+
"RBRACE",
|
215
|
+
"SHARP",
|
216
|
+
"STRING",
|
217
|
+
"STRING_LITERAL",
|
218
|
+
"$start",
|
219
|
+
"bibliography",
|
220
|
+
"objects",
|
221
|
+
"object",
|
222
|
+
"at_object",
|
223
|
+
"comment",
|
224
|
+
"string",
|
225
|
+
"preamble",
|
226
|
+
"entry",
|
227
|
+
"content",
|
228
|
+
"string_value",
|
229
|
+
"string_assignment",
|
230
|
+
"string_literal",
|
231
|
+
"entry_head",
|
232
|
+
"assignments",
|
233
|
+
"opt_key",
|
234
|
+
"assignment",
|
235
|
+
"value" ]
|
236
|
+
|
237
|
+
Racc_debug_parser = false
|
238
|
+
|
239
|
+
##### State transition tables end #####
|
240
|
+
|
241
|
+
# reduce 0 omitted
|
242
|
+
|
243
|
+
module_eval(<<'.,.,', 'bibtex.y', 32)
|
244
|
+
def _reduce_1(val, _values, result)
|
245
|
+
result = BibTeX::Bibliography.new(@options)
|
246
|
+
result
|
247
|
+
end
|
248
|
+
.,.,
|
249
|
+
|
250
|
+
module_eval(<<'.,.,', 'bibtex.y', 33)
|
251
|
+
def _reduce_2(val, _values, result)
|
252
|
+
result = val[0]
|
253
|
+
result
|
254
|
+
end
|
255
|
+
.,.,
|
256
|
+
|
257
|
+
module_eval(<<'.,.,', 'bibtex.y', 35)
|
258
|
+
def _reduce_3(val, _values, result)
|
259
|
+
result = BibTeX::Bibliography.new(@options) << val[0]
|
260
|
+
result
|
261
|
+
end
|
262
|
+
.,.,
|
263
|
+
|
264
|
+
module_eval(<<'.,.,', 'bibtex.y', 36)
|
265
|
+
def _reduce_4(val, _values, result)
|
266
|
+
result << val[1]
|
267
|
+
result
|
268
|
+
end
|
269
|
+
.,.,
|
270
|
+
|
271
|
+
module_eval(<<'.,.,', 'bibtex.y', 38)
|
272
|
+
def _reduce_5(val, _values, result)
|
273
|
+
result = val[1]
|
274
|
+
result
|
275
|
+
end
|
276
|
+
.,.,
|
277
|
+
|
278
|
+
module_eval(<<'.,.,', 'bibtex.y', 39)
|
279
|
+
def _reduce_6(val, _values, result)
|
280
|
+
result = BibTeX::MetaContent.new(val[0])
|
281
|
+
result
|
282
|
+
end
|
283
|
+
.,.,
|
284
|
+
|
285
|
+
module_eval(<<'.,.,', 'bibtex.y', 40)
|
286
|
+
def _reduce_7(val, _values, result)
|
287
|
+
result = BibTeX::Error.new(val[0])
|
288
|
+
result
|
289
|
+
end
|
290
|
+
.,.,
|
291
|
+
|
292
|
+
module_eval(<<'.,.,', 'bibtex.y', 42)
|
293
|
+
def _reduce_8(val, _values, result)
|
294
|
+
result = val[0]
|
295
|
+
result
|
296
|
+
end
|
297
|
+
.,.,
|
298
|
+
|
299
|
+
module_eval(<<'.,.,', 'bibtex.y', 43)
|
300
|
+
def _reduce_9(val, _values, result)
|
301
|
+
result = val[0]
|
302
|
+
result
|
303
|
+
end
|
304
|
+
.,.,
|
305
|
+
|
306
|
+
module_eval(<<'.,.,', 'bibtex.y', 44)
|
307
|
+
def _reduce_10(val, _values, result)
|
308
|
+
result = val[0]
|
309
|
+
result
|
310
|
+
end
|
311
|
+
.,.,
|
312
|
+
|
313
|
+
module_eval(<<'.,.,', 'bibtex.y', 45)
|
314
|
+
def _reduce_11(val, _values, result)
|
315
|
+
result = val[0]
|
316
|
+
result
|
317
|
+
end
|
318
|
+
.,.,
|
319
|
+
|
320
|
+
module_eval(<<'.,.,', 'bibtex.y', 47)
|
321
|
+
def _reduce_12(val, _values, result)
|
322
|
+
result = BibTeX::Comment.new(val[2])
|
323
|
+
result
|
324
|
+
end
|
325
|
+
.,.,
|
326
|
+
|
327
|
+
module_eval(<<'.,.,', 'bibtex.y', 49)
|
328
|
+
def _reduce_13(val, _values, result)
|
329
|
+
result = ''
|
330
|
+
result
|
331
|
+
end
|
332
|
+
.,.,
|
333
|
+
|
334
|
+
module_eval(<<'.,.,', 'bibtex.y', 50)
|
335
|
+
def _reduce_14(val, _values, result)
|
336
|
+
result = val[0]
|
337
|
+
result
|
338
|
+
end
|
339
|
+
.,.,
|
340
|
+
|
341
|
+
module_eval(<<'.,.,', 'bibtex.y', 52)
|
342
|
+
def _reduce_15(val, _values, result)
|
343
|
+
result = BibTeX::Preamble.new(val[2])
|
344
|
+
result
|
345
|
+
end
|
346
|
+
.,.,
|
347
|
+
|
348
|
+
module_eval(<<'.,.,', 'bibtex.y', 54)
|
349
|
+
def _reduce_16(val, _values, result)
|
350
|
+
result = BibTeX::String.new(val[2][0],val[2][1]);
|
351
|
+
result
|
352
|
+
end
|
353
|
+
.,.,
|
354
|
+
|
355
|
+
module_eval(<<'.,.,', 'bibtex.y', 56)
|
356
|
+
def _reduce_17(val, _values, result)
|
357
|
+
result = [val[0].downcase.to_sym, val[2]]
|
358
|
+
result
|
359
|
+
end
|
360
|
+
.,.,
|
361
|
+
|
362
|
+
module_eval(<<'.,.,', 'bibtex.y', 58)
|
363
|
+
def _reduce_18(val, _values, result)
|
364
|
+
result = [val[0]]
|
365
|
+
result
|
366
|
+
end
|
367
|
+
.,.,
|
368
|
+
|
369
|
+
module_eval(<<'.,.,', 'bibtex.y', 59)
|
370
|
+
def _reduce_19(val, _values, result)
|
371
|
+
result << val[2]
|
372
|
+
result
|
373
|
+
end
|
374
|
+
.,.,
|
375
|
+
|
376
|
+
module_eval(<<'.,.,', 'bibtex.y', 61)
|
377
|
+
def _reduce_20(val, _values, result)
|
378
|
+
result = val[0].downcase.to_sym
|
379
|
+
result
|
380
|
+
end
|
381
|
+
.,.,
|
382
|
+
|
383
|
+
module_eval(<<'.,.,', 'bibtex.y', 62)
|
384
|
+
def _reduce_21(val, _values, result)
|
385
|
+
result = val[1]
|
386
|
+
result
|
387
|
+
end
|
388
|
+
.,.,
|
389
|
+
|
390
|
+
module_eval(<<'.,.,', 'bibtex.y', 63)
|
391
|
+
def _reduce_22(val, _values, result)
|
392
|
+
result = val[0]
|
393
|
+
result
|
394
|
+
end
|
395
|
+
.,.,
|
396
|
+
|
397
|
+
module_eval(<<'.,.,', 'bibtex.y', 65)
|
398
|
+
def _reduce_23(val, _values, result)
|
399
|
+
result = val[0] << val[1]
|
400
|
+
result
|
401
|
+
end
|
402
|
+
.,.,
|
403
|
+
|
404
|
+
module_eval(<<'.,.,', 'bibtex.y', 66)
|
405
|
+
def _reduce_24(val, _values, result)
|
406
|
+
result = val[0] << val[1]
|
407
|
+
result
|
408
|
+
end
|
409
|
+
.,.,
|
410
|
+
|
411
|
+
module_eval(<<'.,.,', 'bibtex.y', 67)
|
412
|
+
def _reduce_25(val, _values, result)
|
413
|
+
result = val[0]
|
414
|
+
result
|
415
|
+
end
|
416
|
+
.,.,
|
417
|
+
|
418
|
+
module_eval(<<'.,.,', 'bibtex.y', 69)
|
419
|
+
def _reduce_26(val, _values, result)
|
420
|
+
result = BibTeX::Entry.new(:bibtex_type => val[0].downcase.to_sym, :bibtex_key => val[2])
|
421
|
+
result
|
422
|
+
end
|
423
|
+
.,.,
|
424
|
+
|
425
|
+
module_eval(<<'.,.,', 'bibtex.y', 71)
|
426
|
+
def _reduce_27(val, _values, result)
|
427
|
+
missing_key
|
428
|
+
result
|
429
|
+
end
|
430
|
+
.,.,
|
431
|
+
|
432
|
+
# reduce 28 omitted
|
433
|
+
|
434
|
+
module_eval(<<'.,.,', 'bibtex.y', 74)
|
435
|
+
def _reduce_29(val, _values, result)
|
436
|
+
result = val[0]
|
437
|
+
result
|
438
|
+
end
|
439
|
+
.,.,
|
440
|
+
|
441
|
+
module_eval(<<'.,.,', 'bibtex.y', 75)
|
442
|
+
def _reduce_30(val, _values, result)
|
443
|
+
result.merge!(val[2])
|
444
|
+
result
|
445
|
+
end
|
446
|
+
.,.,
|
447
|
+
|
448
|
+
module_eval(<<'.,.,', 'bibtex.y', 77)
|
449
|
+
def _reduce_31(val, _values, result)
|
450
|
+
result = { val[0].downcase.to_sym => val[2] }
|
451
|
+
result
|
452
|
+
end
|
453
|
+
.,.,
|
454
|
+
|
455
|
+
module_eval(<<'.,.,', 'bibtex.y', 79)
|
456
|
+
def _reduce_32(val, _values, result)
|
457
|
+
result = val[0]
|
458
|
+
result
|
459
|
+
end
|
460
|
+
.,.,
|
461
|
+
|
462
|
+
module_eval(<<'.,.,', 'bibtex.y', 80)
|
463
|
+
def _reduce_33(val, _values, result)
|
464
|
+
result = val[0]
|
465
|
+
result
|
466
|
+
end
|
467
|
+
.,.,
|
468
|
+
|
469
|
+
def _reduce_none(val, _values, result)
|
470
|
+
val[0]
|
471
|
+
end
|
472
|
+
|
473
|
+
end # class Parser
|
474
|
+
end # module BibTeX
|