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 integer { TInteger $$ }
52 noBraces { TNoBraces $$ }
57 info : pDefaults pEntries thats_all_folks { Info $1 $2 }
59 pDefaults :: { [Option] }
60 pDefaults : defaults pOptions { $2 }
62 pOptions :: { [Option] }
63 pOptions : pOption pOptions { $1 : $2 }
67 pOption : lowerName '=' false { OptionFalse $1 }
68 | lowerName '=' true { OptionTrue $1 }
69 | lowerName '=' pStuffBetweenBraces { OptionString $1 $3 }
70 | lowerName '=' integer { OptionInteger $1 $3 }
72 pEntries :: { [Entry] }
73 pEntries : pEntry pEntries { $1 : $2 }
77 pEntry : pPrimOpSpec { $1 }
78 | pPrimTypeSpec { $1 }
79 | pPseudoOpSpec { $1 }
82 pPrimOpSpec :: { Entry }
83 pPrimOpSpec : primop upperName string pCategory pType
95 pPrimTypeSpec :: { Entry }
96 pPrimTypeSpec : primtype pType pDesc pWithOptions
97 { PrimTypeSpec { ty = $2, desc = $3, opts = $4 } }
99 pPseudoOpSpec :: { Entry }
100 pPseudoOpSpec : pseudoop string pType pDesc pWithOptions
101 { PseudoOpSpec { name = $2, ty = $3, desc = $4, opts = $5 } }
103 pSection :: { Entry }
104 pSection : section string pDesc { Section { title = $2, desc = $3 } }
106 pWithOptions :: { [Option] }
107 pWithOptions : with pOptions { $2 }
110 pCategory :: { Category }
111 pCategory : dyadic { Dyadic }
112 | monadic { Monadic }
113 | compare { Compare }
114 | genprimop { GenPrimOp }
117 pDesc : pStuffBetweenBraces { $1 }
120 pStuffBetweenBraces :: { String }
121 pStuffBetweenBraces : '{' pInsides '}' { $2 }
123 pInsides :: { String }
124 pInsides : pInside pInsides { $1 ++ $2 }
127 pInside :: { String }
128 pInside : '{' pInsides '}' { "{" ++ $2 ++ "}" }
132 pType : paT '->' pType { TyF $1 $3 }
137 paT : pTycon ppTs { TyApp $1 $2 }
138 | pUnboxedTupleTy { $1 }
139 | '(' pType ')' { $2 }
140 | lowerName { TyVar $1 }
142 pUnboxedTupleTy :: { Ty }
143 pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 }
145 pCommaTypes :: { [Ty] }
146 pCommaTypes : pType ',' pCommaTypes { $1 : $3 }
150 ppTs : ppT ppTs { $1 : $2 }
155 ppT : lowerName { TyVar $1 }
156 | pTycon { TyApp $1 [] }
159 pTycon : upperName { $1 }
163 parse :: String -> Either String Info
164 parse = run_parser parsex