diff --git a/dotscape b/dotscape index 864c3a9..db63536 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/parser/parser.sml b/fcore/parser/parser.sml index fe46950..43e90fa 100644 --- a/fcore/parser/parser.sml +++ b/fcore/parser/parser.sml @@ -35,7 +35,7 @@ struct SOME (tokens, grid) => loopParseItems (tokens, grid) | NONE => NONE - fun parseLayers (tokens, canvasWidth, canvasHeight, tree, counter) = + fun parseLayer (tokens, canvasWidth, canvasHeight, tree, counter) = case tokens of T.L_BRACKET :: tl => let @@ -44,12 +44,23 @@ struct 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) + in SOME (tl, tree) end | SOME _ => NONE - | NONE => (tokens, tree) + | NONE => NONE end - | _ => (tokens, tree) + | _ => NONE + + fun parseLayerLoop (tokens, canvasWidth, canvasHeight, tree, counter) = + case parseLayer (tokens, canvasWidth, canvasHeight, tree, counter) of + SOME (tl, tree) => + parseLayerLoop (tl, canvasWidth, canvasHeight, tree, counter + 1) + | NONE => SOME (tokens, tree) + + fun startParseLayer (tokens, canvasWidth, canvasHeight, tree) = + case parseLayer (tokens, canvasWidth, canvasHeight, tree, 1) of + SOME (tl, tree) => parseLayerLoop (tl, canvasWidth, canvasHeight, tree, 2) + | NONE => NONE fun parse string = case Lexer.scan string of @@ -59,12 +70,12 @@ struct let val maxSide = Int.max (canvasWidth, canvasHeight) val tree = LayerTree.init maxSide - val (tokens, tree) = parseLayers - (tl, canvasWidth, canvasHeight, tree, 1) in - case tokens of - [T.R_BRACE] => SOME (canvasWidth, canvasHeight, tree) - | _ => NONE + case startParseLayer (tl, canvasWidth, canvasHeight, tree) of + SOME ([T.R_BRACE], tree) => + SOME (canvasWidth, canvasHeight, tree) + | SOME _ => NONE + | NONE => NONE end | _ => NONE) | NONE => NONE