diff --git a/dotscape b/dotscape index 63455cf..b9f2d3d 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/app-with.sml b/fcore/app-with.sml index d297c44..462e71b 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -3,12 +3,12 @@ struct open AppType fun updateSquares (squares, newX, newY, item) = - Vector.mapi - (fn (idx, el) => - if idx = newX then - Vector.mapi (fn (iidx, iel) => if iidx = newY then item else iel) el - else - el) squares + let + val yAxis = Vector.sub (squares, newX) + val yAxis = Vector.update (yAxis, newY, item) + in + Vector.update (squares, newX, yAxis) + end fun changeSquaresSize (squares, newCanvasWidth, newCanvasHeight) = let diff --git a/fcore/parsing/brace-dfa.sml b/fcore/parsing/brace-dfa.sml new file mode 100644 index 0000000..6c376e4 --- /dev/null +++ b/fcore/parsing/brace-dfa.sml @@ -0,0 +1,33 @@ +structure BraceDfa = +struct + val dead = 0 + val start = 1 + val final = 2 + + fun makeStart i = + let + val chr = Char.chr i + in + if chr = #"{" orelse chr = #"}" then + final + else + dead + end + + val deadTable = SpaceDfa.deadTable + val startTable = Vector.tabulate (255, makeStart) + val finalTable = deadTable + + val tables = #[deadTable, startTable, finalTable] + + fun isFinal state = + state = final + + fun next (state, chr) = + let + val table = Vector.sub (tables, state) + val idx = Char.ord chr + in + Vector.sub (table, idx) + end +end diff --git a/fcore/parsing/int-dfa.sml b/fcore/parsing/int-dfa.sml new file mode 100644 index 0000000..55f00ab --- /dev/null +++ b/fcore/parsing/int-dfa.sml @@ -0,0 +1,29 @@ +structure IntDfa = +MakeDfa (struct + val dead = 0 + val start = 1 + val final = 2 + + fun makeStart i = + let + val chr = Char.chr i + in + if i >= #"0" orelse i < #"9" then + final + else dead + end + + val deadTable = SpaceDfa.deadTable + val startTable = Vector.tabulate (255, makeStart) + val finalTable = startTable + + val tables = #[]deadTable, startTable, finalTable + + fun next (state, chr) = + let + val table = Vector.sub (tables, state) + val idx = Char.ord chr + in + Vector.sub (table, idx) + end +end) diff --git a/fcore/parsing/lexer.sml b/fcore/parsing/lexer.sml new file mode 100644 index 0000000..c137368 --- /dev/null +++ b/fcore/parsing/lexer.sml @@ -0,0 +1,4 @@ +structure Lexer = +struct + +end diff --git a/fcore/parsing/parse-grid.sml b/fcore/parsing/parse-grid.sml new file mode 100644 index 0000000..06de46a --- /dev/null +++ b/fcore/parsing/parse-grid.sml @@ -0,0 +1,40 @@ +structure ParseGrid = +struct + fun makeGrid (canvasWidth, canvasHeight) = + let + val maxPoints = Int.max (canvasWidth, canvasHeight) + val emptyYAxis = Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0}) + in + Vector.tabulate (maxPoints, fn _ => emptyYAxis) + end + + local + fun loopY (yAxis, x, ex, y, ey, colour) = + if y > ey then yAxis + else + let + val yAxis = Vector.update (yAxis, y, colour) + in + loopY (yAxis, x, ex, y + 1, ey, colour) + end + + fun loopX (grid, x, ex, y, ey, colour) = + if x > ex then grid + else + let + val yAxis = Vector.sub (grid, x) + val yAxis = loopY (yAxis, x, ex, y, ey, colour) + val grid = Vector.update (grid, x, yAxis) + in + loopX (grid, x + 1, ex, y, ey, colour) + end + in + fun applyItem (grid, item) = + let + val {x, y, ex, ey, r, g, b, a} = item + val colour = {r = r, g = g, b = b, a = a} + in + loopX (grid, x, ex, y, ey, colour) + end + end +end diff --git a/fcore/parsing/parsing.md b/fcore/parsing/parsing.md new file mode 100644 index 0000000..68fc58d --- /dev/null +++ b/fcore/parsing/parsing.md @@ -0,0 +1,17 @@ +# Parsing + +The parsing functionality is for saving and loading from a custom file format. + +The BNF for the custom file format is below. + +Terminals are surrounded by `**` to the left and right. (rule)+ means "1 o more". + +``` +int ::= (0-9)+ + +item ::= **{** int int int int int int int int **}** + +grid ::= int int **{** (item)+ **}** +``` + +The large number of `int`s in the `item` always follows the order: `x y ex ey r g b a`. diff --git a/fcore/parsing/space-dfa.sml b/fcore/parsing/space-dfa.sml new file mode 100644 index 0000000..bc97120 --- /dev/null +++ b/fcore/parsing/space-dfa.sml @@ -0,0 +1,34 @@ +structure SpaceDfa = +struct + val dead = 0 + val start = 1 + val final = 2 + + fun makeDead _ = 0 + + fun makeStart i = + let + val chr = Char.chr i + in + if chr = #" " orelse chr = #"\n" + then final + else dead + end + + val deadTable = Vector.tabulate (255, makeDead) + val startTable = Vector.tabulate (255, makeStart) + val finalTable = startTable + + val tables = #[deadTable, startTable, finalTable] + + fun isFinal state = + state = final + + fun next (state, chr) = + let + val table = Vector.sub (tables, state) + val idx = Char.ord chr + in + Vector.sub (table, idx) + end +end diff --git a/fcore/parsing/tokens.sml b/fcore/parsing/tokens.sml new file mode 100644 index 0000000..bd6d619 --- /dev/null +++ b/fcore/parsing/tokens.sml @@ -0,0 +1,8 @@ +structure Tokens = +struct + datatype t = + L_BRACE + | R_BRACE + | INT of int + | X +end