-- Haskel data types for the abstract syntax. -- Generated by the BNF converter. {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE PatternSynonyms #-} -- | The abstract syntax of language FstStudio. module AbsFstStudio where import qualified Prelude as T (Integer, String) import qualified Prelude as C ( Eq , Ord , Show , Read , Functor , Foldable , Traversable , Int, Maybe(..) ) import Data.String type Program = Program' BNFC'Position data Program' a = Prog a [Def' a] -- ^ Program ::= Def deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Def = Def' BNFC'Position data Def' a = Declaration a Ident [Ident] (Exp' a) -- ^ Def ::= "<" Ident Ident ">" "::=" Exp | Import a [Ident] -- ^ Def ::= "import" Ident | Main a (Exp' a) -- ^ Def ::= "<" "main" ">" "::=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Exp = Exp' BNFC'Position data Exp' a = Any a -- ^ Exp ::= "?" | AppDecl a Ident [Exp' a] -- ^ Exp ::= "<" Ident Exp ">" | Boundary a -- ^ Exp ::= ".#." | CReplacement a (Exp' a) (Exp' a) (Exp' a) (Exp' a) -- ^ Exp ::= Exp "->" Exp1 "||" Exp1 "_" Exp1 | CSReplacement a (Exp' a) (Exp' a) (Exp' a) (Exp' a) -- ^ Exp ::= Exp "->" Exp1 "//" Exp1 "_" Exp1 | Complement a (Exp' a) -- ^ Exp ::= "~" Exp4 | Composition a (Exp' a) (Exp' a) -- ^ Exp ::= Exp ".o." Exp1 | Concat a (Exp' a) (Exp' a) -- ^ Exp ::= Exp2 Exp3 | Concats a T.String -- ^ Exp ::= "{" String "}" | Containment a (Exp' a) -- ^ Exp ::= "$" Exp4 | CrossProduct a (Exp' a) (Exp' a) -- ^ Exp ::= Exp ".x." Exp1 | Epsilon a -- ^ Exp ::= "0" | Intersect a (Exp' a) (Exp' a) -- ^ Exp ::= Exp1 "&" Exp2 | LongReplace a (Exp' a) (Exp' a) -- ^ Exp ::= Exp "@->" Exp1 | Markup a (Exp' a) (Exp' a) -- ^ Exp ::= Exp2 "..." Exp2 | Minus a (Exp' a) (Exp' a) -- ^ Exp ::= Exp1 "-" Exp2 | NConcat a (Exp' a) T.Integer -- ^ Exp ::= Exp4 "^" Integer | Plus a (Exp' a) -- ^ Exp ::= Exp4 "+" | Relation a T.String T.String -- ^ Exp ::= String ":" String | Replacement a (Exp' a) (Exp' a) -- ^ Exp ::= Exp "->" Exp1 | Restriction a (Exp' a) (Exp' a) (Exp' a) -- ^ Exp ::= Exp "=>" Exp1 "_" Exp1 | Star a (Exp' a) -- ^ Exp ::= Exp4 "*" | Symbol a T.String -- ^ Exp ::= String | TComplement a (Exp' a) -- ^ Exp ::= "\\" Exp4 | Union a (Exp' a) (Exp' a) -- ^ Exp ::= Exp1 "|" Exp2 | Variable a Ident -- ^ Exp ::= Ident deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) newtype Ident = Ident T.String deriving (C.Eq, C.Ord, C.Show, C.Read, Data.String.IsString) -- | Start position (line, column) of something. type BNFC'Position = C.Maybe (C.Int, C.Int) pattern BNFC'NoPosition :: BNFC'Position pattern BNFC'NoPosition = C.Nothing pattern BNFC'Position :: C.Int -> C.Int -> BNFC'Position pattern BNFC'Position line col = C.Just (line, col) -- | Get the start position of something. class HasPosition a where hasPosition :: a -> BNFC'Position instance HasPosition Program where hasPosition = \case Prog p _ -> p instance HasPosition Def where hasPosition = \case Declaration p _ _ _ -> p Import p _ -> p Main p _ -> p instance HasPosition Exp where hasPosition = \case Any p -> p AppDecl p _ _ -> p Boundary p -> p CReplacement p _ _ _ _ -> p CSReplacement p _ _ _ _ -> p Complement p _ -> p Composition p _ _ -> p Concat p _ _ -> p Concats p _ -> p Containment p _ -> p CrossProduct p _ _ -> p Epsilon p -> p Intersect p _ _ -> p LongReplace p _ _ -> p Markup p _ _ -> p Minus p _ _ -> p NConcat p _ _ -> p Plus p _ -> p Relation p _ _ -> p Replacement p _ _ -> p Restriction p _ _ _ -> p Star p _ -> p Symbol p _ -> p TComplement p _ -> p Union p _ _ -> p Variable p _ -> p