Class: Parse::RockitProductionsEvaluator
- Defined in:
- lib/rpdf2txt-rockit/rockit_grammar_ast_eval.rb
Instance Method Summary collapse
- #eval_ast(ast) ⇒ Object
-
#initialize(tokens = []) ⇒ RockitProductionsEvaluator
constructor
A new instance of RockitProductionsEvaluator.
Constructor Details
#initialize(tokens = []) ⇒ RockitProductionsEvaluator
Returns a new instance of RockitProductionsEvaluator.
120 121 122 123 |
# File 'lib/rpdf2txt-rockit/rockit_grammar_ast_eval.rb', line 120 def initialize(tokens = []) @token_map = Hash.new tokens.each {|token| @token_map[token.name] = token} end |
Instance Method Details
#eval_ast(ast) ⇒ Object
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) # Eval to String or Regexp 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 |