-- File generated by the BNF Converter. -- Parser definition for use with Happy. { {-# OPTIONS_GHC -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-} {-# LANGUAGE PatternSynonyms #-} module ParCore ( happyError , myLexer , pModule , pTdef , pListTdef , pMaybeTy , pCdef , pListTyt , pTyt , pListCdef , pVdefg , pListVdefg , pVdef , pListVdef , pExp2 , pExp1 , pExp , pBind , pListBind , pAlt , pListAlt , pVbind , pListVbind , pTbind , pListTbind , pATbind , pListATbind , pTy2 , pTy1 , pTy , pKind1 , pKind , pLit , pQualIdent ) where import Prelude import qualified AbsCore import LexCore } %name pModule Module %name pTdef Tdef %name pListTdef ListTdef %name pMaybeTy MaybeTy %name pCdef Cdef %name pListTyt ListTyt %name pTyt Tyt %name pListCdef ListCdef %name pVdefg Vdefg %name pListVdefg ListVdefg %name pVdef Vdef %name pListVdef ListVdef %name pExp2 Exp2 %name pExp1 Exp1 %name pExp Exp %name pBind Bind %name pListBind ListBind %name pAlt Alt %name pListAlt ListAlt %name pVbind Vbind %name pListVbind ListVbind %name pTbind Tbind %name pListTbind ListTbind %name pATbind ATbind %name pListATbind ListATbind %name pTy2 Ty2 %name pTy1 Ty1 %name pTy Ty %name pKind1 Kind1 %name pKind Kind %name pLit Lit %name pQualIdent QualIdent %monad { Err } { (>>=) } { return } %tokentype {Token} %token '#' { PT _ (TS _ 1) } '%_' { PT _ (TS _ 2) } '%case' { PT _ (TS _ 3) } '%coerce' { PT _ (TS _ 4) } '%data' { PT _ (TS _ 5) } '%external' { PT _ (TS _ 6) } '%forall' { PT _ (TS _ 7) } '%in' { PT _ (TS _ 8) } '%let' { PT _ (TS _ 9) } '%module' { PT _ (TS _ 10) } '%newtype' { PT _ (TS _ 11) } '%note' { PT _ (TS _ 12) } '%of' { PT _ (TS _ 13) } '%rec' { PT _ (TS _ 14) } '(' { PT _ (TS _ 15) } ')' { PT _ (TS _ 16) } '*' { PT _ (TS _ 17) } '->' { PT _ (TS _ 18) } '.' { PT _ (TS _ 19) } '::' { PT _ (TS _ 20) } ';' { PT _ (TS _ 21) } '=' { PT _ (TS _ 22) } '?' { PT _ (TS _ 23) } '@' { PT _ (TS _ 24) } '\\' { PT _ (TS _ 25) } '{' { PT _ (TS _ 26) } '}' { PT _ (TS _ 27) } L_Ident { PT _ (TV $$) } L_charac { PT _ (TC $$) } L_doubl { PT _ (TD $$) } L_integ { PT _ (TI $$) } L_quoted { PT _ (TL $$) } %% Ident :: { AbsCore.Ident } Ident : L_Ident { AbsCore.Ident $1 } Char :: { Char } Char : L_charac { (read $1 ) :: Char } Double :: { Double } Double : L_doubl { (read $1 ) :: Double } Integer :: { Integer } Integer : L_integ { (read $1 ) :: Integer } String :: { String } String : L_quoted { $1 } Module :: { AbsCore.Module } Module : '%module' Ident ListTdef ListVdefg { AbsCore.Module $2 $3 $4 } Tdef :: { AbsCore.Tdef } Tdef : '%data' QualIdent ListTbind '=' '{' ListCdef '}' { AbsCore.Data $2 $3 $6 } | '%newtype' QualIdent ListTbind MaybeTy { AbsCore.Newtype $2 $3 $4 } ListTdef :: { [AbsCore.Tdef] } ListTdef : {- empty -} { [] } | Tdef ';' ListTdef { (:) $1 $3 } MaybeTy :: { AbsCore.MaybeTy } MaybeTy : {- empty -} { AbsCore.NoTy } | '=' Ty { AbsCore.JustTy $2 } Cdef :: { AbsCore.Cdef } Cdef : QualIdent ListATbind ListTyt { AbsCore.Constr $1 $2 $3 } ListTyt :: { [AbsCore.Tyt] } ListTyt : {- empty -} { [] } | Tyt ListTyt { (:) $1 $2 } Tyt :: { AbsCore.Tyt } Tyt : Ty2 { AbsCore.TT $1 } ListCdef :: { [AbsCore.Cdef] } ListCdef : Cdef { (:[]) $1 } | Cdef ';' ListCdef { (:) $1 $3 } Vdefg :: { AbsCore.Vdefg } Vdefg : '%rec' '{' ListVdef '}' { AbsCore.Rec $3 } | Vdef { AbsCore.Nonrec $1 } ListVdefg :: { [AbsCore.Vdefg] } ListVdefg : {- empty -} { [] } | Vdefg ';' ListVdefg { (:) $1 $3 } Vdef :: { AbsCore.Vdef } Vdef : Ident '::' Ty '=' Exp { AbsCore.VdefU $1 $3 $5 } | QualIdent '::' Ty '=' Exp { AbsCore.VdefQ $1 $3 $5 } ListVdef :: { [AbsCore.Vdef] } ListVdef : Vdef { (:[]) $1 } | Vdef ';' ListVdef { (:) $1 $3 } Exp2 :: { AbsCore.Exp } Exp2 : '(' Exp ')' { $2 } | Ident { AbsCore.Var $1 } | Lit { AbsCore.Litc $1 } | QualIdent { AbsCore.Dcon $1 } Exp1 :: { AbsCore.Exp } Exp1 : Exp1 '@' Ty2 { AbsCore.Appt $1 $3 } | Exp1 Exp2 { AbsCore.App $1 $2 } | Exp2 { $1 } Exp :: { AbsCore.Exp } Exp : '%case' Exp2 '%of' Vbind '{' ListAlt '}' { AbsCore.Case $2 $4 $6 } | '%coerce' Ty2 Exp { AbsCore.Coerce $2 $3 } | '%external' String Ty { AbsCore.External $2 $3 } | '%let' Vdefg '%in' Exp { AbsCore.Let $2 $4 } | '%note' String Exp { AbsCore.Note $2 $3 } | '\\' ListBind '->' Exp { AbsCore.Lams $2 $4 } | Exp1 { $1 } Bind :: { AbsCore.Bind } Bind : '@' Tbind { AbsCore.Tb $2 } | Vbind { AbsCore.Vb $1 } ListBind :: { [AbsCore.Bind] } ListBind : Bind { (:[]) $1 } | Bind ListBind { (:) $1 $2 } Alt :: { AbsCore.Alt } Alt : '%_' '->' Exp { AbsCore.Adefault $3 } | Lit '->' Exp { AbsCore.Alit $1 $3 } | QualIdent ListATbind ListVbind '->' Exp { AbsCore.Acon $1 $2 $3 $5 } ListAlt :: { [AbsCore.Alt] } ListAlt : Alt { (:[]) $1 } | Alt ';' ListAlt { (:) $1 $3 } Vbind :: { AbsCore.Vbind } Vbind : '(' Ident '::' Ty ')' { AbsCore.Vbind $2 $4 } ListVbind :: { [AbsCore.Vbind] } ListVbind : {- empty -} { [] } | Vbind ListVbind { (:) $1 $2 } Tbind :: { AbsCore.Tbind } Tbind : '(' Ident '::' Kind1 ')' { AbsCore.TbindPair $2 $4 } | Ident { AbsCore.TbindLift $1 } ListTbind :: { [AbsCore.Tbind] } ListTbind : {- empty -} { [] } | Tbind ListTbind { (:) $1 $2 } ATbind :: { AbsCore.ATbind } ATbind : '@' Tbind { AbsCore.ATbind $2 } ListATbind :: { [AbsCore.ATbind] } ListATbind : {- empty -} { [] } | ATbind ListATbind { (:) $1 $2 } Ty2 :: { AbsCore.Ty } Ty2 : '(' Ty ')' { $2 } | Ident { AbsCore.Tvar $1 } | QualIdent { AbsCore.Tcon $1 } Ty1 :: { AbsCore.Ty } Ty1 : Ty1 Ty2 { AbsCore.Tapp $1 $2 } | Ty2 { $1 } Ty :: { AbsCore.Ty } Ty : '%forall' ListTbind '.' Ty { AbsCore.Tforalls $2 $4 } | Ty1 { $1 } | Ty1 '->' Ty { AbsCore.TArrow $1 $3 } Kind1 :: { AbsCore.Kind } Kind1 : '#' { AbsCore.Kunlifted } | '(' Kind ')' { $2 } | '*' { AbsCore.Klifted } | '?' { AbsCore.Kopen } Kind :: { AbsCore.Kind } Kind : Kind1 { $1 } | Kind1 '->' Kind { AbsCore.Karrow $1 $3 } Lit :: { AbsCore.Lit } Lit : '(' Char '::' Ty2 ')' { AbsCore.Lchar $2 $4 } | '(' Double '::' Ty2 ')' { AbsCore.Lrational $2 $4 } | '(' Integer '::' Ty2 ')' { AbsCore.Lint $2 $4 } | '(' String '::' Ty2 ')' { AbsCore.Lstring $2 $4 } QualIdent :: { AbsCore.QualIdent } QualIdent : Ident '.' Ident { AbsCore.Qual $1 $3 } { type Err = Either String happyError :: [Token] -> Err a happyError ts = Left $ "syntax error at " ++ tokenPos ts ++ case ts of [] -> [] [Err _] -> " due to lexer error" t:_ -> " before `" ++ (prToken t) ++ "'" myLexer :: String -> [Token] myLexer = tokens }