forked from GitHub/gf-core
fix the precedence for patterns ~, - and @
This commit is contained in:
@@ -426,7 +426,7 @@ Exp4
|
|||||||
| 'pre' '{' String ';' ListAltern '}' { Alts (K $3, $5) }
|
| 'pre' '{' String ';' ListAltern '}' { Alts (K $3, $5) }
|
||||||
| 'pre' '{' Ident ';' ListAltern '}' { Alts (Vr $3, $5) }
|
| 'pre' '{' Ident ';' ListAltern '}' { Alts (Vr $3, $5) }
|
||||||
| 'strs' '{' ListExp '}' { Strs $3 }
|
| 'strs' '{' ListExp '}' { Strs $3 }
|
||||||
| '#' Patt2 { EPatt $2 }
|
| '#' Patt3 { EPatt $2 }
|
||||||
| 'pattern' Exp5 { EPattType $2 }
|
| 'pattern' Exp5 { EPattType $2 }
|
||||||
| 'lincat' Ident Exp5 { ELincat $2 $3 }
|
| 'lincat' Ident Exp5 { ELincat $2 $3 }
|
||||||
| 'lin' Ident Exp5 { ELin $2 $3 }
|
| 'lin' Ident Exp5 { ELin $2 $3 }
|
||||||
@@ -477,18 +477,22 @@ Patt1 :: { Patt }
|
|||||||
Patt1
|
Patt1
|
||||||
: Ident ListPatt { PC $1 $2 }
|
: Ident ListPatt { PC $1 $2 }
|
||||||
| Ident '.' Ident ListPatt { PP $1 $3 $4 }
|
| Ident '.' Ident ListPatt { PP $1 $3 $4 }
|
||||||
| Patt2 '*' { PRep $1 }
|
| Patt3 '*' { PRep $1 }
|
||||||
| Ident '@' Patt2 { PAs $1 $3 }
|
|
||||||
| '-' Patt2 { PNeg $2 }
|
|
||||||
| Patt2 { $1 }
|
| Patt2 { $1 }
|
||||||
|
|
||||||
Patt2 :: { Patt }
|
Patt2 :: { Patt }
|
||||||
Patt2
|
Patt2
|
||||||
|
: Ident '@' Patt3 { PAs $1 $3 }
|
||||||
|
| '-' Patt3 { PNeg $2 }
|
||||||
|
| '~' Exp6 { PTilde $2 }
|
||||||
|
| Patt3 { $1 }
|
||||||
|
|
||||||
|
Patt3 :: { Patt }
|
||||||
|
Patt3
|
||||||
: '?' { PChar }
|
: '?' { PChar }
|
||||||
| '[' String ']' { PChars $2 }
|
| '[' String ']' { PChars $2 }
|
||||||
| '#' Ident { PMacro $2 }
|
| '#' Ident { PMacro $2 }
|
||||||
| '#' Ident '.' Ident { PM $2 $4 }
|
| '#' Ident '.' Ident { PM $2 $4 }
|
||||||
| '~' Exp6 { PTilde $2 }
|
|
||||||
| '_' { PW }
|
| '_' { PW }
|
||||||
| Ident { PV $1 }
|
| Ident { PV $1 }
|
||||||
| Ident '.' Ident { PP $1 $3 [] }
|
| Ident '.' Ident { PP $1 $3 [] }
|
||||||
@@ -529,7 +533,7 @@ ListPatt
|
|||||||
|
|
||||||
PattArg :: { Patt }
|
PattArg :: { Patt }
|
||||||
: Patt2 { $1 }
|
: Patt2 { $1 }
|
||||||
| '{' Patt2 '}' { PImplArg $2 }
|
| '{' Patt '}' { PImplArg $2 }
|
||||||
|
|
||||||
Arg :: { [(BindType,Ident)] }
|
Arg :: { [(BindType,Ident)] }
|
||||||
Arg
|
Arg
|
||||||
|
|||||||
@@ -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 (PSeq p1 p2) = prec d 0 (ppPatt q 0 p1 <+> char '+' <+> ppPatt q 1 p2)
|
||||||
ppPatt q d (PC f ps) = if null ps
|
ppPatt q d (PC f ps) = if null ps
|
||||||
then ppIdent f
|
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
|
ppPatt q d (PP f g ps) = if null ps
|
||||||
then ppQIdent q f g
|
then ppQIdent q f g
|
||||||
else prec d 1 (ppQIdent q f g <+> hsep (map (ppPatt q 2) ps))
|
else prec d 1 (ppQIdent q f g <+> hsep (map (ppPatt q 3) ps))
|
||||||
ppPatt q d (PRep p) = prec d 1 (ppPatt q 2 p <> char '*')
|
ppPatt q d (PRep p) = prec d 1 (ppPatt q 3 p <> char '*')
|
||||||
ppPatt q d (PAs f p) = prec d 1 (ppIdent f <> char '@' <> ppPatt q 2 p)
|
ppPatt q d (PAs f p) = prec d 2 (ppIdent f <> char '@' <> ppPatt q 3 p)
|
||||||
ppPatt q d (PNeg p) = prec d 1 (char '-' <> ppPatt q 2 p)
|
ppPatt q d (PNeg p) = prec d 2 (char '-' <> ppPatt q 3 p)
|
||||||
ppPatt q d (PChar) = char '?'
|
ppPatt q d (PChar) = char '?'
|
||||||
ppPatt q d (PChars s) = brackets (str s)
|
ppPatt q d (PChars s) = brackets (str s)
|
||||||
ppPatt q d (PMacro id) = char '#' <> ppIdent id
|
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 (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 (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 (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 :: TermPrintQual -> Int -> Val -> Doc
|
||||||
ppValue q d (VGen i x) = ppIdent x <> text "{-" <> int i <> text "-}" ---- latter part for debugging
|
ppValue q d (VGen i x) = ppIdent x <> text "{-" <> int i <> text "-}" ---- latter part for debugging
|
||||||
|
|||||||
Reference in New Issue
Block a user