summaryrefslogtreecommitdiff
path: root/src/GF/CFGM/ParCFG.y
diff options
context:
space:
mode:
authorbringert <unknown>2004-08-23 07:51:36 +0000
committerbringert <unknown>2004-08-23 07:51:36 +0000
commit65f012d15513814bd2cc4ad74f54edd35ade13fe (patch)
tree089419071773038e8357a6b97a9ec0481df2a338 /src/GF/CFGM/ParCFG.y
parent25ffe15333a881022047409a1c12a17dd41d1198 (diff)
Added CFGM format (pm -printer=cfgm) and utf8 conversion for pm.
Diffstat (limited to 'src/GF/CFGM/ParCFG.y')
-rw-r--r--src/GF/CFGM/ParCFG.y144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/GF/CFGM/ParCFG.y b/src/GF/CFGM/ParCFG.y
new file mode 100644
index 000000000..09e3a4b5a
--- /dev/null
+++ b/src/GF/CFGM/ParCFG.y
@@ -0,0 +1,144 @@
+-- This Happy file was machine-generated by the BNF converter
+{
+module ParCFG where
+import AbsCFG
+import LexCFG
+import ErrM
+}
+
+%name pGrammars Grammars
+
+%monad { Err } { thenM } { returnM }
+%tokentype { Token }
+
+%token
+ ';' { PT _ (TS ";") }
+ ':' { PT _ (TS ":") }
+ '.' { PT _ (TS ".") }
+ '->' { PT _ (TS "->") }
+ '[' { PT _ (TS "[") }
+ ']' { PT _ (TS "]") }
+ ',' { PT _ (TS ",") }
+ '/' { PT _ (TS "/") }
+ '{' { PT _ (TS "{") }
+ '}' { PT _ (TS "}") }
+ '!' { PT _ (TS "!") }
+ 'end' { PT _ (TS "end") }
+ 'grammar' { PT _ (TS "grammar") }
+ 'startcat' { PT _ (TS "startcat") }
+
+L_ident { PT _ (TV $$) }
+L_integ { PT _ (TI $$) }
+L_quoted { PT _ (TL $$) }
+L_err { _ }
+
+
+%%
+
+Ident : L_ident { Ident $1 }
+Integer : L_integ { (read $1) :: Integer }
+String : L_quoted { $1 }
+
+Grammars :: { Grammars }
+Grammars : ListGrammar { Grammars (reverse $1) }
+
+
+Grammar :: { Grammar }
+Grammar : 'grammar' Ident ListFlag ListRule 'end' 'grammar' { Grammar $2 (reverse $3) (reverse $4) }
+
+
+ListGrammar :: { [Grammar] }
+ListGrammar : {- empty -} { [] }
+ | ListGrammar Grammar { flip (:) $1 $2 }
+
+
+Flag :: { Flag }
+Flag : 'startcat' Category { StartCat $2 }
+
+
+ListFlag :: { [Flag] }
+ListFlag : {- empty -} { [] }
+ | ListFlag Flag ';' { flip (:) $1 $2 }
+
+
+Rule :: { Rule }
+Rule : Ident ':' Name Profile '.' Category '->' ListSymbol { Rule $1 $3 $4 $6 (reverse $8) }
+
+
+ListRule :: { [Rule] }
+ListRule : {- empty -} { [] }
+ | ListRule Rule ';' { flip (:) $1 $2 }
+
+
+Profile :: { Profile }
+Profile : '[' ListInts ']' { Profile $2 }
+
+
+Ints :: { Ints }
+Ints : '[' ListInteger ']' { Ints $2 }
+
+
+ListInts :: { [Ints] }
+ListInts : {- empty -} { [] }
+ | Ints { (:[]) $1 }
+ | Ints ',' ListInts { (:) $1 $3 }
+
+
+ListInteger :: { [Integer] }
+ListInteger : {- empty -} { [] }
+ | Integer { (:[]) $1 }
+ | Integer ',' ListInteger { (:) $1 $3 }
+
+
+Symbol :: { Symbol }
+Symbol : Category { CatS $1 }
+ | String { TermS $1 }
+
+
+ListSymbol :: { [Symbol] }
+ListSymbol : {- empty -} { [] }
+ | ListSymbol Symbol { flip (:) $1 $2 }
+
+
+Name :: { Name }
+Name : ListIdentParam Category { Name (reverse $1) $2 }
+
+
+ListIdentParam :: { [IdentParam] }
+ListIdentParam : {- empty -} { [] }
+ | ListIdentParam IdentParam '/' { flip (:) $1 $2 }
+
+
+Category :: { Category }
+Category : IdentParam '.' Ident ListParam { Category $1 $3 (reverse $4) }
+
+
+IdentParam :: { IdentParam }
+IdentParam : Ident '{' ListParam '}' { IdentParam $1 (reverse $3) }
+
+
+Param :: { Param }
+Param : '!' Ident { Param $2 }
+
+
+ListParam :: { [Param] }
+ListParam : {- empty -} { [] }
+ | ListParam Param { flip (:) $1 $2 }
+
+
+
+{
+
+returnM :: a -> Err a
+returnM = return
+
+thenM :: Err a -> (a -> Err b) -> Err b
+thenM = (>>=)
+
+happyError :: [Token] -> Err a
+happyError ts =
+ Bad $ "syntax error at " ++ tokenPos ts ++ if null ts then [] else (" before " ++ unwords (map prToken (take 4 ts)))
+
+myLexer = tokens
+}
+