I have the following state diagram that is for validating whether a string matches a format.
I would like to recreate this language matching fsm in xstate. The machine should return true for ac
, abc
, abbbbbc
etc and otherwise false. It should have exactly the same output as the regex expression string.match(/^ab*c$/) !== null;
I currently have the following:
const machine = Machine({
initial: 'start',
states: {
start: {
on: {A: 'state1'}
},
state1: {
on: {
B: 'state1',
C: 'end'
}
},
end: {}
}
});
Is there a way through actions and context I can check if a string matches this language fsm through it reaching the end state.
Of course I could just use regex but I have simplified the problem for the purpose of this so question. The actual language I want to parse is not regular and requires pda / context. I just want to know the structure of using xstate for language / string parsing.