3 module Parser (parse) where
6 import ParserM (Token(..), ParserM, run_parser, get_pos, show_pos,
14 %lexer { lex_tok } { TEOF }
22 '(#' { TOpenParenHash }
23 '#)' { THashCloseParen }
28 pseudoop { TPseudoop }
29 primtype { TPrimtype }
31 defaults { TDefaults }
37 genprimop { TGenPrimOp }
38 thats_all_folks { TThatsAllFolks }
39 lowerName { TLowerName $$ }
40 upperName { TUpperName $$ }
42 noBraces { TNoBraces $$ }
47 info : pDefaults pEntries thats_all_folks { Info $1 $2 }
49 pDefaults :: { [Option] }
50 pDefaults : defaults pOptions { $2 }
52 pOptions :: { [Option] }
53 pOptions : pOption pOptions { $1 : $2 }
57 pOption : lowerName '=' false { OptionFalse $1 }
58 | lowerName '=' true { OptionTrue $1 }
59 | lowerName '=' pStuffBetweenBraces { OptionString $1 $3 }
61 pEntries :: { [Entry] }
62 pEntries : pEntry pEntries { $1 : $2 }
66 pEntry : pPrimOpSpec { $1 }
67 | pPrimTypeSpec { $1 }
68 | pPseudoOpSpec { $1 }
71 pPrimOpSpec :: { Entry }
72 pPrimOpSpec : primop upperName string pCategory pType
84 pPrimTypeSpec :: { Entry }
85 pPrimTypeSpec : primtype pType pDesc pWithOptions
86 { PrimTypeSpec { ty = $2, desc = $3, opts = $4 } }
88 pPseudoOpSpec :: { Entry }
89 pPseudoOpSpec : pseudoop string pType pDesc pWithOptions
90 { PseudoOpSpec { name = $2, ty = $3, desc = $4, opts = $5 } }
93 pSection : section string pDesc { Section { title = $2, desc = $3 } }
95 pWithOptions :: { [Option] }
96 pWithOptions : with pOptions { $2 }
99 pCategory :: { Category }
100 pCategory : dyadic { Dyadic }
101 | monadic { Monadic }
102 | compare { Compare }
103 | genprimop { GenPrimOp }
106 pDesc : pStuffBetweenBraces { $1 }
109 pStuffBetweenBraces :: { String }
110 pStuffBetweenBraces : '{' pInsides '}' { $2 }
112 pInsides :: { String }
113 pInsides : pInside pInsides { $1 ++ $2 }
116 pInside :: { String }
117 pInside : '{' pInsides '}' { "{" ++ $2 ++ "}" }
121 pType : paT '->' pType { TyF $1 $3 }
126 paT : pTycon ppTs { TyApp $1 $2 }
127 | pUnboxedTupleTy { $1 }
128 | '(' pType ')' { $2 }
129 | lowerName { TyVar $1 }
131 pUnboxedTupleTy :: { Ty }
132 pUnboxedTupleTy : '(#' pCommaTypes '#)' { TyUTup $2 }
134 pCommaTypes :: { [Ty] }
135 pCommaTypes : pType ',' pCommaTypes { $1 : $3 }
139 ppTs : ppT ppTs { $1 : $2 }
144 ppT : lowerName { TyVar $1 }
145 | pTycon { TyApp $1 [] }
148 pTycon : upperName { $1 }
152 parse :: String -> Either String Info
153 parse = run_parser parsex