fix lexer/parser bugs, add code in file-thread.sml to handle loading/saving of files (but loading is not completely finished yet)

This commit is contained in:
2025-07-12 07:03:09 +01:00
parent eb0b8d31b2
commit dcf6bc074d
8 changed files with 42 additions and 43 deletions

View File

@@ -8,12 +8,10 @@ struct
let
val chr = Char.chr i
in
if chr >= #"0" orelse chr < #"9" then
final
else dead
if Char.isDigit chr then final else dead
end
val deadTable = SpaceDfa.deadTable
val deadTable = Vector.tabulate (255, fn _ => dead)
val startTable = Vector.tabulate (255, makeStart)
val finalTable = startTable

View File

@@ -17,7 +17,7 @@ struct
SOME (lastSpace, acc)
else
let
val str = String.substring (str, min, finish - min)
val str = String.substring (str, min, finish - min + 1)
in
if min = lastInt then
case Int.fromString str of
@@ -33,14 +33,15 @@ struct
end
fun scanStep (pos, str, acc, dfa, finish) =
if AllDfa.areAllDead dfa then
if pos < 0 orelse AllDfa.areAllDead dfa then
addToken (acc, dfa, str, finish)
else
let
val chr = String.sub (str, pos)
val dfa = AllDfa.update (chr, dfa, pos)
in
scanStep (pos - 1, str, acc, dfa, finish)
if AllDfa.areAllDead dfa then addToken (acc, dfa, str, finish)
else scanStep (pos - 1, str, acc, dfa, finish)
end
fun scanLoop (pos, str, acc) =

View File

@@ -18,18 +18,21 @@ struct
end
| _ => SOME (tokens, grid)
fun parse tokens =
case tokens of
T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl =>
let
val grid = ParseGrid.make (canvasWidth, canvasHeight)
in
case parseItems (tl, grid) of
SOME (tokens, grid) =>
(case tokens of
[T.R_BRACE] => SOME grid
| _ => NONE)
| NONE => NONE
end
| _ => NONE
fun parse string =
case Lexer.scan string of
SOME tokens =>
(case tokens of
T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl =>
let
val grid = ParseGrid.make (canvasWidth, canvasHeight)
in
case parseItems (tl, grid) of
SOME (tokens, grid) =>
(case tokens of
[T.R_BRACE] => SOME (canvasWidth, canvasHeight, grid)
| _ => NONE)
| NONE => NONE
end
| _ => NONE)
| NONE => NONE
end