Improve parsing.
Chris Pressey
2 years ago
54 | 54 |
TODO
|
55 | 55 |
----
|
56 | 56 |
|
57 | |
* Need to understand why the anbncn parser fails when given only "aaabbbccc" with no further characters. (See test suite)
|
58 | 57 |
* Failure should produce nonzero exit code.
|
59 | 58 |
* Terminals should be multi-character in the syntax.
|
60 | 59 |
* Rename "arb" to "param" (?)
|
61 | 60 |
* Allow params to be supplied.
|
62 | |
* `fountain parse` should be able to read the input string from stdin.
|
63 | 61 |
* Check constraints on all branches of an alternation.
|
122 | 122 |
|
123 | 123 |
### Parsing with Constraints
|
124 | 124 |
|
125 | |
TODO: Understand why this needs a space afterwards.
|
|
125 |
This one succeeds because it satisfies all constraints.
|
126 | 126 |
|
127 | 127 |
Goal ::= <. arb n .>
|
128 | 128 |
<. a = 0 .> { "a" <. a += 1 .> } <. a = n .>
|
129 | 129 |
<. b = 0 .> { "b" <. b += 1 .> } <. b = n .>
|
130 | 130 |
<. c = 0 .> { "c" <. c += 1 .> } <. c = n .>
|
131 | 131 |
;
|
132 | |
<=== aaabbbccc
|
133 | |
===> Remaining: " "
|
|
132 |
<=== aaabbbccc
|
|
133 |
===> Success
|
134 | 134 |
|
135 | 135 |
This one fails at the `<. b = n .>` constraint.
|
136 | 136 |
|
9 | 9 |
deriving (Show, Ord, Eq)
|
10 | 10 |
|
11 | 11 |
|
|
12 |
expectTerminal :: Char -> ParseState -> ParseState
|
12 | 13 |
expectTerminal tc (Parsing (c:cs) a) = if c == tc then (Parsing cs a) else Failure
|
|
14 |
expectTerminal tc (Parsing [] a) = Failure
|
13 | 15 |
expectTerminal tc Failure = Failure
|
14 | 16 |
|
15 | 17 |
formatResult (Parsing "" _) = "Success"
|
56 | 56 |
abortWith $ show error
|
57 | 57 |
|
58 | 58 |
loadText fileName = do
|
59 | |
handle <- openFile fileName ReadMode
|
|
59 |
handle <- if fileName == "--" then return stdin else openFile fileName ReadMode
|
60 | 60 |
-- hSetEncoding handle utf8
|
61 | 61 |
text <- hGetContents handle
|
62 | 62 |
return text
|