38 lines
941 B
Standard ML
38 lines
941 B
Standard ML
|
|
structure ViLDfa =
|
||
|
|
struct
|
||
|
|
val startState: Word8.word = 0w0
|
||
|
|
val notNewlineState: Word8.word = 0w1
|
||
|
|
val oneNewlineState: Word8.word = 0w2
|
||
|
|
|
||
|
|
fun makeStart i =
|
||
|
|
if Char.chr i = #"\n" then oneNewlineState else notNewlineState
|
||
|
|
|
||
|
|
fun makeOneNewline _ = notNewlineState
|
||
|
|
|
||
|
|
val startTable = Vector.tabulate (255, makeStart)
|
||
|
|
val notNewlineTable = startTable
|
||
|
|
val oneNewlineTable = Vector.tabulate (255, makeOneNewline)
|
||
|
|
|
||
|
|
val tables = #[startTable, notNewlineTable, oneNewlineTable]
|
||
|
|
|
||
|
|
structure ViL =
|
||
|
|
MakeNextDfaLoop
|
||
|
|
(struct
|
||
|
|
val startState = startState
|
||
|
|
|
||
|
|
structure Folder =
|
||
|
|
MakeCharFolderNext
|
||
|
|
(struct
|
||
|
|
val startState = startState
|
||
|
|
val tables = tables
|
||
|
|
|
||
|
|
fun finish x = x
|
||
|
|
fun isFinal currentState = currentState = notNewlineState
|
||
|
|
end)
|
||
|
|
|
||
|
|
val fStart = Folder.foldNext
|
||
|
|
end)
|
||
|
|
|
||
|
|
val next = ViL.next
|
||
|
|
end
|