Skip to content

Commit

Permalink
Use %no-stdlib instead of --no-stdlib option
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jan 22, 2024
1 parent a655c31 commit 6786de3
Show file tree
Hide file tree
Showing 8 changed files with 470 additions and 480 deletions.
2 changes: 1 addition & 1 deletion lib/lrama/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def run(argv)
options.y.close if options.y != STDIN
begin
grammar = Lrama::Parser.new(text, options.grammar_file, options.debug).parse
unless options.no_stdlib
unless grammar.no_stdlib
stdlib_grammar = Lrama::Parser.new(File.read(STDLIB_FILE_PATH), STDLIB_FILE_PATH, options.debug).parse
grammar.insert_before_parameterizing_rules(stdlib_grammar.parameterizing_rules)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/lrama/grammar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Grammar
:lex_param, :parse_param, :initial_action,
:symbols, :types,
:rules, :rule_builders,
:sym_to_rules
:sym_to_rules, :no_stdlib

def initialize(rule_counter)
@rule_counter = rule_counter
Expand All @@ -45,6 +45,7 @@ def initialize(rule_counter)
@undef_symbol = nil
@accept_symbol = nil
@aux = Auxiliary.new
@no_stdlib = false

append_special_symbols
end
Expand Down
1 change: 1 addition & 0 deletions lib/lrama/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Lexer
%empty
%code
%rule
%no-stdlib
)

def initialize(grammar_file)
Expand Down
1 change: 0 additions & 1 deletion lib/lrama/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def parse_by_option_parser(argv)
o.on('-S', '--skeleton=FILE', 'specify the skeleton to use') {|v| @options.skeleton = v }
o.on('-t', 'reserved, do nothing') { }
o.on('--debug', 'display debugging outputs of internal parser') {|v| @options.debug = true }
o.on('--no-stdlib', 'do not include standard library') {|v| @options.no_stdlib = true }
o.separator ''
o.separator 'Output:'
o.on('-H', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v }
Expand Down
3 changes: 1 addition & 2 deletions lib/lrama/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Options
:report_file, :outfile,
:error_recovery, :grammar_file,
:trace_opts, :report_opts, :y,
:debug, :no_stdlib
:debug

def initialize
@skeleton = "bison/yacc.c"
Expand All @@ -18,7 +18,6 @@ def initialize
@trace_opts = nil
@report_opts = nil
@y = STDIN
@no_stdlib = false
end
end
end
918 changes: 464 additions & 454 deletions lib/lrama/parser.rb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ rule
{
@grammar.initial_action = Grammar::Code::InitialActionCode.new(type: :initial_action, token_code: val[3])
}
| "%no-stdlib" { @grammar.no_stdlib = true }
| ";"

grammar_declaration: "%union" "{"
Expand Down
21 changes: 0 additions & 21 deletions spec/lrama/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
-S, --skeleton=FILE specify the skeleton to use
-t reserved, do nothing
--debug display debugging outputs of internal parser
--no-stdlib do not include standard library
Output:
-H, --header=[FILE] also produce a header file named FILE
Expand Down Expand Up @@ -198,24 +197,4 @@
end
end
end

describe "@no_stdlib" do
context "--no-stdlib option is not passed" do
it "@no_stdlib is false" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["-", "test.y"])
options = option_parser.instance_variable_get(:@options)
expect(options.no_stdlib).to eq false
end
end

context "--no-stdlib option is passed" do
it "@no_stdlib is true" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["--no-stdlib", "-", "test.y"])
options = option_parser.instance_variable_get(:@options)
expect(options.no_stdlib).to eq true
end
end
end
end

0 comments on commit 6786de3

Please sign in to comment.