reimplement parsing code (but program does not compile yet because I have to change type of 'USE_SQUARES' constructure)
This commit is contained in:
@@ -18,20 +18,32 @@ struct
|
||||
end
|
||||
| _ => SOME (tokens, grid)
|
||||
|
||||
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
|
||||
|
||||
fun parse string =
|
||||
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 :: tl =>
|
||||
let
|
||||
val grid = ParseGrid.make (canvasWidth, canvasHeight)
|
||||
val maxSide = Int.max (canvasWidth, canvasHeight)
|
||||
val tree = LayerTree.init maxSide
|
||||
val (tokens, tree) = parseLayers
|
||||
(tl, canvasWidth, canvasHeight, tree, 1)
|
||||
in
|
||||
case parseItems (tl, grid) of
|
||||
SOME (tokens, grid) =>
|
||||
(case tokens of
|
||||
[T.R_BRACE] => SOME (canvasWidth, canvasHeight, grid)
|
||||
| _ => NONE)
|
||||
| NONE => NONE
|
||||
case tokens of
|
||||
[T.R_BRACE] => SOME tree
|
||||
| _ => NONE
|
||||
end
|
||||
| _ => NONE)
|
||||
| NONE => NONE
|
||||
|
||||
Reference in New Issue
Block a user