diff --git a/.github/workflows/codespell.yaml b/.github/workflows/codespell.yaml index 7632ba8e..fae65a6c 100644 --- a/.github/workflows/codespell.yaml +++ b/.github/workflows/codespell.yaml @@ -13,4 +13,3 @@ jobs: check_filenames: true check_hidden: true ignore_words_file: .codespellignore - exclude_file: lib/lrama/new_parser.rb diff --git a/Rakefile b/Rakefile index 6a8ac011..077bf110 100644 --- a/Rakefile +++ b/Rakefile @@ -3,11 +3,11 @@ require "bundler/gem_tasks" namespace "build" do desc "build parser from parser.y by using Racc" task :racc_parser do - `bundle exec racc parser.y --embedded -o lib/lrama/new_parser.rb` + `bundle exec racc parser.y --embedded -o lib/lrama/parser.rb` end desc "build parser for debugging" task :racc_verbose_parser do - `bundle exec racc parser.y --embedded -o lib/lrama/new_parser.rb -t --log-file=parser.output` + `bundle exec racc parser.y --embedded -o lib/lrama/parser.rb -t --log-file=parser.output` end end diff --git a/lib/lrama.rb b/lib/lrama.rb index aa813a52..f9c5ec16 100644 --- a/lib/lrama.rb +++ b/lib/lrama.rb @@ -8,7 +8,7 @@ require "lrama/option_parser" require "lrama/options" require "lrama/output" -# require "lrama/parser" +require "lrama/parser" require "lrama/report" require "lrama/state" require "lrama/states" @@ -16,5 +16,4 @@ require "lrama/type" require "lrama/version" require "lrama/warning" -require "lrama/new_parser" require "lrama/new_lexer" diff --git a/lib/lrama/command.rb b/lib/lrama/command.rb index 213b7acb..5d8957da 100644 --- a/lib/lrama/command.rb +++ b/lib/lrama/command.rb @@ -8,7 +8,7 @@ def run(argv) warning = Lrama::Warning.new text = options.y.read options.y.close if options.y != STDIN - grammar = Lrama::NewParser.new(text).parse + grammar = Lrama::Parser.new(text).parse states = Lrama::States.new(grammar, warning, trace_state: (options.trace_opts[:automaton] || options.trace_opts[:closure])) states.compute context = Lrama::Context.new(states) diff --git a/lib/lrama/new_parser.rb b/lib/lrama/parser.rb similarity index 99% rename from lib/lrama/new_parser.rb rename to lib/lrama/parser.rb index dc0c77f7..efa87da8 100644 --- a/lib/lrama/new_parser.rb +++ b/lib/lrama/parser.rb @@ -666,7 +666,7 @@ def token_to_str(t) end ###### racc/parser.rb end module Lrama - class NewParser < Racc::Parser + class Parser < Racc::Parser module_eval(<<'...end parser.y/module_eval...', 'parser.y', 388) @@ -1787,5 +1787,5 @@ def _reduce_none(val, _values, result) val[0] end - end # class NewParser + end # class Parser end # module Lrama diff --git a/parser.y b/parser.y index 27b1566f..126da691 100644 --- a/parser.y +++ b/parser.y @@ -1,4 +1,4 @@ -class Lrama::NewParser +class Lrama::Parser rule input: prologue_declarations bison_declarations "%%" grammar epilogue_opt diff --git a/spec/lrama/context_spec.rb b/spec/lrama/context_spec.rb index d81d5964..a8ff640d 100644 --- a/spec/lrama/context_spec.rb +++ b/spec/lrama/context_spec.rb @@ -5,7 +5,7 @@ describe "basic" do it do y = File.read(fixture_path("context/basic.y")) - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute context = Lrama::Context.new(states) @@ -181,7 +181,7 @@ %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute context = Lrama::Context.new(states) @@ -230,7 +230,7 @@ %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute context = Lrama::Context.new(states) diff --git a/spec/lrama/counterexamples_spec.rb b/spec/lrama/counterexamples_spec.rb index 501d680d..f0cce980 100644 --- a/spec/lrama/counterexamples_spec.rb +++ b/spec/lrama/counterexamples_spec.rb @@ -50,7 +50,7 @@ end it "build counterexamples of S/R conflicts" do - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute counterexamples = Lrama::Counterexamples.new(states) @@ -249,7 +249,7 @@ end it "build counterexamples of R/R conflicts" do - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute counterexamples = Lrama::Counterexamples.new(states) @@ -326,7 +326,7 @@ end it "build counterexamples of S/R conflicts" do - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute counterexamples = Lrama::Counterexamples.new(states) @@ -407,7 +407,7 @@ end it "build counterexamples of S/R and R/R conflicts" do - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute counterexamples = Lrama::Counterexamples.new(states) diff --git a/spec/lrama/new_parser_spec.rb b/spec/lrama/parser_spec.rb similarity index 98% rename from spec/lrama/new_parser_spec.rb rename to spec/lrama/parser_spec.rb index 6833ac0d..6bae8ace 100644 --- a/spec/lrama/new_parser_spec.rb +++ b/spec/lrama/parser_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe Lrama::NewParser do +RSpec.describe Lrama::Parser do T ||= Lrama::Lexer::Token Type = Lrama::Type Sym = Lrama::Grammar::Symbol @@ -41,7 +41,7 @@ describe '#parse' do it "basic" do y = File.read(fixture_path("common/basic.y")) - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.union.code.s_value).to eq(<<-CODE.chomp) @@ -408,7 +408,7 @@ it "nullable" do y = File.read(fixture_path("common/nullable.y")) - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.nterms.sort_by(&:number)).to eq([ Sym.new(id: T.new(type: T::Ident, s_value: "$accept"), alias_name: nil, number: 6, tag: nil, term: false, token_id: 0, nullable: false), @@ -562,7 +562,7 @@ class : keyword_class tSTRING keyword_end { code 1 } %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar._rules).to eq([ [ @@ -605,7 +605,7 @@ class : keyword_class tSTRING keyword_end { code 1 } %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.terms.sort_by(&:number)).to eq([ Sym.new(id: T.new(type: T::Ident, s_value: "EOI"), alias_name: "\"EOI\"", number: 0, tag: nil, term: true, token_id: 0, nullable: false, precedence: nil), @@ -661,7 +661,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 } %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.nterms.sort_by(&:number)).to eq([ Sym.new(id: T.new(type: T::Ident, s_value: "$accept"), alias_name: nil, number: 11, tag: nil, term: false, token_id: 0, nullable: false), @@ -756,7 +756,7 @@ class : keyword_class tSTRING %prec tPLUS keyword_end { code 1 } %% INPUT - parser = Lrama::NewParser.new(y) + parser = Lrama::Parser.new(y) expect { parser.parse }.to raise_error("Ident after %prec") end @@ -773,7 +773,7 @@ class : keyword_class { code 2 } tSTRING %prec "=" '!' keyword_end { code 3 } %% INPUT - parser = Lrama::NewParser.new(y) + parser = Lrama::Parser.new(y) expect { parser.parse }.to raise_error("Char after %prec") end @@ -790,7 +790,7 @@ class : keyword_class { code 4 } tSTRING '?' keyword_end %prec tEQ { code 5 } { %% INPUT - parser = Lrama::NewParser.new(y) + parser = Lrama::Parser.new(y) expect { parser.parse }.to raise_error("Multiple User_code after %prec") end @@ -811,7 +811,7 @@ class : keyword_class %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse codes = grammar.rules.map(&:code).compact expect(codes.count).to eq(1) @@ -838,7 +838,7 @@ class : keyword_class %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse codes = grammar.rules.map(&:code).compact expect(codes.count).to eq(1) @@ -883,7 +883,7 @@ class : keyword_class tSTRING keyword_end { code 1 } %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.terms.sort_by(&:number)).to eq([ Sym.new(id: T.new(type: T::Ident, s_value: "EOI"), alias_name: "\"EOI\"", number: 0, tag: nil, term: true, token_id: 0, nullable: false), @@ -932,7 +932,7 @@ class : keyword_class tSTRING keyword_end { code 1 } %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.terms.sort_by(&:number)).to eq([ Sym.new(id: T.new(type: T::Ident, s_value: "EOI"), alias_name: "\"EOI\"", number: 0, tag: nil, term: true, token_id: 0, nullable: false, precedence: nil), @@ -978,7 +978,7 @@ class : keyword_class tSTRING keyword_end { code 1 } ; %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.rules).to eq([ Rule.new( @@ -1086,7 +1086,7 @@ class : keyword_class tSTRING keyword_end { code 1 } ; %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.rules).to eq([ Rule.new( @@ -1177,7 +1177,7 @@ class : keyword_class tSTRING keyword_end { code 1 } { $$ = $1 - $2; } ; INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse expect(grammar.rules).to eq([ Rule.new( @@ -1311,7 +1311,7 @@ class : keyword_class tSTRING keyword_end { code 1 } ; INPUT - expect { Lrama::NewParser.new(y).parse }.to raise_error("'results' is invalid name.") + expect { Lrama::Parser.new(y).parse }.to raise_error("'results' is invalid name.") end end end @@ -1348,7 +1348,7 @@ class : keyword_class tSTRING keyword_end ; %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse terms = grammar.terms.sort_by(&:number).map do |term| [term.id.s_value, term.token_id] end @@ -1397,7 +1397,7 @@ class : keyword_class tSTRING keyword_end %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse codes = grammar.rules.map(&:code) expect(codes.count).to eq(3) @@ -1444,7 +1444,7 @@ class : keyword_class tSTRING keyword_end %% INPUT - expect { Lrama::NewParser.new(y).parse }.to raise_error(RuntimeError) do |e| + expect { Lrama::Parser.new(y).parse }.to raise_error(RuntimeError) do |e| expect(e.message).to eq(<<~MSG.chomp) $$ of 'stmt' has no declared type $1 of 'stmt' has no declared type diff --git a/spec/lrama/states_spec.rb b/spec/lrama/states_spec.rb index 01e383e2..e46c3759 100644 --- a/spec/lrama/states_spec.rb +++ b/spec/lrama/states_spec.rb @@ -5,7 +5,7 @@ describe '#compute' do it "basic" do y = File.read(fixture_path("common/basic.y")) - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -298,7 +298,7 @@ class go to state 5 it '#State#accessing_symbol' do y = File.read(fixture_path("common/basic.y")) - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -338,7 +338,7 @@ class go to state 5 describe '#reads_relation' do it do y = File.read(fixture_path("states/reads_relation.y")) - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -605,7 +605,7 @@ class go to state 5 describe '#includes_relation' do it do y = File.read(fixture_path("states/includes_relation.y")) - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -904,7 +904,7 @@ class go to state 5 %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -973,7 +973,7 @@ class go to state 5 %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1063,7 +1063,7 @@ class go to state 5 %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1180,7 +1180,7 @@ class go to state 5 %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1277,7 +1277,7 @@ class go to state 5 %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1426,7 +1426,7 @@ class go to state 5 %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1598,7 +1598,7 @@ class go to state 5 %% INPUT - grammar = Lrama::NewParser.new(y).parse + grammar = Lrama::Parser.new(y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1816,7 +1816,7 @@ class : keyword_class tSTRING keyword_end %prec tPLUS end it "has errors for r/r conflicts" do - grammar = Lrama::NewParser.new(header + y).parse + grammar = Lrama::Parser.new(header + y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1840,7 +1840,7 @@ class : keyword_class tSTRING keyword_end %prec tPLUS end it "has errors for s/r conflicts and r/r conflicts" do - grammar = Lrama::NewParser.new(header + y).parse + grammar = Lrama::Parser.new(header + y).parse states = Lrama::States.new(grammar, warning) states.compute @@ -1864,7 +1864,7 @@ class : keyword_class tSTRING keyword_end %prec tPLUS end it "has warns for s/r conflicts and r/r conflicts" do - grammar = Lrama::NewParser.new(header + y).parse + grammar = Lrama::Parser.new(header + y).parse states = Lrama::States.new(grammar, warning) states.compute diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b00d8b69..fe7e706f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,7 +6,7 @@ # Created Groups based on the folder structures add_group "Grammar", "lib/lrama/grammar" add_group "Lexer", "lib/lrama/lexer" - # add_group "Parser", "lib/lrama/parser" + add_group "Parser", "lib/lrama/parser" add_group "Report", "lib/lrama/report" add_group "State", "lib/lrama/state/" add_group "States", "lib/lrama/states/"