git @ Cat's Eye Technologies Fountain / 7aa9178
Improve parsing. Chris Pressey 2 years ago
4 changed file(s) with 6 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
5454 TODO
5555 ----
5656
57 * Need to understand why the anbncn parser fails when given only "aaabbbccc" with no further characters. (See test suite)
5857 * Failure should produce nonzero exit code.
5958 * Terminals should be multi-character in the syntax.
6059 * Rename "arb" to "param" (?)
6160 * Allow params to be supplied.
62 * `fountain parse` should be able to read the input string from stdin.
6361 * Check constraints on all branches of an alternation.
122122
123123 ### Parsing with Constraints
124124
125 TODO: Understand why this needs a space afterwards.
125 This one succeeds because it satisfies all constraints.
126126
127127 Goal ::= <. arb n .>
128128 <. a = 0 .> { "a" <. a += 1 .> } <. a = n .>
129129 <. b = 0 .> { "b" <. b += 1 .> } <. b = n .>
130130 <. c = 0 .> { "c" <. c += 1 .> } <. c = n .>
131131 ;
132 <=== aaabbbccc
133 ===> Remaining: " "
132 <=== aaabbbccc
133 ===> Success
134134
135135 This one fails at the `<. b = n .>` constraint.
136136
99 deriving (Show, Ord, Eq)
1010
1111
12 expectTerminal :: Char -> ParseState -> ParseState
1213 expectTerminal tc (Parsing (c:cs) a) = if c == tc then (Parsing cs a) else Failure
14 expectTerminal tc (Parsing [] a) = Failure
1315 expectTerminal tc Failure = Failure
1416
1517 formatResult (Parsing "" _) = "Success"
5656 abortWith $ show error
5757
5858 loadText fileName = do
59 handle <- openFile fileName ReadMode
59 handle <- if fileName == "--" then return stdin else openFile fileName ReadMode
6060 -- hSetEncoding handle utf8
6161 text <- hGetContents handle
6262 return text