From e15392e5794b8d31ad80b86bf8cc902ebba795d3 Mon Sep 17 00:00:00 2001 From: krangelov Date: Mon, 17 Feb 2020 19:29:36 +0100 Subject: [PATCH] fix: pattern matching on strings should reconstruct the tokens after matching --- src/compiler/GF/Grammar/PatternMatch.hs | 14 +++++++++----- 1 file 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 +-}