Store whether a state accepts, not whether it drops
This commit is contained in:
parent
8a377b4950
commit
c88338698a
@ -191,12 +191,7 @@ class <%= @classname %>
|
||||
uint n_transitions;
|
||||
Token token;
|
||||
UserCodeID code_id;
|
||||
bool drop;
|
||||
|
||||
bool accepts() const
|
||||
{
|
||||
return drop || token.is_valid() || code_id.is_valid();
|
||||
}
|
||||
bool accepts;
|
||||
}
|
||||
|
||||
private struct Mode
|
||||
@ -225,7 +220,7 @@ class <%= @classname %>
|
||||
<% else %>
|
||||
UserCodeID.invalid(),
|
||||
<% end %>
|
||||
<%= state_table_entry[:drop] %>),
|
||||
<%= state_table_entry[:accepts] %>),
|
||||
<% end %>
|
||||
];
|
||||
|
||||
@ -269,7 +264,7 @@ class <%= @classname %>
|
||||
for (;;)
|
||||
{
|
||||
size_t result = attempt_lex_token(out_token_info);
|
||||
if (out_token_info.token < _TOKEN_COUNT)
|
||||
if (result != P_DROP)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@ -340,7 +335,7 @@ class <%= @classname %>
|
||||
{
|
||||
m_input_col += match_info.delta_col;
|
||||
}
|
||||
if (match_info.accepting_state.drop)
|
||||
if (token_to_accept == _TOKEN_COUNT)
|
||||
{
|
||||
return P_DROP;
|
||||
}
|
||||
@ -410,7 +405,7 @@ class <%= @classname %>
|
||||
attempt_match.delta_col++;
|
||||
}
|
||||
current_state = transition_result.destination();
|
||||
if (states[current_state].accepts())
|
||||
if (states[current_state].accepts)
|
||||
{
|
||||
attempt_match.accepting_state = &states[current_state];
|
||||
longest_match = attempt_match;
|
||||
|
@ -148,7 +148,7 @@ class Propane
|
||||
end
|
||||
consume!(/\s+/)
|
||||
consume!(/;/, "expected `;'")
|
||||
@patterns << Pattern.new(pattern: pattern, line_number: @line_number, drop: true, mode: @mode)
|
||||
@patterns << Pattern.new(pattern: pattern, line_number: @line_number, mode: @mode)
|
||||
@mode = nil
|
||||
true
|
||||
end
|
||||
|
@ -24,7 +24,6 @@ class Propane
|
||||
}
|
||||
states = mode_info[:dfa].enumerate
|
||||
states.each do |state, id|
|
||||
drop = state.accepts && state.accepts.drop?
|
||||
token =
|
||||
if state.accepts && state.accepts.token
|
||||
state.accepts.token.id
|
||||
@ -36,7 +35,7 @@ class Propane
|
||||
state_table << {
|
||||
transition_table_index: transition_table.size,
|
||||
n_transitions: state.transitions.size,
|
||||
drop: drop,
|
||||
accepts: !!state.accepts,
|
||||
token: token,
|
||||
code_id: code_id,
|
||||
}
|
||||
|
@ -40,8 +40,6 @@ class Propane
|
||||
# Optional parameters.
|
||||
# @option options [String, nil] :code
|
||||
# Code block to execute when the pattern is matched.
|
||||
# @option options [Boolean] :drop
|
||||
# Whether this is a drop pattern.
|
||||
# @option options [String, nil] :pattern
|
||||
# Pattern.
|
||||
# @option options [Token, nil] :token
|
||||
@ -52,7 +50,6 @@ class Propane
|
||||
# Lexer mode for this pattern.
|
||||
def initialize(options)
|
||||
@code = options[:code]
|
||||
@drop = options[:drop]
|
||||
@pattern = options[:pattern]
|
||||
@token = options[:token]
|
||||
@line_number = options[:line_number]
|
||||
@ -63,14 +60,6 @@ class Propane
|
||||
@nfa = regex.nfa
|
||||
end
|
||||
|
||||
# Whether the pattern is a drop pattern.
|
||||
#
|
||||
# @return [Boolean]
|
||||
# Whether the pattern is a drop pattern.
|
||||
def drop?
|
||||
@drop
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user