Don't let lex state merging be fooled by trivial loops
This commit is contained in:
parent
baf7f3603c
commit
d0c3e26e84
3 changed files with 21 additions and 16 deletions
|
|
@ -342,7 +342,7 @@ impl Generator {
|
|||
for (i, state) in lex_table.states.into_iter().enumerate() {
|
||||
add_line!(self, "case {}:", i);
|
||||
indent!(self);
|
||||
self.add_lex_state(state);
|
||||
self.add_lex_state(i, state);
|
||||
dedent!(self);
|
||||
}
|
||||
|
||||
|
|
@ -358,7 +358,7 @@ impl Generator {
|
|||
add_line!(self, "");
|
||||
}
|
||||
|
||||
fn add_lex_state(&mut self, state: LexState) {
|
||||
fn add_lex_state(&mut self, index: usize, state: LexState) {
|
||||
if let Some(accept_action) = state.accept_action {
|
||||
add_line!(self, "ACCEPT_TOKEN({});", self.symbol_ids[&accept_action]);
|
||||
}
|
||||
|
|
@ -372,14 +372,14 @@ impl Generator {
|
|||
if self.add_character_set_condition(&characters, &ruled_out_characters) {
|
||||
add!(self, ")\n");
|
||||
indent!(self);
|
||||
self.add_advance_action(&action);
|
||||
self.add_advance_action(index, &action);
|
||||
if let CharacterSet::Include(chars) = characters {
|
||||
ruled_out_characters.extend(chars.iter().map(|c| *c as u32));
|
||||
}
|
||||
dedent!(self);
|
||||
} else {
|
||||
self.buffer.truncate(previous_length);
|
||||
self.add_advance_action(&action);
|
||||
self.add_advance_action(index, &action);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -491,11 +491,11 @@ impl Generator {
|
|||
})
|
||||
}
|
||||
|
||||
fn add_advance_action(&mut self, action: &AdvanceAction) {
|
||||
fn add_advance_action(&mut self, index: usize, action: &AdvanceAction) {
|
||||
if action.in_main_token {
|
||||
add_line!(self, "ADVANCE({});", action.state);
|
||||
add_line!(self, "ADVANCE({});", action.state.unwrap_or(index));
|
||||
} else {
|
||||
add_line!(self, "SKIP({});", action.state);
|
||||
add_line!(self, "SKIP({});", action.state.unwrap_or(index));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue