-- 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 ParFstStudio ( happyError , myLexer , pProgram , pDef , pExp , pExp1 , pExp2 , pExp3 , pExp4 , pListDef , pListExp , pListIdent ) where import Prelude import qualified AbsFstStudio import LexFstStudio } %name pProgram_internal Program %name pDef_internal Def %name pExp_internal Exp %name pExp1_internal Exp1 %name pExp2_internal Exp2 %name pExp3_internal Exp3 %name pExp4_internal Exp4 %name pListDef_internal ListDef %name pListExp_internal ListExp %name pListIdent_internal ListIdent %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) } '.o.' { PT _ (TS _ 12) } '.x.' { PT _ (TS _ 13) } '//' { PT _ (TS _ 14) } '0' { 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) } 'import' { PT _ (TS _ 27) } 'main' { PT _ (TS _ 28) } '{' { PT _ (TS _ 29) } '|' { PT _ (TS _ 30) } '||' { PT _ (TS _ 31) } '}' { PT _ (TS _ 32) } '~' { PT _ (TS _ 33) } L_Ident { PT _ (TV _)} L_integ { PT _ (TI _)} L_quoted { PT _ (TL _)} %% Ident :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Ident) } Ident : L_Ident { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Ident (tokenText $1)) } Integer :: { (AbsFstStudio.BNFC'Position, Integer) } Integer : L_integ { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), (read (tokenText $1) ) :: Integer) } String :: { (AbsFstStudio.BNFC'Position, String) } String : L_quoted { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), ((\(PT _ (TL s)) -> s) $1)) } Program :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Program) } Program : ListDef { (fst $1, AbsFstStudio.Prog (fst $1) (snd $1)) } Def :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Def) } Def : '<' 'main' '>' '::=' Exp { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Main (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $5)) } | '<' Ident ListIdent '>' '::=' Exp { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Declaration (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $2) (snd $3) (snd $6)) } | 'import' ListIdent { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Import (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $2)) } Exp :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Exp) } Exp : Exp '->' Exp1 { (fst $1, AbsFstStudio.Replacement (fst $1) (snd $1) (snd $3)) } | Exp '->' Exp1 '//' Exp1 '_' Exp1 { (fst $1, AbsFstStudio.CSReplacement (fst $1) (snd $1) (snd $3) (snd $5) (snd $7)) } | Exp '->' Exp1 '||' Exp1 '_' Exp1 { (fst $1, AbsFstStudio.CReplacement (fst $1) (snd $1) (snd $3) (snd $5) (snd $7)) } | Exp '.o.' Exp1 { (fst $1, AbsFstStudio.Composition (fst $1) (snd $1) (snd $3)) } | Exp '.x.' Exp1 { (fst $1, AbsFstStudio.CrossProduct (fst $1) (snd $1) (snd $3)) } | Exp '=>' Exp1 '_' Exp1 { (fst $1, AbsFstStudio.Restriction (fst $1) (snd $1) (snd $3) (snd $5)) } | Exp '@->' Exp1 { (fst $1, AbsFstStudio.LongReplace (fst $1) (snd $1) (snd $3)) } | Exp1 { (fst $1, (snd $1)) } Exp1 :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Exp) } Exp1 : Exp1 '&' Exp2 { (fst $1, AbsFstStudio.Intersect (fst $1) (snd $1) (snd $3)) } | Exp1 '-' Exp2 { (fst $1, AbsFstStudio.Minus (fst $1) (snd $1) (snd $3)) } | Exp1 '|' Exp2 { (fst $1, AbsFstStudio.Union (fst $1) (snd $1) (snd $3)) } | Exp2 { (fst $1, (snd $1)) } | Exp2 '...' Exp2 { (fst $1, AbsFstStudio.Markup (fst $1) (snd $1) (snd $3)) } Exp2 :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Exp) } Exp2 : Exp2 Exp3 { (fst $1, AbsFstStudio.Concat (fst $1) (snd $1) (snd $2)) } | Exp3 { (fst $1, (snd $1)) } Exp3 :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Exp) } Exp3 : '$' Exp4 { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Containment (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $2)) } | '\\' Exp4 { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.TComplement (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $2)) } | '~' Exp4 { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Complement (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $2)) } | Exp4 { (fst $1, (snd $1)) } Exp4 :: { (AbsFstStudio.BNFC'Position, AbsFstStudio.Exp) } Exp4 : '(' Exp ')' { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), (snd $2)) } | '.#.' { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Boundary (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1))) } | '0' { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Epsilon (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1))) } | '<' Ident ListExp '>' { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.AppDecl (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $2) (snd $3)) } | '?' { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Any (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1))) } | '{' String '}' { (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1), AbsFstStudio.Concats (uncurry AbsFstStudio.BNFC'Position (tokenLineCol $1)) (snd $2)) } | String { (fst $1, AbsFstStudio.Symbol (fst $1) (snd $1)) } | String ':' String { (fst $1, AbsFstStudio.Relation (fst $1) (snd $1) (snd $3)) } | Ident { (fst $1, AbsFstStudio.Variable (fst $1) (snd $1)) } | Exp4 '*' { (fst $1, AbsFstStudio.Star (fst $1) (snd $1)) } | Exp4 '+' { (fst $1, AbsFstStudio.Plus (fst $1) (snd $1)) } | Exp4 '^' Integer { (fst $1, AbsFstStudio.NConcat (fst $1) (snd $1) (snd $3)) } ListDef :: { (AbsFstStudio.BNFC'Position, [AbsFstStudio.Def]) } ListDef : {- empty -} { (AbsFstStudio.BNFC'NoPosition, []) } | Def ';' ListDef { (fst $1, (:) (snd $1) (snd $3)) } ListExp :: { (AbsFstStudio.BNFC'Position, [AbsFstStudio.Exp]) } ListExp : {- empty -} { (AbsFstStudio.BNFC'NoPosition, []) } | ',' Exp ListExp { (uncurry BNFC'Position (tokenLineCol $1), (:) (snd $2) (snd $3)) } ListIdent :: { (AbsFstStudio.BNFC'Position, [AbsFstStudio.Ident]) } ListIdent : {- empty -} { (AbsFstStudio.BNFC'NoPosition, []) } | ',' Ident ListIdent { (uncurry BNFC'Position (tokenLineCol $1), (:) (snd $2) (snd $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 -- Entrypoints pProgram :: [Token] -> Err AbsFstStudio.Program pProgram = fmap snd . pProgram_internal pDef :: [Token] -> Err AbsFstStudio.Def pDef = fmap snd . pDef_internal pExp :: [Token] -> Err AbsFstStudio.Exp pExp = fmap snd . pExp_internal pExp1 :: [Token] -> Err AbsFstStudio.Exp pExp1 = fmap snd . pExp1_internal pExp2 :: [Token] -> Err AbsFstStudio.Exp pExp2 = fmap snd . pExp2_internal pExp3 :: [Token] -> Err AbsFstStudio.Exp pExp3 = fmap snd . pExp3_internal pExp4 :: [Token] -> Err AbsFstStudio.Exp pExp4 = fmap snd . pExp4_internal pListDef :: [Token] -> Err [AbsFstStudio.Def] pListDef = fmap snd . pListDef_internal pListExp :: [Token] -> Err [AbsFstStudio.Exp] pListExp = fmap snd . pListExp_internal pListIdent :: [Token] -> Err [AbsFstStudio.Ident] pListIdent = fmap snd . pListIdent_internal }