Merge branch 'develop-0.6' into convert-loops-to-recursion
Chris Pressey
1 year, 1 month ago
52 | 52 |
Nothing -> Just x
|
53 | 53 |
) choices
|
54 | 54 |
|
|
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 |
|
55 | 63 |
scramble :: [a] -> GenState -> ([a], GenState)
|
56 | 64 |
scramble choices state@Generating{ prng=prng } =
|
57 | 65 |
let
|
|
97 | 105 |
missing@(_:_) ->
|
98 | 106 |
error ("No pre-condition present on these Alt choices: " ++ (depictExprs missing))
|
99 | 107 |
[] ->
|
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)
|
107 | 109 |
where
|
108 | 110 |
genAlt _st [] = Left "no more choices"
|
109 | 111 |
-- we ignore the constraint here because it will be found and applied when we descend into e
|
21 | 21 |
--
|
22 | 22 |
-- Utils
|
23 | 23 |
--
|
|
24 |
|
|
25 |
can (Right _) = True
|
|
26 |
can (Left _) = False
|
24 | 27 |
|
25 | 28 |
expectTerminal :: Char -> ParseState -> ParseResult
|
26 | 29 |
expectTerminal tc (Parsing (c:cs) a)
|
|
50 | 53 |
getApplicableChoices state choices =
|
51 | 54 |
let
|
52 | 55 |
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
|
56 | 57 |
isApplicableChoice _ = False
|
57 | 58 |
in
|
58 | 59 |
filter (isApplicableChoice) preConditionedChoices
|