summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Grammar
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2010-03-18 19:34:30 +0000
committerkrasimir <krasimir@chalmers.se>2010-03-18 19:34:30 +0000
commitf870c4d80f9e1b55a18c54f8119e5ed11f9d14e1 (patch)
tree0aaf19f5156e6f62f9f8f41732432a49aa1c64fc /src/compiler/GF/Grammar
parentd91999dec0bcdbed95fe3977d89f38157389852a (diff)
syntax for inaccessible patterns in GF
Diffstat (limited to 'src/compiler/GF/Grammar')
-rw-r--r--src/compiler/GF/Grammar/Binary.hs2
-rw-r--r--src/compiler/GF/Grammar/Grammar.hs1
-rw-r--r--src/compiler/GF/Grammar/Lexer.x4
-rw-r--r--src/compiler/GF/Grammar/Parser.y6
-rw-r--r--src/compiler/GF/Grammar/Printer.hs1
5 files changed, 11 insertions, 3 deletions
diff --git a/src/compiler/GF/Grammar/Binary.hs b/src/compiler/GF/Grammar/Binary.hs
index 8ac7f4dea..1febdcd46 100644
--- a/src/compiler/GF/Grammar/Binary.hs
+++ b/src/compiler/GF/Grammar/Binary.hs
@@ -209,6 +209,7 @@ instance Binary Patt where
put (PChars x) = putWord8 16 >> put x
put (PMacro x) = putWord8 17 >> put x
put (PM x y) = putWord8 18 >> put (x,y)
+ put (PTilde x) = putWord8 19 >> put x
get = do tag <- getWord8
case tag of
0 -> get >>= \(x,y) -> return (PC x y)
@@ -229,6 +230,7 @@ instance Binary Patt where
16 -> get >>= \x -> return (PChars x)
17 -> get >>= \x -> return (PMacro x)
18 -> get >>= \(x,y) -> return (PM x y)
+ 19 -> get >>= \x -> return (PTilde x)
_ -> decodingError
instance Binary TInfo where
diff --git a/src/compiler/GF/Grammar/Grammar.hs b/src/compiler/GF/Grammar/Grammar.hs
index b39e0f160..371e0ac08 100644
--- a/src/compiler/GF/Grammar/Grammar.hs
+++ b/src/compiler/GF/Grammar/Grammar.hs
@@ -168,6 +168,7 @@ data Patt =
| PAs Ident Patt -- ^ as-pattern: x@p
| PImplArg Patt -- ^ placeholder for pattern for implicit argument @{p}@
+ | PTilde Term -- ^ inaccessible pattern
-- regular expression patterns
| PNeg Patt -- ^ negated pattern: -p
diff --git a/src/compiler/GF/Grammar/Lexer.x b/src/compiler/GF/Grammar/Lexer.x
index b776668a3..492c7ce8e 100644
--- a/src/compiler/GF/Grammar/Lexer.x
+++ b/src/compiler/GF/Grammar/Lexer.x
@@ -23,7 +23,7 @@ $i = [$l $d _ '] -- identifier character
$u = [\0-\255] -- universal: any character
@rsyms = -- symbols and non-identifier-like reserved words
- \; | \= | \{ | \} | \( | \) | \* \* | \: | \- \> | \, | \[ | \] | \- | \. | \| | \% | \? | \< | \> | \@ | \# | \! | \* | \+ | \+ \+ | \\ | \\\\ | \= \> | \_ | \$ | \/
+ \; | \= | \{ | \} | \( | \) | \~ | \* \* | \: | \- \> | \, | \[ | \] | \- | \. | \| | \% | \? | \< | \> | \@ | \# | \! | \* | \+ | \+ \+ | \\ | \\\\ | \= \> | \_ | \$ | \/
:-
"--" [.]* ; -- Toss single line comments
@@ -49,6 +49,7 @@ data Token
| T_int_label
| T_oparen
| T_cparen
+ | T_tilde
| T_star
| T_starstar
| T_plus
@@ -132,6 +133,7 @@ resWords = Map.fromList
, b "$" T_int_label
, b "(" T_oparen
, b ")" T_cparen
+ , b "~" T_tilde
, b "*" T_star
, b "**" T_starstar
, b "+" T_plus
diff --git a/src/compiler/GF/Grammar/Parser.y b/src/compiler/GF/Grammar/Parser.y
index 2a08caa1b..f1b429339 100644
--- a/src/compiler/GF/Grammar/Parser.y
+++ b/src/compiler/GF/Grammar/Parser.y
@@ -35,6 +35,7 @@ import GF.Compile.Update (buildAnyTree)
'$' { T_int_label }
'(' { T_oparen }
')' { T_cparen }
+ '~' { T_tilde }
'*' { T_star }
'**' { T_starstar }
'+' { T_plus }
@@ -487,6 +488,7 @@ Patt2
| '[' String ']' { PChars $2 }
| '#' Ident { PMacro $2 }
| '#' Ident '.' Ident { PM $2 $4 }
+ | '~' Exp6 { PTilde $2 }
| '_' { PW }
| Ident { PV $1 }
| Ident '.' Ident { PP $1 $3 [] }
@@ -526,8 +528,8 @@ ListPatt
| PattArg ListPatt { $1 : $2 }
PattArg :: { Patt }
- : Patt2 { $1 }
- | '{' Patt2 '}' { PImplArg $2 }
+ : Patt2 { $1 }
+ | '{' Patt2 '}' { PImplArg $2 }
Arg :: { [(BindType,Ident)] }
Arg
diff --git a/src/compiler/GF/Grammar/Printer.hs b/src/compiler/GF/Grammar/Printer.hs
index b3b6bbf77..12f574b52 100644
--- a/src/compiler/GF/Grammar/Printer.hs
+++ b/src/compiler/GF/Grammar/Printer.hs
@@ -208,6 +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
ppValue :: TermPrintQual -> Int -> Val -> Doc
ppValue q d (VGen i x) = ppIdent x <> text "{-" <> int i <> text "-}" ---- latter part for debugging