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

BIN
dotscape

Binary file not shown.

View File

@@ -16,9 +16,10 @@ struct
(model, [FILE msg]) (model, [FILE msg])
end end
(* unimplemented *) fun getLoadSquaresMsg model =
fun getLoadSquaresMsg model = (model, []) (model, [FILE LOAD_SQUARES])
(* unimplemented *)
fun getExportSquaresMsg model = (model, []) fun getExportSquaresMsg model = (model, [])
fun useSquaresInNormalMode (model, squares) = (model, []) fun useSquaresInNormalMode (model, squares) = (model, [])

View File

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

View File

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

View File

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

View File

@@ -381,23 +381,6 @@ struct
else y else y
end end
fun printItem {x, y, ex, ey, data} =
let
val msg = String.concat
[ "{x = "
, Int.toString x
, ", y = "
, Int.toString y
, ", ex = "
, Int.toString ex
, ", ey = "
, Int.toString ey
, "}\n"
]
in
print msg
end
local local
fun loop (tree, grid) = fun loop (tree, grid) =
case tree of case tree of

1
green.dsc Normal file
View File

@@ -0,0 +1 @@
4 4 { {0 1 0 1 0 0 0 1 } {1 2 1 2 0 0 0 1 } }

View File

@@ -8,8 +8,6 @@ struct
open FileMessage open FileMessage
open InputMessage open InputMessage
datatype parse_result = OK of unit | PARSE_ERROR
val structureName = "Green" val structureName = "Green"
val filename = "green.dsc" val filename = "green.dsc"
val exportFilename = "green.sml" val exportFilename = "green.sml"
@@ -49,7 +47,21 @@ struct
fun parse (io, acc) = () fun parse (io, acc) = ()
fun loadSquares (path, inputMailbox) = () fun loadIO (io, str) =
case TextIO.inputLine io of
SOME line => loadIO (io, str ^ line)
| NONE => str
fun loadSquares (path, inputMailbox) =
let
val io = TextIO.openIn filename
val str = loadIO (io, "")
val () = TextIO.closeIn io
in
case Parser.parse str of
SOME (canvasWidth, canvasHeight, grid) => ()
| NONE => ()
end
fun saveSquares squaresString = fun saveSquares squaresString =
let let