summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Grammar/PatternMatch.hs
diff options
context:
space:
mode:
authorkrangelov <kr.angelov@gmail.com>2020-02-17 19:29:36 +0100
committerkrangelov <kr.angelov@gmail.com>2020-02-17 19:29:36 +0100
commite15392e5794b8d31ad80b86bf8cc902ebba795d3 (patch)
tree5b61414a8a7de7d32148b65fd545998c626877f7 /src/compiler/GF/Grammar/PatternMatch.hs
parent9604a6309cf82f9471d97b0513467d99d2ef0f15 (diff)
fix: pattern matching on strings should reconstruct the tokens after matching
Diffstat (limited to 'src/compiler/GF/Grammar/PatternMatch.hs')
-rw-r--r--src/compiler/GF/Grammar/PatternMatch.hs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/compiler/GF/Grammar/PatternMatch.hs b/src/compiler/GF/Grammar/PatternMatch.hs
index 845867459..8fdb33408 100644
--- a/src/compiler/GF/Grammar/PatternMatch.hs
+++ b/src/compiler/GF/Grammar/PatternMatch.hs
@@ -73,14 +73,13 @@ tryMatch (p,t) = do
t' <- termForm t
trym p t'
where
-
- isInConstantFormt = True -- tested already in matchPattern
trym p t' =
case (p,t') of
-- (_,(x,Typed e ty,y)) -> trym p (x,e,y) -- Add this? /TH 2013-09-05
(_,(x,Empty,y)) -> trym p (x,K [],y) -- because "" = [""] = []
- (PW, _) | isInConstantFormt -> return [] -- optimization with wildcard
- (PV x, _) | isInConstantFormt -> return [(x,t)]
+ (PW, _) -> return [] -- optimization with wildcard
+ (PV x,([],K s,[])) -> return [(x,words2term (words s))]
+ (PV x, _) -> return [(x,t)]
(PString s, ([],K i,[])) | s==i -> return []
(PInt s, ([],EInt i,[])) | s==i -> return []
(PFloat s,([],EFloat i,[])) | s==i -> return [] --- rounding?
@@ -132,6 +131,11 @@ tryMatch (p,t) = do
_ -> raise (render ("no match in case expr for" <+> t))
+ words2term [] = Empty
+ words2term [w] = K w
+ words2term (w:ws) = C (K w) (words2term ws)
+
+
matchPMSeq (m1,p1) (m2,p2) s = matchPSeq' m1 p1 m2 p2 s
--matchPSeq p1 p2 s = matchPSeq' (0,maxBound::Int) p1 (0,maxBound::Int) p2 s
matchPSeq p1 p2 s = matchPSeq' (lengthBounds p1) p1 (lengthBounds p2) p2 s
@@ -209,4 +213,4 @@ isMatchingForms ps ts = all match (zip ps ts') where
match _ = True
ts' = map appForm ts
--} \ No newline at end of file
+-}