verify that parsing saved file is successful

This commit is contained in:
2024-08-29 05:21:04 +01:00
parent f0958686b7
commit 2549703dc7
8 changed files with 46 additions and 20 deletions

2
a.dsc Normal file
View File

@@ -0,0 +1,2 @@
x ~0.0499999858439 y 0.400000035763 x ~0.400000035763 y 0.350000023842 x ~0.100000038743 y 0.100000038743
x 0.25 y ~0.449999958277 x 0.599999964237 y ~0.199999943376 x 0.0499999858439 y 0.0499999858439

BIN
dotscape

Binary file not shown.

View File

@@ -13,6 +13,7 @@ int KEY_Z = GLFW_KEY_Z;
int KEY_S = GLFW_KEY_S; int KEY_S = GLFW_KEY_S;
int KEY_E = GLFW_KEY_E; int KEY_E = GLFW_KEY_E;
int KEY_I = GLFW_KEY_I; int KEY_I = GLFW_KEY_I;
int KEY_L = GLFW_KEY_L;
// Calls function exported from SML // Calls function exported from SML
void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos) { void mouseMoveCallback(GLFWwindow *window, double xpos, double ypos) {

View File

@@ -44,4 +44,6 @@ struct
_symbol "KEY_E" public : ( unit -> int ) * ( int -> unit ); _symbol "KEY_E" public : ( unit -> int ) * ( int -> unit );
val (KEY_I, _) = val (KEY_I, _) =
_symbol "KEY_I" public : ( unit -> int ) * ( int -> unit ); _symbol "KEY_I" public : ( unit -> int ) * ( int -> unit );
val (KEY_L, _) =
_symbol "KEY_L" public : ( unit -> int ) * ( int -> unit );
end end

View File

@@ -182,7 +182,9 @@ struct
in in
(model, DRAW drawMsg) (model, DRAW drawMsg)
end) end)
| [] => (* Nothing to redo. *) (model, NO_MAILBOX) | [] =>
(* Nothing to redo. *)
(model, NO_MAILBOX)
fun toggleGraph (model: app_type) = fun toggleGraph (model: app_type) =
if #showGraph model then if #showGraph model then
@@ -209,6 +211,9 @@ struct
(model, FILE fileMsg) (model, FILE fileMsg)
end end
fun getLoadTriangleMsg model =
(model, FILE LOAD_TRIANGLES)
fun update (model: app_type, inputMsg) = fun update (model: app_type, inputMsg) =
case inputMsg of case inputMsg of
MOUSE_MOVE {x = mouseX, y = mouseY} => MOUSE_MOVE {x = mouseX, y = mouseY} =>
@@ -222,4 +227,5 @@ struct
| REDO_ACTION => redoAction model | REDO_ACTION => redoAction model
| KEY_G => toggleGraph model | KEY_G => toggleGraph model
| KEY_CTRL_S => getSaveTrianglesMsg model | KEY_CTRL_S => getSaveTrianglesMsg model
| KEY_CTRL_L => getLoadTriangleMsg model
end end

View File

@@ -14,13 +14,13 @@ struct
fun extractTriangle lst = fun extractTriangle lst =
case lst of case lst of
[ X , COORD x1 [ X, COORD x1
, Y , COORD y1 , Y, COORD y1
, X , COORD x2 , X, COORD x2
, Y , COORD y2 , Y, COORD y2
, X , COORD x3 , X, COORD x3
, Y , COORD y3 , Y, COORD y3
] => SOME {x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x3, y3 = y3} ] => SOME {x1 = x1, y1 = y1, x2 = x2, y2 = y2, x3 = x3, y3 = y3}
| _ => NONE | _ => NONE
@@ -41,16 +41,14 @@ struct
let let
val chr = String.sub (line, pos) val chr = String.sub (line, pos)
in in
if chr = #" " then if chr = #" " orelse chr = #"\n" then
let let
val strToken = val strToken = String.substring
String.substring (line, lastSpacePos, pos - (lastSpacePos + 1)) (line, lastSpacePos + 1, pos - (lastSpacePos + 1))
val token = tokeniseString strToken val token = tokeniseString strToken
in in
helpParseLine (line, pos + 1, token :: acc, pos) helpParseLine (line, pos + 1, token :: acc, pos)
end end
else if chr = #"\n" then
List.rev acc
else else
helpParseLine (line, pos + 1, acc, lastSpacePos) helpParseLine (line, pos + 1, acc, lastSpacePos)
end end
@@ -62,17 +60,27 @@ struct
datatype parse_resule = OK of AppType.triangle list | PARSE_ERROR datatype parse_resule = OK of AppType.triangle list | PARSE_ERROR
fun helpParse (io, acc) = fun parse (io, acc) =
case TextIO.inputLine io of case TextIO.inputLine io of
SOME line => SOME line =>
(case parseLine line of let
SOME tri => helpParse (io, tri :: acc) val line = parseLine line
| NONE => PARSE_ERROR) in
(case line of
SOME tri => parse (io, tri :: acc)
| NONE => PARSE_ERROR)
end
| NONE => let val triangles = List.rev acc in OK triangles end | NONE => let val triangles = List.rev acc in OK triangles end
fun parse () = fun loadTriangles () =
let val io = TextIO.openIn filename let
in helpParse (io, []) val io = TextIO.openIn filename
val triangles = parse (io, [])
val _ = TextIO.closeIn io
in
case triangles of
OK triangles => print "parse success\n"
| PARSE_ERROR => print "parse error\n"
end end
fun helpSaveTriangles (triangles, io) = fun helpSaveTriangles (triangles, io) =
@@ -111,7 +119,7 @@ struct
val _ = val _ =
case Mailbox.recv fileMailbox of case Mailbox.recv fileMailbox of
SAVE_TRIANGLES triangles => saveTriangles triangles SAVE_TRIANGLES triangles => saveTriangles triangles
| LOAD_TRIANGLES => () | LOAD_TRIANGLES => loadTriangles ()
| EXPORT_TRIANGLES triangles => () | EXPORT_TRIANGLES triangles => ()
in in
run fileMailbox run fileMailbox

View File

@@ -46,6 +46,11 @@ struct
key = Input.KEY_S () andalso action = Input.PRESS () andalso mods = 0x002 key = Input.KEY_S () andalso action = Input.PRESS () andalso mods = 0x002
then then
Mailbox.send (mailbox, KEY_CTRL_S) Mailbox.send (mailbox, KEY_CTRL_S)
else if
(* ctrl-l *)
key = Input.KEY_L () andalso action = Input.PRESS () andalso mods = 0x002
then
Mailbox.send (mailbox, KEY_CTRL_L)
else else
() ()

View File

@@ -9,6 +9,7 @@ sig
| REDO_ACTION | REDO_ACTION
| KEY_G | KEY_G
| KEY_CTRL_S | KEY_CTRL_S
| KEY_CTRL_L
end end
structure InputMessage :> INPUT_MESSAGE = structure InputMessage :> INPUT_MESSAGE =
@@ -22,4 +23,5 @@ struct
| REDO_ACTION | REDO_ACTION
| KEY_G | KEY_G
| KEY_CTRL_S | KEY_CTRL_S
| KEY_CTRL_L
end end