Files
sml-projects/fcore/parser/brace-dfa.sml

34 lines
600 B
Standard ML
Raw Normal View History

2025-07-12 02:02:21 +01:00
structure BraceDfa =
struct
val dead = 0
val start = 1
val final = 2
fun makeStart i =
let
val chr = Char.chr i
in
if chr = #"{" orelse chr = #"}" then
final
else
dead
end
val deadTable = SpaceDfa.deadTable
val startTable = Vector.tabulate (255, makeStart)
val finalTable = deadTable
val tables = #[deadTable, startTable, finalTable]
fun isFinal state =
state = final
fun next (state, chr) =
let
val table = Vector.sub (tables, state)
val idx = Char.ord chr
in
Vector.sub (table, idx)
end
end