spec/rley/formatter/bracket_notation_spec.rb in rley-0.5.14 vs spec/rley/formatter/bracket_notation_spec.rb in rley-0.6.00

- old
+ new

@@ -4,40 +4,36 @@ require_relative '../support/grammar_abc_helper' require_relative '../../../lib/rley/lexical/token' require_relative '../../../lib/rley/parser/gfg_earley_parser' require_relative '../../../lib/rley/ptree/parse_tree' require_relative '../../../lib/rley/parse_tree_visitor' +require_relative '../../../lib/rley/engine' # Load the class under test require_relative '../../../lib/rley/formatter/bracket_notation' module Rley # Re-open the module to get rid of qualified names module Formatter describe BracketNotation do - include GrammarABCHelper # Mix-in module for grammar abc # Factory method. Build a production with the given sequence # of symbols as its rhs. let(:grammar_abc) do - builder = grammar_abc_builder + sandbox = Object.new + sandbox.extend(GrammarABCHelper) + builder = sandbox.grammar_abc_builder builder.grammar end # Variables for the terminal symbols let(:a_) { grammar_abc.name2symbol['a'] } let(:b_) { grammar_abc.name2symbol['b'] } let(:c_) { grammar_abc.name2symbol['c'] } # Helper method that mimicks the output of a tokenizer - # for the language specified by gramma_abc + # for the language specified by grammar_abc let(:grm_abc_tokens1) do - [ - Lexical::Token.new('a', a_), - Lexical::Token.new('a', a_), - Lexical::Token.new('b', b_), - Lexical::Token.new('c', c_), - Lexical::Token.new('c', c_) - ] + %w[a a b c c].map { |ch| Lexical::Token.new(ch, ch) } end # Factory method that builds a sample parse tree. # Generated tree has the following structure: # S[0,5] @@ -49,12 +45,14 @@ # | | +- b[2,3] # | +- c[3,4] # +- c[4,5] # Capital letters represent non-terminal nodes let(:grm_abc_ptree1) do - parser = Parser::GFGEarleyParser.new(grammar_abc) - parse_result = parser.parse(grm_abc_tokens1) - parse_result.parse_tree + engine = Rley::Engine.new + engine.use_grammar(grammar_abc) + parse_result = engine.parse(grm_abc_tokens1) + ptree = engine.convert(parse_result) + ptree end let(:destination) { StringIO.new('', 'w') } subject { BracketNotation.new(destination) }