diff --git a/dotscape b/dotscape index 79f1b7c..569f6b7 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/common-update.sml b/fcore/common-update.sml index 7ece0d5..d51c285 100644 --- a/fcore/common-update.sml +++ b/fcore/common-update.sml @@ -16,9 +16,10 @@ struct (model, [FILE msg]) end - (* unimplemented *) - fun getLoadSquaresMsg model = (model, []) + fun getLoadSquaresMsg model = + (model, [FILE LOAD_SQUARES]) + (* unimplemented *) fun getExportSquaresMsg model = (model, []) fun useSquaresInNormalMode (model, squares) = (model, []) diff --git a/fcore/parser/int-dfa.sml b/fcore/parser/int-dfa.sml index 1dba3da..2f70b75 100644 --- a/fcore/parser/int-dfa.sml +++ b/fcore/parser/int-dfa.sml @@ -8,12 +8,10 @@ struct let val chr = Char.chr i in - if chr >= #"0" orelse chr < #"9" then - final - else dead + if Char.isDigit chr then final else dead end - val deadTable = SpaceDfa.deadTable + val deadTable = Vector.tabulate (255, fn _ => dead) val startTable = Vector.tabulate (255, makeStart) val finalTable = startTable diff --git a/fcore/parser/lexer.sml b/fcore/parser/lexer.sml index 9e97769..9c23714 100644 --- a/fcore/parser/lexer.sml +++ b/fcore/parser/lexer.sml @@ -17,7 +17,7 @@ struct SOME (lastSpace, acc) else let - val str = String.substring (str, min, finish - min) + val str = String.substring (str, min, finish - min + 1) in if min = lastInt then case Int.fromString str of @@ -33,14 +33,15 @@ struct end fun scanStep (pos, str, acc, dfa, finish) = - if AllDfa.areAllDead dfa then + if pos < 0 orelse AllDfa.areAllDead dfa then addToken (acc, dfa, str, finish) else let val chr = String.sub (str, pos) val dfa = AllDfa.update (chr, dfa, pos) in - scanStep (pos - 1, str, acc, dfa, finish) + if AllDfa.areAllDead dfa then addToken (acc, dfa, str, finish) + else scanStep (pos - 1, str, acc, dfa, finish) end fun scanLoop (pos, str, acc) = diff --git a/fcore/parser/parser.sml b/fcore/parser/parser.sml index 098f14a..2011981 100644 --- a/fcore/parser/parser.sml +++ b/fcore/parser/parser.sml @@ -18,18 +18,21 @@ struct end | _ => SOME (tokens, grid) - fun parse tokens = - case tokens of - T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl => - let - val grid = ParseGrid.make (canvasWidth, canvasHeight) - in - case parseItems (tl, grid) of - SOME (tokens, grid) => - (case tokens of - [T.R_BRACE] => SOME grid - | _ => NONE) - | NONE => NONE - end - | _ => NONE + fun parse string = + case Lexer.scan string of + SOME tokens => + (case tokens of + T.INT canvasWidth :: T.INT canvasHeight :: T.L_BRACE :: tl => + let + val grid = ParseGrid.make (canvasWidth, canvasHeight) + in + case parseItems (tl, grid) of + SOME (tokens, grid) => + (case tokens of + [T.R_BRACE] => SOME (canvasWidth, canvasHeight, grid) + | _ => NONE) + | NONE => NONE + end + | _ => NONE) + | NONE => NONE end diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 7076764..d4d30a0 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -381,23 +381,6 @@ struct else y end - fun printItem {x, y, ex, ey, data} = - let - val msg = String.concat - [ "{x = " - , Int.toString x - , ", y = " - , Int.toString y - , ", ex = " - , Int.toString ex - , ", ey = " - , Int.toString ey - , "}\n" - ] - in - print msg - end - local fun loop (tree, grid) = case tree of diff --git a/green.dsc b/green.dsc new file mode 100644 index 0000000..9ea7afb --- /dev/null +++ b/green.dsc @@ -0,0 +1 @@ +4 4 { {0 1 0 1 0 0 0 1 } {1 2 1 2 0 0 0 1 } } diff --git a/imperative-shell/file-thread.sml b/imperative-shell/file-thread.sml index 078d7f4..6d9197e 100644 --- a/imperative-shell/file-thread.sml +++ b/imperative-shell/file-thread.sml @@ -8,8 +8,6 @@ struct open FileMessage open InputMessage - datatype parse_result = OK of unit | PARSE_ERROR - val structureName = "Green" val filename = "green.dsc" val exportFilename = "green.sml" @@ -49,7 +47,21 @@ struct fun parse (io, acc) = () - fun loadSquares (path, inputMailbox) = () + fun loadIO (io, str) = + case TextIO.inputLine io of + SOME line => loadIO (io, str ^ line) + | NONE => str + + fun loadSquares (path, inputMailbox) = + let + val io = TextIO.openIn filename + val str = loadIO (io, "") + val () = TextIO.closeIn io + in + case Parser.parse str of + SOME (canvasWidth, canvasHeight, grid) => () + | NONE => () + end fun saveSquares squaresString = let