lib/rley/engine.rb in rley-0.6.03 vs lib/rley/engine.rb in rley-0.6.04
- old
+ new
@@ -3,34 +3,41 @@
require_relative './parse_rep/parse_tree_factory'
module Rley # This module is used as a namespace
EngineConfig = Struct.new(
:parse_repr,
- :repr_builder
+ :repr_builder,
+ :diagnose
) do
def initialize()
super()
self.parse_repr = :parse_tree
self.repr_builder = :default
+ self.diagnose = false
end
end
# Implementation of the GoF Facade design pattern.
# an Engine object provides a higher-level interface that shields
# Rley client code from the lower-level classes.
class Engine
+ # @!attribute [r] configuration
+ # @return [EngineConfig] the engine's configuration
attr_reader :configuration
+
+ # @!attribute [r] grammar
+ # @return [Rley::Syntax::Grammar] the grammar of the language to parse
attr_reader :grammar
# Constructor.
def initialize()
@configuration = EngineConfig.new
yield configuration if block_given?
end
# Factory method.
- # @param &aBlock [Proc, Lambda] Code block for creating the grammar.
+ # @param aBlock [Proc, Lambda] Code block for creating the grammar.
def build_grammar(&aBlock)
builder = Rley::Syntax::GrammarBuilder.new(&aBlock)
@grammar = builder.grammar
end
@@ -51,9 +58,10 @@
term_symb = grammar.name2symbol[term_name]
a_token.instance_variable_set(:@terminal, term_symb)
tokens << a_token
end
parser = build_parser(grammar)
+ parser.gf_graph.diagnose if configuration.diagnose
return parser.parse(tokens)
end
# Convert raw parse result into a more convenient representation
# (parse tree or parse forest) as specified by the configuration.