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,
21 %lexer { lex_tok } { TEOF }
29 '(#' { TOpenParenHash }
30 '#)' { THashCloseParen }
35 pseudoop { TPseudoop }
36 primtype { TPrimtype }
38 defaults { TDefaults }
44 genprimop { TGenPrimOp }
45 thats_all_folks { TThatsAllFolks }
46 lowerName { TLowerName $$ }
47 upperName { TUpperName $$ }
49 noBraces { TNoBraces $$ }
54 info : pDefaults pEntries thats_all_folks { Info $1 $2 }
56 pDefaults :: { [Option] }
57 pDefaults : defaults pOptions { $2 }
59 pOptions :: { [Option] }
60 pOptions : pOption pOptions { $1 : $2 }
64 pOption : lowerName '=' false { OptionFalse $1 }
65 | lowerName '=' true { OptionTrue $1 }
66 | lowerName '=' pStuffBetweenBraces { OptionString $1 $3 }
68 pEntries :: { [Entry] }
69 pEntries : pEntry pEntries { $1 : $2 }
73 pEntry : pPrimOpSpec { $1 }
74 | pPrimTypeSpec { $1 }
75 | pPseudoOpSpec { $1 }
78 pPrimOpSpec :: { Entry }
79 pPrimOpSpec : primop upperName string pCategory pType
91 pPrimTypeSpec :: { Entry }
92 pPrimTypeSpec : primtype pType pDesc pWithOptions
93 { PrimTypeSpec { ty = $2, desc = $3, opts = $4 } }
95 pPseudoOpSpec :: { Entry }
96 pPseudoOpSpec : pseudoop string pType pDesc pWithOptions
97 { PseudoOpSpec { name = $2, ty = $3, desc = $4, opts = $5 } }
100 pSection : section string pDesc { Section { title = $2, desc = $3 } }
102 pWithOptions :: { [Option] }
103 pWithOptions : with pOptions { $2 }
106 pCategory :: { Category }
107 pCategory : dyadic { Dyadic }
108 | monadic { Monadic }
109 | compare { Compare }
110 | genprimop { GenPrimOp }
113 pDesc : pStuffBetweenBraces { $1 }
116 pStuffBetweenBraces :: { String }
117 pStuffBetweenBraces : '{' pInsides '}' { $2 }
119 pInsides :: { String }
120 pInsides : pInside pInsides { $1 ++ $2 }
123 pInside :: { String }
124 pInside : '{' pInsides '}' { "{" ++ $2 ++ "}" }
128 pType : paT '->' pType { TyF $1 $3 }
133 paT : pTycon ppTs { TyApp $1 $2 }
134 | pUnboxedTupleTy { $1 }
135 | '(' pType ')' { $2 }
136 | lowerName { TyVar $1 }
138 pUnboxedTupleTy :: { Ty }
139 pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 }
141 pCommaTypes :: { [Ty] }
142 pCommaTypes : pType ',' pCommaTypes { $1 : $3 }
146 ppTs : ppT ppTs { $1 : $2 }
151 ppT : lowerName { TyVar $1 }
152 | pTycon { TyApp $1 [] }
155 pTycon : upperName { $1 }
159 parse :: String -> Either String Info
160 parse = run_parser parsex