diff options
| author | krasimir <krasimir@chalmers.se> | 2010-03-18 19:52:45 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2010-03-18 19:52:45 +0000 |
| commit | 985bb550c0b0c02b5e9c29b53e4f19d859b58dc2 (patch) | |
| tree | a8227c1830f169b5ef4d8ff7952c296997bf3f92 /src | |
| parent | f870c4d80f9e1b55a18c54f8119e5ed11f9d14e1 (diff) | |
fix the precedence for patterns ~, - and @
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiler/GF/Grammar/Parser.y | 16 | ||||
| -rw-r--r-- | src/compiler/GF/Grammar/Printer.hs | 12 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/compiler/GF/Grammar/Parser.y b/src/compiler/GF/Grammar/Parser.y index f1b429339..2346953a9 100644 --- a/src/compiler/GF/Grammar/Parser.y +++ b/src/compiler/GF/Grammar/Parser.y @@ -426,7 +426,7 @@ Exp4 | 'pre' '{' String ';' ListAltern '}' { Alts (K $3, $5) } | 'pre' '{' Ident ';' ListAltern '}' { Alts (Vr $3, $5) } | 'strs' '{' ListExp '}' { Strs $3 } - | '#' Patt2 { EPatt $2 } + | '#' Patt3 { EPatt $2 } | 'pattern' Exp5 { EPattType $2 } | 'lincat' Ident Exp5 { ELincat $2 $3 } | 'lin' Ident Exp5 { ELin $2 $3 } @@ -477,18 +477,22 @@ Patt1 :: { Patt } Patt1 : Ident ListPatt { PC $1 $2 } | Ident '.' Ident ListPatt { PP $1 $3 $4 } - | Patt2 '*' { PRep $1 } - | Ident '@' Patt2 { PAs $1 $3 } - | '-' Patt2 { PNeg $2 } + | Patt3 '*' { PRep $1 } | Patt2 { $1 } Patt2 :: { Patt } Patt2 + : Ident '@' Patt3 { PAs $1 $3 } + | '-' Patt3 { PNeg $2 } + | '~' Exp6 { PTilde $2 } + | Patt3 { $1 } + +Patt3 :: { Patt } +Patt3 : '?' { PChar } | '[' String ']' { PChars $2 } | '#' Ident { PMacro $2 } | '#' Ident '.' Ident { PM $2 $4 } - | '~' Exp6 { PTilde $2 } | '_' { PW } | Ident { PV $1 } | Ident '.' Ident { PP $1 $3 [] } @@ -529,7 +533,7 @@ ListPatt PattArg :: { Patt } : Patt2 { $1 } - | '{' Patt2 '}' { PImplArg $2 } + | '{' Patt '}' { PImplArg $2 } Arg :: { [(BindType,Ident)] } Arg diff --git a/src/compiler/GF/Grammar/Printer.hs b/src/compiler/GF/Grammar/Printer.hs index 12f574b52..15afef865 100644 --- a/src/compiler/GF/Grammar/Printer.hs +++ b/src/compiler/GF/Grammar/Printer.hs @@ -190,13 +190,13 @@ ppPatt q d (PAlt p1 p2) = prec d 0 (ppPatt q 0 p1 <+> char '|' <+> ppPatt q 1 p2 ppPatt q d (PSeq p1 p2) = prec d 0 (ppPatt q 0 p1 <+> char '+' <+> ppPatt q 1 p2)
ppPatt q d (PC f ps) = if null ps
then ppIdent f
- else prec d 1 (ppIdent f <+> hsep (map (ppPatt q 2) ps))
+ else prec d 1 (ppIdent f <+> hsep (map (ppPatt q 3) ps))
ppPatt q d (PP f g ps) = if null ps
then ppQIdent q f g
- else prec d 1 (ppQIdent q f g <+> hsep (map (ppPatt q 2) ps))
-ppPatt q d (PRep p) = prec d 1 (ppPatt q 2 p <> char '*')
-ppPatt q d (PAs f p) = prec d 1 (ppIdent f <> char '@' <> ppPatt q 2 p)
-ppPatt q d (PNeg p) = prec d 1 (char '-' <> ppPatt q 2 p)
+ else prec d 1 (ppQIdent q f g <+> hsep (map (ppPatt q 3) ps))
+ppPatt q d (PRep p) = prec d 1 (ppPatt q 3 p <> char '*')
+ppPatt q d (PAs f p) = prec d 2 (ppIdent f <> char '@' <> ppPatt q 3 p)
+ppPatt q d (PNeg p) = prec d 2 (char '-' <> ppPatt q 3 p)
ppPatt q d (PChar) = char '?'
ppPatt q d (PChars s) = brackets (str s)
ppPatt q d (PMacro id) = char '#' <> ppIdent id
@@ -208,7 +208,7 @@ ppPatt q d (PFloat f) = double f ppPatt q d (PString s) = str s
ppPatt q d (PR xs) = braces (hsep (punctuate semi [ppLabel l <+> equals <+> ppPatt q 0 e | (l,e) <- xs]))
ppPatt q d (PImplArg p) = braces (ppPatt q 0 p)
-ppPatt q d (PTilde t) = char '~' <> ppTerm q 6 t
+ppPatt q d (PTilde t) = prec d 2 (char '~' <> ppTerm q 6 t)
ppValue :: TermPrintQual -> Int -> Val -> Doc
ppValue q d (VGen i x) = ppIdent x <> text "{-" <> int i <> text "-}" ---- latter part for debugging
|
