Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple states when parsing rules #2078

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/rouge/regex_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ def rule(re, tok=nil, next_state=nil, &callback)
puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
@output_stream.call(tok, stream[0])
end
when Array
proc do |stream|
puts " yielding: #{tok.qualname}, #{stream[0].inspect}" if @debug
@output_stream.call(tok, stream[0])
for i_next_state in next_state do
next @stack.pop if i_next_state == :pop!
next @stack.push(@stack.last) if i_next_state == :push

state = @states[i_next_state] || self.class.get_state(i_next_state)
puts " pushing :#{state.name}" if @debug
@stack.push(state)
end
end
else
raise "invalid next state: #{next_state.inspect}"
end
Expand Down