fix bugs related to parsing and loading file (did not implement new BNF grammar properly)

This commit is contained in:
2025-08-09 12:39:41 +01:00
parent d6f7583273
commit 143d02163b
6 changed files with 51 additions and 30 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -1011,8 +1011,8 @@ struct
, yClickPoints
, windowWidth
, windowHeight
, arrowX = _
, arrowY = _
, arrowX
, arrowY
, canvasWidth = _
, canvasHeight = _
@@ -1028,9 +1028,6 @@ struct
, layerTree = _
, modalNum
} = app
val arrowX = 0
val arrowY = 0
in
{ mode = mode
, mouseX = mouseX

View File

@@ -48,12 +48,12 @@ struct
fun getSaveSquaresMsg (model: app_type) =
let
(* todo: reimplement, saving each layer to a different line
val {canvasWidth, canvasHeight, squares, ...} = model
val str = CollisionTree.toSaveString (squares, canvasWidth, canvasHeight)
val msg = SAVE_SQUARES str
*)
in raise Fail "todo common-update.sml: reimplement saving"
val {layerTree, canvasWidth, canvasHeight, ...} = model
val str =
CollisionTree.toSaveString (layerTree, canvasWidth, canvasHeight)
val msg = SAVE_SQUARES str
in
(model, [FILE msg])
end
fun getLoadSquaresMsg model =

View File

@@ -2,7 +2,7 @@ structure Parser =
struct
structure T = Tokens
fun parseItems (tokens, grid) =
fun parseItem (tokens, grid) =
case tokens of
T.L_BRACE ::
T.INT x ::
@@ -14,27 +14,48 @@ struct
val colour = {r = r, g = g, b = b, a = a}
val grid = ParseGrid.applyItem (grid, x, y, ex, ey, colour)
in
parseItems (tl, grid)
SOME (tl, grid)
end
| _ => SOME (tokens, grid)
| _ => NONE
(* note to be careful of:
* - startParseItems returns NONE if there are no items found,
* because we have not found a single item yet.
*
* - loopParseItems returns SOME if there are no items found,
* because this function is called after we have parsed at least one item.
* *)
fun loopParseItems (tokens, grid) =
case parseItem (tokens, grid) of
SOME (tokens, grid) => loopParseItems (tokens, grid)
| NONE => SOME (tokens, grid)
fun startParseItems (tokens, grid) =
case parseItem (tokens, grid) of
SOME (tokens, grid) => loopParseItems (tokens, grid)
| NONE => NONE
fun parseLayers (tokens, canvasWidth, canvasHeight, tree, counter) =
let
val grid = ParseGrid.make (canvasWidth, canvasHeight)
in
case parseItems (tokens, grid) of
SOME (tokens, grid) =>
let val tree = LayerTree.insert (counter, grid, tree)
in parseLayers (tokens, canvasWidth, canvasHeight, tree, counter + 1)
end
| NONE => (tokens, tree)
end
case tokens of
T.L_BRACKET :: tl =>
let
val grid = ParseGrid.make (canvasWidth, canvasHeight)
in
case startParseItems (tl, grid) of
SOME (T.R_BRACKET :: tl, grid) =>
let val tree = LayerTree.insert (counter, grid, tree)
in parseLayers (tl, canvasWidth, canvasHeight, tree, counter + 1)
end
| SOME _ => NONE
| NONE => (tokens, tree)
end
| _ => (tokens, tree)
fun parse string =
case Lexer.scan string of
SOME tokens =>
(case tokens of
T.INT canvasWidth :: T.INT canvasHeight :: tl =>
T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl =>
let
val maxSide = Int.max (canvasWidth, canvasHeight)
val tree = LayerTree.init maxSide

View File

@@ -460,7 +460,7 @@ struct
fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
let
val item = String.concat
[ "["
[ " { "
, Int.toString x
, " "
, Int.toString y
@@ -476,7 +476,7 @@ struct
, Int.toString b
, " "
, Int.toString a
, " ] "
, " } "
]
in
item :: acc
@@ -486,9 +486,11 @@ struct
let
val qtree = buildTree (0, 0, size, grid)
val bintree = merge (qtree, grid)
val str = BinTree.foldr (toSaveStringFolder, bintree, [])
val coords = BinTree.foldr (toSaveStringFolder, bintree, [])
val coords = String.concat coords
val str = " [ " ^ coords ^ " ] "
in
String.concat str :: acc
str :: acc
end
fun toSaveString (layerTree, canvasWidth, canvasHeight) =
@@ -496,7 +498,7 @@ struct
val size = Int.max (canvasWidth, canvasHeight)
val f = toSaveStringTreeFolder size
val initial = ["}"]
val initial = ["}\n"]
val acc = LayerTree.foldr (f, layerTree, initial)
val acc =
String.concat

1
green.dsc Normal file
View File

@@ -0,0 +1 @@
4 4 { [ { 0 0 0 0 33 0 0 1 } ] [ { 1 1 1 1 33 0 99 1 } ] }