Commit 3dbd6c55 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Fix constant parsing for sets with shared prefix

The constant parser naively failed to parse `a10`, when the set was
`{a1, a10}`, because it would stop parsing after the 1.
parent b38dd561
......@@ -288,10 +288,12 @@ showExp (ExplicitExp names) = show names
showExp (FiniteNatExp n) = "{0.." ++ show n ++ "}"
someName :: MonadParser m => Vector Text -> m Int
someName v =
(V.ifoldr (\i new old -> (L.symbol new *> pure i) <|> old) empty v)
<?> ("a name from {" ++ T.unpack (T.intercalate "," (V.toList v)) ++ "}")
someName v = do
name <- try L.name
label ("name from {" ++
T.unpack (T.intercalate "," (V.toList v)) ++
"}") $ do
maybe empty return (V.elemIndex name v)
instance RefinementInterface Polynomial where
init :: H1 Polynomial -> [Label Polynomial] -> Weight Polynomial
......
......@@ -313,6 +313,11 @@ parseMorphismPointSpec = describe "parseMorphismPoint" $ do
morphp (mkPoly [[Exponential Variable (FiniteNatExp 2)]])
`shouldFailOn` "x: {0: x}"
it "can correctly parse constants from a set with shared prefixes" $ do
morphp (mkPoly [[Const (ExplicitSet (v ["a1", "a10"]))]]) "x: a10"
`shouldParse`
(encoding [(1, mkVal 0 [ConstValue 1])] [])
refineSpec :: Spec
refineSpec = describe "refining" $ do
let morphp fexpr input = snd <$> parseMorphisms (Functor 1 fexpr) "" input
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment