3 {-# OPTIONS -w -Wwarn #-}
4 -- The above warning supression flag is a temporary kludge.
5 -- While working on this module you are encouraged to remove it and fix
6 -- any warnings in the module. See
7 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
10 module Parser (parse) where
12 import Lexer (lex_tok)
13 import ParserM (Token(..), ParserM, run_parser, get_pos, show_pos,
22 %lexer { lex_tok } { TEOF }
30 '(#' { TOpenParenHash }
31 '#)' { THashCloseParen }
36 pseudoop { TPseudoop }
37 primtype { TPrimtype }
39 defaults { TDefaults }
45 genprimop { TGenPrimOp }
46 thats_all_folks { TThatsAllFolks }
47 lowerName { TLowerName $$ }
48 upperName { TUpperName $$ }
50 noBraces { TNoBraces $$ }
55 info : pDefaults pEntries thats_all_folks { Info $1 $2 }
57 pDefaults :: { [Option] }
58 pDefaults : defaults pOptions { $2 }
60 pOptions :: { [Option] }
61 pOptions : pOption pOptions { $1 : $2 }
65 pOption : lowerName '=' false { OptionFalse $1 }
66 | lowerName '=' true { OptionTrue $1 }
67 | lowerName '=' pStuffBetweenBraces { OptionString $1 $3 }
69 pEntries :: { [Entry] }
70 pEntries : pEntry pEntries { $1 : $2 }
74 pEntry : pPrimOpSpec { $1 }
75 | pPrimTypeSpec { $1 }
76 | pPseudoOpSpec { $1 }
79 pPrimOpSpec :: { Entry }
80 pPrimOpSpec : primop upperName string pCategory pType
92 pPrimTypeSpec :: { Entry }
93 pPrimTypeSpec : primtype pType pDesc pWithOptions
94 { PrimTypeSpec { ty = $2, desc = $3, opts = $4 } }
96 pPseudoOpSpec :: { Entry }
97 pPseudoOpSpec : pseudoop string pType pDesc pWithOptions
98 { PseudoOpSpec { name = $2, ty = $3, desc = $4, opts = $5 } }
100 pSection :: { Entry }
101 pSection : section string pDesc { Section { title = $2, desc = $3 } }
103 pWithOptions :: { [Option] }
104 pWithOptions : with pOptions { $2 }
107 pCategory :: { Category }
108 pCategory : dyadic { Dyadic }
109 | monadic { Monadic }
110 | compare { Compare }
111 | genprimop { GenPrimOp }
114 pDesc : pStuffBetweenBraces { $1 }
117 pStuffBetweenBraces :: { String }
118 pStuffBetweenBraces : '{' pInsides '}' { $2 }
120 pInsides :: { String }
121 pInsides : pInside pInsides { $1 ++ $2 }
124 pInside :: { String }
125 pInside : '{' pInsides '}' { "{" ++ $2 ++ "}" }
129 pType : paT '->' pType { TyF $1 $3 }
134 paT : pTycon ppTs { TyApp $1 $2 }
135 | pUnboxedTupleTy { $1 }
136 | '(' pType ')' { $2 }
137 | lowerName { TyVar $1 }
139 pUnboxedTupleTy :: { Ty }
140 pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 }
142 pCommaTypes :: { [Ty] }
143 pCommaTypes : pType ',' pCommaTypes { $1 : $3 }
147 ppTs : ppT ppTs { $1 : $2 }
152 ppT : lowerName { TyVar $1 }
153 | pTycon { TyApp $1 [] }
156 pTycon : upperName { $1 }
160 parse :: String -> Either String Info
161 parse = run_parser parsex