fixed final state parsing for FA, made FA transitions more visually appealing, supported identifiers starting with a numeric character

This commit is contained in:
Parker TenBroeck 2026-01-09 23:23:58 -05:00
parent 4b83fe4759
commit 9dcef68d82
3 changed files with 5 additions and 5 deletions

View file

@ -111,7 +111,7 @@ impl<'a> Fa<'a> {
} }
} }
TL::Item(S("F", _), list) => { TL::Item(S("F", _), list) => {
if final_states.is_empty() { if !final_states.is_empty() {
ctx.emit_error("final states already set", span); ctx.emit_error("final states already set", span);
} }
let Some(list) = list.expect_set(ctx) else { let Some(list) = list.expect_set(ctx) else {
@ -124,7 +124,7 @@ impl<'a> Fa<'a> {
if states.contains_key(&State(ident)) { if states.contains_key(&State(ident)) {
if final_states if final_states
.insert(State(ident), StateInfo { definition: item.1 }) .insert(State(ident), StateInfo { definition: item.1 })
.is_none() .is_some()
{ {
ctx.emit_error("final state redefined", item.1); ctx.emit_error("final state redefined", item.1);
} }

View file

@ -92,7 +92,7 @@ impl<'a> Lexer<'a> {
} }
fn begin_ident(c: char) -> bool { fn begin_ident(c: char) -> bool {
c.is_alphabetic() || c == '_' || (!c.is_ascii() && !c.is_control() && !c.is_whitespace()) c.is_alphanumeric() || c == '_' || (!c.is_ascii() && !c.is_control() && !c.is_whitespace())
} }
fn continue_ident(c: char) -> bool { fn continue_ident(c: char) -> bool {

View file

@ -160,7 +160,7 @@ export function setAutomaton(auto: Machine) {
font, font,
from: to_from[0], from: to_from[0],
to: to_from[1], to: to_from[1],
label: transitions.map(i => i.repr).join("\n"), label: transitions.map(i => i.repr).join(auto.type=="fa"?",":"\n"),
}); });
} else { } else {
edges.add({ edges.add({
@ -168,7 +168,7 @@ export function setAutomaton(auto: Machine) {
font, font,
from: to_from[0], from: to_from[0],
to: to_from[1], to: to_from[1],
label: transitions.map(i => i.repr).join("\n"), label: transitions.map(i => i.repr).join(auto.type=="fa"?",":"\n"),
}); });
} }
} }