lib/rley/engine.rb in rley-0.7.07 vs lib/rley/engine.rb in rley-0.7.08

- old
+ new

@@ -13,19 +13,18 @@ # @!attribute [r] parse_repr # Indicates how the parse result must represented # @return [Symbol] allowed values are: :parse_tree, :parse_forest :parse_repr, :repr_builder, - :diagnose - ) do - # Constructor with default initialization. - def initialize() - super() - self.parse_repr = :parse_tree - self.repr_builder = :default - self.diagnose = false - end + :diagnose) do + # Constructor with default initialization. + 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. @@ -41,11 +40,11 @@ # Constructor. # @example Produce a parse forest # Engine.new do |config| # config.parse_repr = :parse_forest # end - def initialize() + def initialize @configuration = EngineConfig.new yield configuration if block_given? end # Factory method. @@ -89,26 +88,24 @@ parser = build_parser(grammar) parser.gf_graph.diagnose if configuration.diagnose result = parser.parse(tokens) result.tidy_up! - return result + result end # Convert raw parse result into a more convenient representation # (parse tree or parse forest) as specified by the configuration. # @param aRawParse [Parser::GFGParsing] # @return [Rley::PTree::ParseTree, Rley::SPPF::ParseForest] def convert(aRawParse) - result = case configuration.parse_repr - when :parse_tree - to_ptree(aRawParse) - when :parse_forest - to_pforest(aRawParse) - end - - return result + case configuration.parse_repr + when :parse_tree + to_ptree(aRawParse) + when :parse_forest + to_pforest(aRawParse) + end end # Convert raw parse result into a parse tree representation # @param aRawParse [Parser::GFGParsing] # @return [Rley::PTree::ParseTree] @@ -118,11 +115,11 @@ result = factory.create(nil) else result = factory.create(configuration.repr_builder) end - return result + result end # Convert raw parse result into a parse forest representation # @param aRawParse [Parser::GFGParsing] # @return [Rley::SPPF::ParseForest] @@ -132,11 +129,11 @@ result = factory.create(nil) else result = factory.create(configuration.repr_builder) end - return result + result end # Build a visitor for the given parse tree # @param aPTree [PTree::ParseTree] # @return [ParseTreeVisitor] @@ -146,15 +143,15 @@ # Build a visitor for the given parse forest # @param aPForest [SPPF::ParseForest] # @return [ParseForestVisitor] def pforest_visitor(aPForest) - return ParseForestVisitor.new(aPForest) + ParseForestVisitor.new(aPForest) end protected def build_parser(aGrammar) - return Parser::GFGEarleyParser.new(aGrammar) + Parser::GFGEarleyParser.new(aGrammar) end end # class end # module