-- 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 Prolog. module AbsProlog where import qualified Prelude as T (String) import qualified Prelude as C ( Eq , Ord , Show , Read , Functor , Foldable , Traversable , Int, Maybe(..) ) import Data.String type Database = Database' BNFC'Position data Database' a = Db a [Clause' a] -- ^ Database ::= Clause deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Clause = Clause' BNFC'Position data Clause' a = Directive a [Predicate' a] -- ^ Clause ::= ":-" Predicate | Fact a (Predicate' a) -- ^ Clause ::= Predicate | Rule a (Predicate' a) [Predicate' a] -- ^ Clause ::= Predicate ":-" Predicate deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Predicate = Predicate' BNFC'Position data Predicate' a = APred a (Atom' a) -- ^ Predicate ::= Atom | CPred a (Atom' a) [Term' a] -- ^ Predicate ::= Atom "(" Term ")" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Term = Term' BNFC'Position data Term' a = Complex a (Atom' a) [Term' a] -- ^ Term ::= Atom "(" Term ")" | TAtom a (Atom' a) -- ^ Term ::= Atom | TList a (List' a) -- ^ Term ::= List | VarT a (Var' a) -- ^ Term ::= Var deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Atom = Atom' BNFC'Position data Atom' a = Atm a LIdent -- ^ Atom ::= LIdent | EAtm a Ident -- ^ Atom ::= "\'" Ident "\'" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Var = Var' BNFC'Position data Var' a = A a Wild -- ^ Var ::= Wild | V a UIdent -- ^ Var ::= UIdent deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type List = List' BNFC'Position data List' a = Cons a [Term' a] (List' a) -- ^ List ::= "[" Term "|" List "]" | ConsV a [Term' a] (Var' a) -- ^ List ::= "[" Term "|" Var "]" | Empty a -- ^ List ::= "[" "]" | Enum a [Term' a] -- ^ List ::= "[" Term "]" 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) newtype UIdent = UIdent T.String deriving (C.Eq, C.Ord, C.Show, C.Read, Data.String.IsString) newtype LIdent = LIdent T.String deriving (C.Eq, C.Ord, C.Show, C.Read, Data.String.IsString) newtype Wild = Wild 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 Database where hasPosition = \case Db p _ -> p instance HasPosition Clause where hasPosition = \case Directive p _ -> p Fact p _ -> p Rule p _ _ -> p instance HasPosition Predicate where hasPosition = \case APred p _ -> p CPred p _ _ -> p instance HasPosition Term where hasPosition = \case Complex p _ _ -> p TAtom p _ -> p TList p _ -> p VarT p _ -> p instance HasPosition Atom where hasPosition = \case Atm p _ -> p EAtm p _ -> p instance HasPosition Var where hasPosition = \case A p _ -> p V p _ -> p instance HasPosition List where hasPosition = \case Cons p _ _ -> p ConsV p _ _ -> p Empty p -> p Enum p _ -> p