125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/rpdf2txt-rockit/rockit_grammar_ast_eval.rb', line 125
def eval_ast(ast)
return nil unless ast
case ast.name
when "Productions"
ast.productions.map {|prod| eval_ast(prod)}.flatten
when "Prod"
nonterminal = eval_ast(ast.nonterminal)
ast.alts.map do |alt|
elements, treespec = eval_ast(alt)
prod(nonterminal, elements, treespec)
end
when "Alt"
[ast.elements.map {|e| eval_ast(e)},
eval_ast(ast.astspec)]
when "SymbolName"
symbol = ast.lexeme
@token_map[symbol] || symbol.intern
when "ImplicitToken"
eval(ast.regexp.lexeme)
when "Maybe"
maybe(eval_ast(ast.element))
when "Plus"
plus(eval_ast(ast.element))
when "Mult"
mult(eval_ast(ast.element))
when "Or"
ore(*(ast.elements.map {|e| eval_ast(e)}))
when "Sequence"
ast.elements.map {|e| eval_ast(e)}
when "List"
liste(eval_ast(ast.element), eval_ast(ast.delimiter))
when "AstSpec"
if ast.elemspecs
elemspecs = ast.elemspecs.map {|e| e.lexeme.intern}
else
elemspecs = []
end
if ast.prodspec
prodspec = (ast.prodspec.lexeme == "^" ? :^ :eval_ast(ast.prodspec))
else
prodspec = nil
end
stb(prodspec, elemspecs)
when "Lift"
:^
end
end
|