fix bugs related to parsing and loading file (did not implement new BNF grammar properly)
This commit is contained in:
@@ -1011,8 +1011,8 @@ struct
|
|||||||
, yClickPoints
|
, yClickPoints
|
||||||
, windowWidth
|
, windowWidth
|
||||||
, windowHeight
|
, windowHeight
|
||||||
, arrowX = _
|
, arrowX
|
||||||
, arrowY = _
|
, arrowY
|
||||||
, canvasWidth = _
|
, canvasWidth = _
|
||||||
, canvasHeight = _
|
, canvasHeight = _
|
||||||
|
|
||||||
@@ -1028,9 +1028,6 @@ struct
|
|||||||
, layerTree = _
|
, layerTree = _
|
||||||
, modalNum
|
, modalNum
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val arrowX = 0
|
|
||||||
val arrowY = 0
|
|
||||||
in
|
in
|
||||||
{ mode = mode
|
{ mode = mode
|
||||||
, mouseX = mouseX
|
, mouseX = mouseX
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ struct
|
|||||||
|
|
||||||
fun getSaveSquaresMsg (model: app_type) =
|
fun getSaveSquaresMsg (model: app_type) =
|
||||||
let
|
let
|
||||||
(* todo: reimplement, saving each layer to a different line
|
val {layerTree, canvasWidth, canvasHeight, ...} = model
|
||||||
val {canvasWidth, canvasHeight, squares, ...} = model
|
val str =
|
||||||
val str = CollisionTree.toSaveString (squares, canvasWidth, canvasHeight)
|
CollisionTree.toSaveString (layerTree, canvasWidth, canvasHeight)
|
||||||
val msg = SAVE_SQUARES str
|
val msg = SAVE_SQUARES str
|
||||||
*)
|
in
|
||||||
in raise Fail "todo common-update.sml: reimplement saving"
|
(model, [FILE msg])
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getLoadSquaresMsg model =
|
fun getLoadSquaresMsg model =
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ structure Parser =
|
|||||||
struct
|
struct
|
||||||
structure T = Tokens
|
structure T = Tokens
|
||||||
|
|
||||||
fun parseItems (tokens, grid) =
|
fun parseItem (tokens, grid) =
|
||||||
case tokens of
|
case tokens of
|
||||||
T.L_BRACE ::
|
T.L_BRACE ::
|
||||||
T.INT x ::
|
T.INT x ::
|
||||||
@@ -14,27 +14,48 @@ struct
|
|||||||
val colour = {r = r, g = g, b = b, a = a}
|
val colour = {r = r, g = g, b = b, a = a}
|
||||||
val grid = ParseGrid.applyItem (grid, x, y, ex, ey, colour)
|
val grid = ParseGrid.applyItem (grid, x, y, ex, ey, colour)
|
||||||
in
|
in
|
||||||
parseItems (tl, grid)
|
SOME (tl, grid)
|
||||||
end
|
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) =
|
fun parseLayers (tokens, canvasWidth, canvasHeight, tree, counter) =
|
||||||
|
case tokens of
|
||||||
|
T.L_BRACKET :: tl =>
|
||||||
let
|
let
|
||||||
val grid = ParseGrid.make (canvasWidth, canvasHeight)
|
val grid = ParseGrid.make (canvasWidth, canvasHeight)
|
||||||
in
|
in
|
||||||
case parseItems (tokens, grid) of
|
case startParseItems (tl, grid) of
|
||||||
SOME (tokens, grid) =>
|
SOME (T.R_BRACKET :: tl, grid) =>
|
||||||
let val tree = LayerTree.insert (counter, grid, tree)
|
let val tree = LayerTree.insert (counter, grid, tree)
|
||||||
in parseLayers (tokens, canvasWidth, canvasHeight, tree, counter + 1)
|
in parseLayers (tl, canvasWidth, canvasHeight, tree, counter + 1)
|
||||||
end
|
end
|
||||||
|
| SOME _ => NONE
|
||||||
| NONE => (tokens, tree)
|
| NONE => (tokens, tree)
|
||||||
end
|
end
|
||||||
|
| _ => (tokens, tree)
|
||||||
|
|
||||||
fun parse string =
|
fun parse string =
|
||||||
case Lexer.scan string of
|
case Lexer.scan string of
|
||||||
SOME tokens =>
|
SOME tokens =>
|
||||||
(case tokens of
|
(case tokens of
|
||||||
T.INT canvasWidth :: T.INT canvasHeight :: tl =>
|
T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl =>
|
||||||
let
|
let
|
||||||
val maxSide = Int.max (canvasWidth, canvasHeight)
|
val maxSide = Int.max (canvasWidth, canvasHeight)
|
||||||
val tree = LayerTree.init maxSide
|
val tree = LayerTree.init maxSide
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ struct
|
|||||||
fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
fun toSaveStringFolder ({x, ex, y, ey, data = {r, g, b, a}}, acc) =
|
||||||
let
|
let
|
||||||
val item = String.concat
|
val item = String.concat
|
||||||
[ "["
|
[ " { "
|
||||||
, Int.toString x
|
, Int.toString x
|
||||||
, " "
|
, " "
|
||||||
, Int.toString y
|
, Int.toString y
|
||||||
@@ -476,7 +476,7 @@ struct
|
|||||||
, Int.toString b
|
, Int.toString b
|
||||||
, " "
|
, " "
|
||||||
, Int.toString a
|
, Int.toString a
|
||||||
, " ] "
|
, " } "
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
item :: acc
|
item :: acc
|
||||||
@@ -486,9 +486,11 @@ struct
|
|||||||
let
|
let
|
||||||
val qtree = buildTree (0, 0, size, grid)
|
val qtree = buildTree (0, 0, size, grid)
|
||||||
val bintree = merge (qtree, 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
|
in
|
||||||
String.concat str :: acc
|
str :: acc
|
||||||
end
|
end
|
||||||
|
|
||||||
fun toSaveString (layerTree, canvasWidth, canvasHeight) =
|
fun toSaveString (layerTree, canvasWidth, canvasHeight) =
|
||||||
@@ -496,7 +498,7 @@ struct
|
|||||||
val size = Int.max (canvasWidth, canvasHeight)
|
val size = Int.max (canvasWidth, canvasHeight)
|
||||||
val f = toSaveStringTreeFolder size
|
val f = toSaveStringTreeFolder size
|
||||||
|
|
||||||
val initial = ["}"]
|
val initial = ["}\n"]
|
||||||
val acc = LayerTree.foldr (f, layerTree, initial)
|
val acc = LayerTree.foldr (f, layerTree, initial)
|
||||||
val acc =
|
val acc =
|
||||||
String.concat
|
String.concat
|
||||||
|
|||||||
Reference in New Issue
Block a user