Skip to content

Commit

Permalink
Add NewPerser support
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Oct 14, 2023
1 parent ace817b commit 124135b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
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::NewParser.new(text, options.header_file).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
14 changes: 11 additions & 3 deletions lib/lrama/new_parser.rb

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

13 changes: 11 additions & 2 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rule
}
"%}"
{
@grammar.prologue = val[2].s_value
@grammar.prologue = prologue(val[2])
}
| "%require" STRING

Expand Down Expand Up @@ -363,8 +363,9 @@ end

---- inner

def initialize(text)
def initialize(text, header_file)
@text = text
@header_path = header_file ? header_file.sub("./", "") : nil
end

def parse
Expand All @@ -382,3 +383,11 @@ end
def next_token
@lexer.next_token
end

def prologue(s_value)
if @header_path
"\n#include \"#{@header_path}\"\n" + s_value
else
s_value
end
end

0 comments on commit 124135b

Please sign in to comment.