git @ Cat's Eye Technologies Fountain / 83de20e
Merge branch 'develop-0.6' into convert-loops-to-recursion Chris Pressey 1 year, 1 month ago
2 changed file(s) with 13 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
5252 Nothing -> Just x
5353 ) choices
5454
55 getApplicableChoices store choices =
56 let
57 preConditionedChoices = map (\x -> (getPreCondition x, x)) choices
58 isApplicableChoice (Just c, _) = can $ applyConstraint c store
59 isApplicableChoice _ = False
60 in
61 filter (isApplicableChoice) preConditionedChoices
62
5563 scramble :: [a] -> GenState -> ([a], GenState)
5664 scramble choices state@Generating{ prng=prng } =
5765 let
97105 missing@(_:_) ->
98106 error ("No pre-condition present on these Alt choices: " ++ (depictExprs missing))
99107 [] ->
100 let
101 preConditionedChoices = map (\x -> (getPreCondition x, x)) choices
102 isApplicableChoice (Just c, _) = can $ applyConstraint c store
103 isApplicableChoice _ = False
104 applicableChoices = filter (isApplicableChoice) preConditionedChoices
105 in
106 genAlt state applicableChoices
108 genAlt state (getApplicableChoices store choices)
107109 where
108110 genAlt _st [] = Left "no more choices"
109111 -- we ignore the constraint here because it will be found and applied when we descend into e
2121 --
2222 -- Utils
2323 --
24
25 can (Right _) = True
26 can (Left _) = False
2427
2528 expectTerminal :: Char -> ParseState -> ParseResult
2629 expectTerminal tc (Parsing (c:cs) a)
5053 getApplicableChoices state choices =
5154 let
5255 preConditionedChoices = map (\x -> (getPreCondition x, x)) choices
53 isApplicableChoice (Just c, _) = case applyParseConstraint c state of
54 Left _ -> False
55 Right _ -> True
56 isApplicableChoice (Just c, _) = can $ applyParseConstraint c state
5657 isApplicableChoice _ = False
5758 in
5859 filter (isApplicableChoice) preConditionedChoices