Skip to content

Commit

Permalink
Rename NewParser to Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
junk0612 committed Oct 19, 2023
1 parent a44f4cb commit 9ee4537
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 51 deletions.
1 change: 0 additions & 1 deletion .github/workflows/codespell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ jobs:
check_filenames: true
check_hidden: true
ignore_words_file: .codespellignore
exclude_file: lib/lrama/new_parser.rb
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions lib/lrama.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
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"
require "lrama/states_reporter"
require "lrama/type"
require "lrama/version"
require "lrama/warning"
require "lrama/new_parser"
require "lrama/new_lexer"
2 changes: 1 addition & 1 deletion lib/lrama/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/lrama/new_parser.rb → lib/lrama/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion parser.y
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Lrama::NewParser
class Lrama::Parser
rule
input: prologue_declarations bison_declarations "%%" grammar epilogue_opt

Expand Down
6 changes: 3 additions & 3 deletions spec/lrama/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions spec/lrama/counterexamples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 20 additions & 20 deletions spec/lrama/new_parser_spec.rb → spec/lrama/parser_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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([
[
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9ee4537

Please sign in to comment.