-- 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 ParAlfa ( happyError , myLexer , pListDecl , pListDef , pDecl , pDef , pExp4 , pExp3 , pExp1 , pExp , pExp2 , pArrow , pTyping , pListTyping , pVarDecl , pBound , pListBound , pListVarDecl , pFieldDecl , pListFieldDecl , pBranch , pListBranch , pConstructor , pListConstructor , pIndConstructor , pListIndConstructor , pListExp2 , pBinding , pListBinding , pPackageBody , pOpenArg , pDefAttr , pImport , pListDefAttr , pListAIdent , pListOpenArg , pAIdent ) where import Prelude import qualified AbsAlfa import LexAlfa } %name pListDecl ListDecl %name pListDef ListDef %name pDecl Decl %name pDef Def %name pExp4 Exp4 %name pExp3 Exp3 %name pExp1 Exp1 %name pExp Exp %name pExp2 Exp2 %name pArrow Arrow %name pTyping Typing %name pListTyping ListTyping %name pVarDecl VarDecl %name pBound Bound %name pListBound ListBound %name pListVarDecl ListVarDecl %name pFieldDecl FieldDecl %name pListFieldDecl ListFieldDecl %name pBranch Branch %name pListBranch ListBranch %name pConstructor Constructor %name pListConstructor ListConstructor %name pIndConstructor IndConstructor %name pListIndConstructor ListIndConstructor %name pListExp2 ListExp2 %name pBinding Binding %name pListBinding ListBinding %name pPackageBody PackageBody %name pOpenArg OpenArg %name pDefAttr DefAttr %name pImport Import %name pListDefAttr ListDefAttr %name pListAIdent ListAIdent %name pListOpenArg ListOpenArg %name pAIdent AIdent %monad { Err } { (>>=) } { return } %tokentype {Token} %token '#' { PT _ (TS _ 1) } '(' { PT _ (TS _ 2) } ')' { PT _ (TS _ 3) } ',' { PT _ (TS _ 4) } '->' { PT _ (TS _ 5) } '.' { PT _ (TS _ 6) } '::' { PT _ (TS _ 7) } ';' { PT _ (TS _ 8) } '=' { PT _ (TS _ 9) } '?' { PT _ (TS _ 10) } '@_' { PT _ (TS _ 11) } 'Set' { PT _ (TS _ 12) } 'Type' { PT _ (TS _ 13) } '\\' { PT _ (TS _ 14) } '_' { PT _ (TS _ 15) } 'abstract' { PT _ (TS _ 16) } 'case' { PT _ (TS _ 17) } 'concrete' { PT _ (TS _ 18) } 'data' { PT _ (TS _ 19) } 'idata' { PT _ (TS _ 20) } 'import' { PT _ (TS _ 21) } 'in' { PT _ (TS _ 22) } 'let' { PT _ (TS _ 23) } 'mutual' { PT _ (TS _ 24) } 'of' { PT _ (TS _ 25) } 'open' { PT _ (TS _ 26) } 'package' { PT _ (TS _ 27) } 'postulate' { PT _ (TS _ 28) } 'private' { PT _ (TS _ 29) } 'public' { PT _ (TS _ 30) } 'sig' { PT _ (TS _ 31) } 'struct' { PT _ (TS _ 32) } 'type' { PT _ (TS _ 33) } 'use' { PT _ (TS _ 34) } 'where' { PT _ (TS _ 35) } '{' { PT _ (TS _ 36) } '|' { PT _ (TS _ 37) } '|->' { PT _ (TS _ 38) } '}' { PT _ (TS _ 39) } L_charac { PT _ (TC $$) } L_doubl { PT _ (TD $$) } L_integ { PT _ (TI $$) } L_quoted { PT _ (TL $$) } L_Comment { PT _ (T_Comment $$) } L_Infix { PT _ (T_Infix $$) } L_PIdent { PT _ (T_PIdent _) } %% 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 } Comment :: { AbsAlfa.Comment } Comment : L_Comment { AbsAlfa.Comment $1 } Infix :: { AbsAlfa.Infix } Infix : L_Infix { AbsAlfa.Infix $1 } PIdent :: { AbsAlfa.PIdent } PIdent : L_PIdent { AbsAlfa.PIdent (mkPosToken $1) } ListDecl :: { [AbsAlfa.Decl] } ListDecl : {- empty -} { [] } | Decl { (:[]) $1 } | Decl ';' ListDecl { (:) $1 $3 } ListDef :: { [AbsAlfa.Def] } ListDef : {- empty -} { [] } | Def { (:[]) $1 } | Def ';' ListDef { (:) $1 $3 } Decl :: { AbsAlfa.Decl } Decl : Import { AbsAlfa.DImp $1 } | ListDefAttr Def { AbsAlfa.DDef $1 $2 } Def :: { AbsAlfa.Def } Def : 'data' AIdent ListTyping '=' ListConstructor { AbsAlfa.Data $2 $3 $5 } | 'mutual' '{' ListDef '}' { AbsAlfa.Mutual $3 } | 'open' Exp 'use' ListOpenArg { AbsAlfa.Open $2 $4 } | 'package' AIdent ListTyping 'where' PackageBody { AbsAlfa.Package $2 $3 $5 } | 'postulate' AIdent ListTyping '::' Exp { AbsAlfa.Axiom $2 $3 $5 } | 'type' AIdent ListTyping '=' Exp { AbsAlfa.Type $2 $3 $5 } | Comment { AbsAlfa.Commt $1 } | AIdent '=' Exp { AbsAlfa.Binding $1 $3 } | AIdent ListVarDecl '::' Exp '=' Exp { AbsAlfa.Value $1 $2 $4 $6 } Exp4 :: { AbsAlfa.Exp } Exp4 : '#' Integer { AbsAlfa.EStar $2 } | '(' Exp ')' { $2 } | '?' { AbsAlfa.EMeta } | 'Set' { AbsAlfa.ESet } | 'Type' { AbsAlfa.EType } | '_' { AbsAlfa.EMetaU } | Char { AbsAlfa.EChar $1 } | Double { AbsAlfa.EDouble $1 } | Integer { AbsAlfa.EInt $1 } | String { AbsAlfa.EString $1 } | AIdent { AbsAlfa.EVar $1 } | AIdent '@_' { AbsAlfa.ECon $1 } Exp3 :: { AbsAlfa.Exp } Exp3 : Exp3 '.' AIdent { AbsAlfa.EProj $1 $3 } | Exp4 { $1 } Exp1 :: { AbsAlfa.Exp } Exp1 : 'sig' '{' ListFieldDecl '}' { AbsAlfa.ESig $3 } | 'struct' '{' ListBinding '}' { AbsAlfa.EStr $3 } | Exp1 Exp2 { AbsAlfa.EApp $1 $2 } | Exp2 { $1 } Exp :: { AbsAlfa.Exp } Exp : '\\' VarDecl Arrow Exp { AbsAlfa.EAbs $2 $3 $4 } | '\\' ListAIdent Arrow Exp { AbsAlfa.EAbsUnt $2 $3 $4 } | 'case' Exp 'of' '{' ListBranch '}' { AbsAlfa.ECase $2 $5 } | 'data' ListConstructor { AbsAlfa.ESum $2 } | 'idata' ListVarDecl ListIndConstructor { AbsAlfa.EIData $2 $3 } | 'let' '{' ListDecl '}' 'in' Exp { AbsAlfa.ELet $3 $6 } | 'open' Exp 'use' ListOpenArg 'in' Exp { AbsAlfa.EOpen $2 $4 $6 } | Comment Exp1 { AbsAlfa.ECommL $1 $2 } | VarDecl Arrow Exp { AbsAlfa.EPi $1 $2 $3 } | Exp1 { $1 } | Exp1 Comment { AbsAlfa.ECommR $1 $2 } | Exp1 Infix Exp1 { AbsAlfa.EInfix $1 $2 $3 } | Exp1 Arrow Exp { AbsAlfa.EFun $1 $2 $3 } Exp2 :: { AbsAlfa.Exp } Exp2 : Exp3 { $1 } Arrow :: { AbsAlfa.Arrow } Arrow : '->' { AbsAlfa.AShow } | '|->' { AbsAlfa.AHide } Typing :: { AbsAlfa.Typing } Typing : VarDecl { AbsAlfa.TDecl $1 } | Exp2 { AbsAlfa.TExp $1 } ListTyping :: { [AbsAlfa.Typing] } ListTyping : {- empty -} { [] } | Typing ListTyping { (:) $1 $2 } VarDecl :: { AbsAlfa.VarDecl } VarDecl : '(' ListBound '::' Exp ')' { AbsAlfa.VDecl $2 $4 } Bound :: { AbsAlfa.Bound } Bound : '|' AIdent { AbsAlfa.BHide $2 } | AIdent { AbsAlfa.BVar $1 } ListBound :: { [AbsAlfa.Bound] } ListBound : Bound { (:[]) $1 } | Bound ',' ListBound { (:) $1 $3 } ListVarDecl :: { [AbsAlfa.VarDecl] } ListVarDecl : {- empty -} { [] } | VarDecl ListVarDecl { (:) $1 $2 } FieldDecl :: { AbsAlfa.FieldDecl } FieldDecl : AIdent '::' Exp { AbsAlfa.FDecl $1 $3 } ListFieldDecl :: { [AbsAlfa.FieldDecl] } ListFieldDecl : {- empty -} { [] } | FieldDecl { (:[]) $1 } | FieldDecl ';' ListFieldDecl { (:) $1 $3 } Branch :: { AbsAlfa.Branch } Branch : '(' AIdent Infix AIdent ')' '->' Exp { AbsAlfa.BranchInf $2 $3 $4 $7 } | '(' AIdent ListAIdent ')' '->' Exp { AbsAlfa.BranchCon $2 $3 $6 } | AIdent '->' Exp { AbsAlfa.BranchVar $1 $3 } ListBranch :: { [AbsAlfa.Branch] } ListBranch : {- empty -} { [] } | Branch { (:[]) $1 } | Branch ';' ListBranch { (:) $1 $3 } Constructor :: { AbsAlfa.Constructor } Constructor : AIdent ListTyping { AbsAlfa.Cnstr $1 $2 } ListConstructor :: { [AbsAlfa.Constructor] } ListConstructor : {- empty -} { [] } | Constructor { (:[]) $1 } | Constructor '|' ListConstructor { (:) $1 $3 } IndConstructor :: { AbsAlfa.IndConstructor } IndConstructor : AIdent ListTyping '::' '_' ListExp2 { AbsAlfa.ICnstr $1 $2 $5 } ListIndConstructor :: { [AbsAlfa.IndConstructor] } ListIndConstructor : {- empty -} { [] } | IndConstructor { (:[]) $1 } | IndConstructor '|' ListIndConstructor { (:) $1 $3 } ListExp2 :: { [AbsAlfa.Exp] } ListExp2 : {- empty -} { [] } | Exp2 ListExp2 { (:) $1 $2 } Binding :: { AbsAlfa.Binding } Binding : AIdent '=' Exp { AbsAlfa.Bind $1 $3 } ListBinding :: { [AbsAlfa.Binding] } ListBinding : {- empty -} { [] } | Binding { (:[]) $1 } | Binding ';' ListBinding { (:) $1 $3 } PackageBody :: { AbsAlfa.PackageBody } PackageBody : '{' ListDecl '}' { AbsAlfa.PackageDef $2 } | Exp { AbsAlfa.PackageInst $1 } OpenArg :: { AbsAlfa.OpenArg } OpenArg : ListDefAttr AIdent { AbsAlfa.OArg $1 $2 } | ListDefAttr AIdent '::' Exp { AbsAlfa.OArgT $1 $2 $4 } | ListDefAttr AIdent '::' Exp '=' Exp { AbsAlfa.OArgTD $1 $2 $4 $6 } | ListDefAttr AIdent '=' Exp { AbsAlfa.OArgD $1 $2 $4 } DefAttr :: { AbsAlfa.DefAttr } DefAttr : 'abstract' { AbsAlfa.Abstract } | 'concrete' { AbsAlfa.Concrete } | 'private' { AbsAlfa.Private } | 'public' { AbsAlfa.Public } Import :: { AbsAlfa.Import } Import : 'import' String ';' { AbsAlfa.Import $2 } ListDefAttr :: { [AbsAlfa.DefAttr] } ListDefAttr : {- empty -} { [] } | DefAttr ListDefAttr { (:) $1 $2 } ListAIdent :: { [AbsAlfa.AIdent] } ListAIdent : {- empty -} { [] } | AIdent ListAIdent { (:) $1 $2 } ListOpenArg :: { [AbsAlfa.OpenArg] } ListOpenArg : {- empty -} { [] } | OpenArg { (:[]) $1 } | OpenArg ',' ListOpenArg { (:) $1 $3 } AIdent :: { AbsAlfa.AIdent } AIdent : '(' Infix ')' { AbsAlfa.I $2 } | PIdent { AbsAlfa.F $1 } { 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 }