3 {-# LANGUAGE BangPatterns #-} -- required for versions of Happy before 1.18.6
4 {-# OPTIONS -w -Wwarn #-}
5 -- The above warning supression flag is a temporary kludge.
6 -- While working on this module you are encouraged to remove it and fix
7 -- any warnings in the module. See
8 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
11 module Parser (parse) where
13 import Lexer (lex_tok)
14 import ParserM (Token(..), ParserM, run_parser, get_pos, show_pos,
23 %lexer { lex_tok } { TEOF }
31 '(#' { TOpenParenHash }
32 '#)' { THashCloseParen }
37 pseudoop { TPseudoop }
38 primtype { TPrimtype }
40 defaults { TDefaults }
46 genprimop { TGenPrimOp }
47 thats_all_folks { TThatsAllFolks }
48 lowerName { TLowerName $$ }
49 upperName { TUpperName $$ }
51 noBraces { TNoBraces $$ }
56 info : pDefaults pEntries thats_all_folks { Info $1 $2 }
58 pDefaults :: { [Option] }
59 pDefaults : defaults pOptions { $2 }
61 pOptions :: { [Option] }
62 pOptions : pOption pOptions { $1 : $2 }
66 pOption : lowerName '=' false { OptionFalse $1 }
67 | lowerName '=' true { OptionTrue $1 }
68 | lowerName '=' pStuffBetweenBraces { OptionString $1 $3 }
70 pEntries :: { [Entry] }
71 pEntries : pEntry pEntries { $1 : $2 }
75 pEntry : pPrimOpSpec { $1 }
76 | pPrimTypeSpec { $1 }
77 | pPseudoOpSpec { $1 }
80 pPrimOpSpec :: { Entry }
81 pPrimOpSpec : primop upperName string pCategory pType
93 pPrimTypeSpec :: { Entry }
94 pPrimTypeSpec : primtype pType pDesc pWithOptions
95 { PrimTypeSpec { ty = $2, desc = $3, opts = $4 } }
97 pPseudoOpSpec :: { Entry }
98 pPseudoOpSpec : pseudoop string pType pDesc pWithOptions
99 { PseudoOpSpec { name = $2, ty = $3, desc = $4, opts = $5 } }
101 pSection :: { Entry }
102 pSection : section string pDesc { Section { title = $2, desc = $3 } }
104 pWithOptions :: { [Option] }
105 pWithOptions : with pOptions { $2 }
108 pCategory :: { Category }
109 pCategory : dyadic { Dyadic }
110 | monadic { Monadic }
111 | compare { Compare }
112 | genprimop { GenPrimOp }
115 pDesc : pStuffBetweenBraces { $1 }
118 pStuffBetweenBraces :: { String }
119 pStuffBetweenBraces : '{' pInsides '}' { $2 }
121 pInsides :: { String }
122 pInsides : pInside pInsides { $1 ++ $2 }
125 pInside :: { String }
126 pInside : '{' pInsides '}' { "{" ++ $2 ++ "}" }
130 pType : paT '->' pType { TyF $1 $3 }
135 paT : pTycon ppTs { TyApp $1 $2 }
136 | pUnboxedTupleTy { $1 }
137 | '(' pType ')' { $2 }
138 | lowerName { TyVar $1 }
140 pUnboxedTupleTy :: { Ty }
141 pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 }
143 pCommaTypes :: { [Ty] }
144 pCommaTypes : pType ',' pCommaTypes { $1 : $3 }
148 ppTs : ppT ppTs { $1 : $2 }
153 ppT : lowerName { TyVar $1 }
154 | pTycon { TyApp $1 [] }
157 pTycon : upperName { $1 }
161 parse :: String -> Either String Info
162 parse = run_parser parsex