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:
@@ -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, [])
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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) =
|
||||||
|
|||||||
@@ -18,18 +18,21 @@ struct
|
|||||||
end
|
end
|
||||||
| _ => SOME (tokens, grid)
|
| _ => SOME (tokens, grid)
|
||||||
|
|
||||||
fun parse tokens =
|
fun parse string =
|
||||||
case tokens of
|
case Lexer.scan string of
|
||||||
T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl =>
|
SOME tokens =>
|
||||||
let
|
(case tokens of
|
||||||
val grid = ParseGrid.make (canvasWidth, canvasHeight)
|
T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl =>
|
||||||
in
|
let
|
||||||
case parseItems (tl, grid) of
|
val grid = ParseGrid.make (canvasWidth, canvasHeight)
|
||||||
SOME (tokens, grid) =>
|
in
|
||||||
(case tokens of
|
case parseItems (tl, grid) of
|
||||||
[T.R_BRACE] => SOME grid
|
SOME (tokens, grid) =>
|
||||||
| _ => NONE)
|
(case tokens of
|
||||||
| NONE => NONE
|
[T.R_BRACE] => SOME (canvasWidth, canvasHeight, grid)
|
||||||
end
|
| _ => NONE)
|
||||||
| _ => NONE
|
| NONE => NONE
|
||||||
|
end
|
||||||
|
| _ => NONE)
|
||||||
|
| NONE => NONE
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user