format files related to parser
This commit is contained in:
@@ -1,17 +1,21 @@
|
|||||||
structure AllDfa =
|
structure AllDfa =
|
||||||
struct
|
struct
|
||||||
type t = {curInt: int, curSpace: int, curBrace: int, lastInt: int,
|
type t =
|
||||||
lastSpace: int, lastBrace: int}
|
{ curInt: int
|
||||||
|
, curSpace: int
|
||||||
|
, curBrace: int
|
||||||
|
, lastInt: int
|
||||||
|
, lastSpace: int
|
||||||
|
, lastBrace: int
|
||||||
|
}
|
||||||
|
|
||||||
val initial: t =
|
val initial: t =
|
||||||
{
|
{ curInt = IntDfa.start
|
||||||
curInt = IntDfa.start,
|
, curSpace = SpaceDfa.start
|
||||||
curSpace = SpaceDfa.start,
|
, curBrace = BraceDfa.start
|
||||||
curBrace = BraceDfa.start,
|
, lastInt = ~1
|
||||||
|
, lastSpace = ~1
|
||||||
lastInt = ~1,
|
, lastBrace = ~1
|
||||||
lastSpace = ~1,
|
|
||||||
lastBrace = ~1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun areAllDead ({curInt, curSpace, curBrace, ...}: t) =
|
fun areAllDead ({curInt, curSpace, curBrace, ...}: t) =
|
||||||
@@ -29,7 +33,12 @@ struct
|
|||||||
val lastSpace = if SpaceDfa.isFinal curSpace then pos else lastSpace
|
val lastSpace = if SpaceDfa.isFinal curSpace then pos else lastSpace
|
||||||
val lastBrace = if BraceDfa.isFinal curBrace then pos else lastBrace
|
val lastBrace = if BraceDfa.isFinal curBrace then pos else lastBrace
|
||||||
in
|
in
|
||||||
{curInt = curInt, curSpace = curSpace, curBrace = curBrace, lastInt =
|
{ curInt = curInt
|
||||||
lastInt, lastBrace = lastBrace, lastSpace = lastSpace}
|
, curSpace = curSpace
|
||||||
|
, curBrace = curBrace
|
||||||
|
, lastInt = lastInt
|
||||||
|
, lastBrace = lastBrace
|
||||||
|
, lastSpace = lastSpace
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,17 +1,12 @@
|
|||||||
structure BraceDfa =
|
structure BraceDfa =
|
||||||
struct
|
struct
|
||||||
val dead = 0
|
val dead = 0
|
||||||
val start = 1
|
val start = 1
|
||||||
val final = 2
|
val final = 2
|
||||||
|
|
||||||
fun makeStart i =
|
fun makeStart i =
|
||||||
let
|
let val chr = Char.chr i
|
||||||
val chr = Char.chr i
|
in if chr = #"{" orelse chr = #"}" then final else dead
|
||||||
in
|
|
||||||
if chr = #"{" orelse chr = #"}" then
|
|
||||||
final
|
|
||||||
else
|
|
||||||
dead
|
|
||||||
end
|
end
|
||||||
|
|
||||||
val deadTable = SpaceDfa.deadTable
|
val deadTable = SpaceDfa.deadTable
|
||||||
@@ -20,8 +15,7 @@ struct
|
|||||||
|
|
||||||
val tables = #[deadTable, startTable, finalTable]
|
val tables = #[deadTable, startTable, finalTable]
|
||||||
|
|
||||||
fun isFinal state =
|
fun isFinal state = state = final
|
||||||
state = final
|
|
||||||
|
|
||||||
fun next (state, chr) =
|
fun next (state, chr) =
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -5,20 +5,17 @@ struct
|
|||||||
val final = 2
|
val final = 2
|
||||||
|
|
||||||
fun makeStart i =
|
fun makeStart i =
|
||||||
let
|
let val chr = Char.chr i
|
||||||
val chr = Char.chr i
|
in if Char.isDigit chr then final else dead
|
||||||
in
|
|
||||||
if Char.isDigit chr then final else dead
|
|
||||||
end
|
end
|
||||||
|
|
||||||
val deadTable = Vector.tabulate (255, fn _ => dead)
|
val deadTable = Vector.tabulate (255, fn _ => dead)
|
||||||
val startTable = Vector.tabulate (255, makeStart)
|
val startTable = Vector.tabulate (255, makeStart)
|
||||||
val finalTable = startTable
|
val finalTable = startTable
|
||||||
|
|
||||||
val tables = #[deadTable, startTable, finalTable]
|
val tables = #[deadTable, startTable, finalTable]
|
||||||
|
|
||||||
fun isFinal state =
|
fun isFinal state = state = final
|
||||||
state = final
|
|
||||||
|
|
||||||
fun next (state, chr) =
|
fun next (state, chr) =
|
||||||
let
|
let
|
||||||
|
|||||||
@@ -3,23 +3,24 @@ struct
|
|||||||
fun make (canvasWidth, canvasHeight) =
|
fun make (canvasWidth, canvasHeight) =
|
||||||
let
|
let
|
||||||
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
val maxPoints = Int.max (canvasWidth, canvasHeight)
|
||||||
val emptyYAxis = Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0})
|
val emptyYAxis = Vector.tabulate (maxPoints, fn _ =>
|
||||||
|
{r = 0, g = 0, b = 0, a = 0})
|
||||||
in
|
in
|
||||||
Vector.tabulate (maxPoints, fn _ => emptyYAxis)
|
Vector.tabulate (maxPoints, fn _ => emptyYAxis)
|
||||||
end
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
fun loopY (yAxis, x, ex, y, ey, colour) =
|
fun loopY (yAxis, x, ex, y, ey, colour) =
|
||||||
if y > ey then yAxis
|
if y > ey then
|
||||||
|
yAxis
|
||||||
else
|
else
|
||||||
let
|
let val yAxis = Vector.update (yAxis, y, colour)
|
||||||
val yAxis = Vector.update (yAxis, y, colour)
|
in loopY (yAxis, x, ex, y + 1, ey, colour)
|
||||||
in
|
|
||||||
loopY (yAxis, x, ex, y + 1, ey, colour)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
fun loopX (grid, x, ex, y, ey, colour) =
|
fun loopX (grid, x, ex, y, ey, colour) =
|
||||||
if x > ex then grid
|
if x > ex then
|
||||||
|
grid
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val yAxis = Vector.sub (grid, x)
|
val yAxis = Vector.sub (grid, x)
|
||||||
|
|||||||
@@ -7,12 +7,8 @@ struct
|
|||||||
fun makeDead _ = 0
|
fun makeDead _ = 0
|
||||||
|
|
||||||
fun makeStart i =
|
fun makeStart i =
|
||||||
let
|
let val chr = Char.chr i
|
||||||
val chr = Char.chr i
|
in if Char.isSpace chr then final else dead
|
||||||
in
|
|
||||||
if Char.isSpace chr
|
|
||||||
then final
|
|
||||||
else dead
|
|
||||||
end
|
end
|
||||||
|
|
||||||
val deadTable = Vector.tabulate (255, makeDead)
|
val deadTable = Vector.tabulate (255, makeDead)
|
||||||
@@ -21,8 +17,7 @@ struct
|
|||||||
|
|
||||||
val tables = #[deadTable, startTable, finalTable]
|
val tables = #[deadTable, startTable, finalTable]
|
||||||
|
|
||||||
fun isFinal state =
|
fun isFinal state = state = final
|
||||||
state = final
|
|
||||||
|
|
||||||
fun next (state, chr) =
|
fun next (state, chr) =
|
||||||
let
|
let
|
||||||
|
|||||||
Reference in New Issue
Block a user