Another step towards parsing initial values from the cmdline.
Chris Pressey
2 years ago
93 | 93 |
|
94 | 94 |
|
95 | 95 |
constructState :: [String] -> GenState
|
96 | |
constructState _ = (Generating "" empty) -- FIXME
|
|
96 |
constructState initialParams = Generating "" (constructStore initialParams)
|
97 | 97 |
|
98 | 98 |
generateFrom :: Grammar -> GenState -> GenState
|
99 | 99 |
generateFrom g state = revgen $ gen g state (production (startSymbol g) g)
|
147 | 147 |
|
148 | 148 |
parseFountain :: String -> Either ParseError Grammar
|
149 | 149 |
parseFountain text = parse fountain "" text
|
|
150 |
|
|
151 |
parseConstConstraint :: String -> (Variable, Integer)
|
|
152 |
parseConstConstraint text = case parse unifyConst "" text of
|
|
153 |
Right (UnifyConst v i) -> (v, i)
|
2 | 2 |
import qualified Data.Map as Map
|
3 | 3 |
|
4 | 4 |
import Language.Fountain.Constraint
|
|
5 |
import Language.Fountain.Loader (parseConstConstraint) -- FIXME an unfortunate coupling
|
5 | 6 |
|
6 | 7 |
|
7 | 8 |
data Store = Store {
|
|
14 | 15 |
fetch k st = Map.lookup k (table st)
|
15 | 16 |
insert k v st = st{ table=Map.insert k v (table st), events=("insert":events st) }
|
16 | 17 |
update f k st = st{ table=Map.update f k (table st), events=("update":events st) }
|
|
18 |
|
|
19 |
constructStore :: [String] -> Store
|
|
20 |
constructStore [] = empty
|
|
21 |
constructStore (constConstrainer:rest) =
|
|
22 |
let
|
|
23 |
(k, v) = parseConstConstraint constConstrainer
|
|
24 |
in
|
|
25 |
insert k v $ constructStore rest
|