As.hs revision d703a61b7fa9f85d92ac8f768d7c290b7c0a41c5
$Id$
Authors: Christian Maeder
Year: 2002
abstract syntax for HasCASL
more liberal than HetCATS/HasCASL/Concrete-Syntax.txt
annotations almost as in HetCATS/CASL/AS_Basic_CASL.hs v 1.8
-}
module As where
import Id
import AS_Annotation
data BasicSpec = BasicSpec [Annoted BasicItem]
deriving (Show,Eq)
data BasicItem = SigItems SigItems
| ProgItems [Annoted ProgEq] [Pos]
-- pos "program", ";"s
| ClassItems Instance [Annoted ClassItem] [Pos]
-- pos "class", ";"s
| GenVarItems [GenVarDecl] [Pos]
-- pos "var", ";"s
| FreeDatatype [Annoted DatatypeDecl] [Pos]
-- pos "free", "type", ";"s
| GenItems [Annoted BasicItem] [Pos]
-- pos "generated" "{", ";"s, "}"
-- or "generated" "type" ";"s
| LocalVarAxioms [GenVarDecl] [Annoted Formula] [Pos]
-- pos "forall" , dots
| AxiomItems [Annoted Formula] [Pos]
-- pos dots
deriving (Show,Eq)
data SigItems = TypeItems Instance [Annoted TypeItem] [Pos] -- including sort
-- pos "type", ";"s
| OpItems [Annoted OpItem] [Pos]
-- pos "op", ";"s
| PredItems [Annoted PredItem] [Pos]
-- pos "pred", ";"s
| Datatype [Annoted DatatypeDecl] [Pos]
-- pos "type", ";"s
deriving (Show,Eq)
-- "instance" indicator
data Instance = Instance | Plain deriving (Show,Eq)
data ClassItem = ClassItem ClassDecl [Annoted BasicItem] [Pos]
-- pos "{", ";"s "}"
deriving (Show,Eq)
data ClassDecl = ClassDecl [ClassName] [Pos]
-- pos ","s
| SubclassDecl [ClassName] Class [Pos]
-- pos ","s, "<"
| ClassDefn ClassName Class [Pos]
-- pos "="
| DownsetDefn ClassName TypeVar Type [Pos]
-- pos " =" "{", dot, "<", typeVar, "}"
deriving (Show,Eq)
data TypeItem = TypeDecl [TypePattern] Kind [Pos]
-- pos ","s
| SubtypeDecl [TypePattern] [Type] [Pos]
-- pos ","s, "<"
| IsoDecl [TypePattern] [Pos]
-- pos "="s
| SubtypeDefn TypePattern Var Type Formula [Pos]
-- pos "=", "{", ":", dot, "}"
| AliasType TypePattern PseudoType [Pos]
-- pos ":="
deriving (Show,Eq)
data TypePattern = TypePattern TypeName [TypeArg] [Pos]
-- pos "("s, ")"s
| TypePatternToken Token
| MixfixTypePattern [TypePattern]
| BracketTypePattern BracketKind [TypePattern] [Pos]
-- pos brackets
| TypePatternArgs [TypeArg]
deriving (Show,Eq)
data PseudoType = SimplePseudoType Type
| PseudoType [TypeArgs] PseudoType [Pos]
-- pos "\" "("s, ")"s, dot
deriving (Show,Eq)
data Type = TypeConstrAppl TypeName Kind [Type] [Pos] -- analysed
| TypeToken Token
| BracketType BracketKind [Type] [Pos]
| KindedType Type Kind Pos
-- pos ":"
| MixfixType [Type]
| TupleType [Type] [Pos]
-- pos "," (between type arguments)
| LazyType Type Pos
-- pos "?"
| ProductType [Type] [Pos]
-- pos crosses
| FunType Type Arrow Type Pos
-- pos arrow
deriving (Show,Eq)
data Arrow = FunArr| PFunArr | ContFunArr | PContFunArr
deriving (Show,Eq)
-- no curried notation for bound variables
data TypeScheme = SimpleTypeScheme Type
| TypeScheme [TypeVarDecl] TypeScheme [Pos]
-- pos "forall", ";"s, dot
deriving (Show,Eq)
data PartialKind = Partial | Total deriving (Show,Eq)
data OpItem = OpDecl [OpName] TypeScheme [OpAttr] [Pos]
-- pos ","s, ":", ","s, "assoc", "comm", "idem", "unit"
| OpDefn OpName [Pattern] TypeScheme Term [Pos]
-- pos "("s, ")"s, ":" or ":?", "="
deriving (Show,Eq)
data PredItem = PredDecl [OpName] TypeScheme [Pos]
-- pos ","s, ":", ","s, "assoc", "comm", "idem", "unit"
| PredDefn OpName [Pattern] Formula [Pos]
-- pos "("s, ")"s, "<=>"
deriving (Show,Eq)
data BinOpAttr = Assoc | Comm | Idem deriving (Show,Eq)
data OpAttr = BinOpAttr BinOpAttr | UnitOpAttr Term deriving (Show,Eq)
data DatatypeDecl = DatatypeDecl
TypePattern
[Annoted Alternative]
(Maybe Class)
[Pos]
-- pos "::=", "|"s, "deriving"
deriving (Show,Eq)
data Alternative = Constructor UninstOpName [Components] PartialKind [Pos]
-- pos: "?"
| Subtype Type SeparatorKind [Pos]
-- pos: "type", "," or "|"
deriving (Show,Eq)
data Components = Selector UninstOpName PartialKind Type SeparatorKind [Pos]
-- pos ",", ":" or ":?"
| NoSelector Type
| NestedComponents [Components] [Pos]
-- pos : "(", ";"s, ")"
deriving (Show,Eq)
data Quantifier = Universal | Existential | Unique
deriving (Show,Eq)
data TypeQual = OfType | AsType | InType deriving (Show,Eq)
data BracketKind = Parens | Squares | Braces deriving (Show,Eq)
data LogOp = NotOp | AndOp | OrOp | ImplOp | EquivOp deriving (Show,Eq)
data EqOp = EqualOp | ExEqualOp deriving (Show,Eq)
-- proper formulae only exist after static analysis
data Formula = TermFormula Term
| ConnectFormula LogOp [Formula] [Pos]
-- pos not, "/\", "\/", impl, "<=>"
| EqFormula EqOp Term Term [Pos]
-- pos "=", "=e="
| DefFormula Term [Pos]
-- pos "def"
| QuantifiedFormula Quantifier [VarDecl] Formula [Pos]
-- pos quantifier, ";"s, dot
| PolyFormula [TypeVarDecl] Formula [Pos]
-- pos "forall", ";"s, dot
deriving (Show,Eq)
-- parse quantified formulae as terms first
-- eases also parsing of formulae in parenthesis
data Term = CondTerm Term Formula Term [Pos]
-- pos "when", "else"
| QualVar Var Type [Pos]
-- pos "(", "var", ":", ")"
| QualOp InstOpName TypeScheme [Pos]
-- pos "(", "op", ":", ")"
| ApplTerm Term Term [Pos] -- analysed
-- pos?
| TupleTerm [Term] [Pos]
-- pos "(", ","s, ")"
| TypedTerm Term TypeQual Type Pos
-- pos ":", "as" or "in"
| QuantifiedTerm Quantifier [GenVarDecl] Term [Pos]
-- pos quantifier, ";"s, dot
-- only "forall" may have a TypeVarDecl
| LambdaTerm [Pattern] PartialKind Term [Pos]
-- pos "\", dot (plus "!")
| CaseTerm Term [ProgEq] [Pos]
-- pos "case", "of", "|"s
| WhereTerm Term [ProgEq] [Pos]
-- pos "where", ";"s
| TermToken Token
| MixfixTerm [Term]
| BracketTerm BracketKind [Term] [Pos]
-- pos brackets, ","s
deriving (Show,Eq)
data Pattern = PatternVars [VarDecl] [Pos]
-- pos ";"s
| PatternConstr InstOpName TypeScheme [Pattern] [Pos]
-- constructor or toplevel operation applied to arguments
-- pos "("s, ")"s
| PatternToken Token
| BracketPattern BracketKind [Pattern] [Pos]
-- pos brackets, ";"s, ","s
| TuplePattern [Pattern] [Pos]
-- pos ","s
| MixfixPattern [Pattern] -- or HO-Pattern
| TypedPattern Pattern Type [Pos]
-- pos ":"
| AsPattern Pattern Pattern [Pos]
-- pos "@"
deriving (Show,Eq)
data ProgEq = ProgEq Pattern Term Pos deriving (Show,Eq)
-- pos "=" (or "->" following case-of)
-- ----------------------------------------------------------------------------
-- (type) var decls
-- ----------------------------------------------------------------------------
data SeparatorKind = Comma | Other deriving (Show,Eq)
data VarDecl = VarDecl Var Type SeparatorKind Pos deriving (Show,Eq)
-- pos "," or ":"
data TypeVarDecl = TypeVarDecl TypeVar Class SeparatorKind Pos
-- pos "," or ":"
deriving (Show,Eq)
data TypeVarDecls = TypeVarDecls [TypeVarDecl] [Pos] deriving (Show,Eq)
-- pos "[", ";"s, "]"
data TypeArg = TypeArg TypeVar ExtClass SeparatorKind Pos
-- pos "," or ":" ("+" or "-" pos is moved to ExtClass)
deriving (Show,Eq)
data TypeArgs = TypeArgs [TypeArg] deriving (Show,Eq)
data GenVarDecl = GenVarDecl VarDecl
| GenTypeVarDecl TypeVarDecl
deriving (Show,Eq)
-- ----------------------------------------------------------------------------
-- class
-- ----------------------------------------------------------------------------
data Variance = CoVar | ContraVar | InVar deriving (Show,Eq)
data ExtClass = ExtClass Class Variance Pos deriving (Show,Eq)
-- pos "+" or "-" (or nullPos)
data ProdClass = ProdClass [ExtClass] [Pos] deriving (Show,Eq)
-- pos crosses
data Kind = Kind [ProdClass] Class [Pos] deriving (Show,Eq)
-- pos "->"s (first order)
data Class = Universe Pos -- pos "type" (or nullPos)
| ClassName ClassName
| Downset Type -- not parsed directly
| Intersection [Class] [Pos]
-- pos "(", ","s, ")"
deriving (Show,Eq)
-- ----------------------------------------------------------------------------
-- op names
-- ----------------------------------------------------------------------------
data OpName = OpName UninstOpName [TypeVarDecls] deriving (Show,Eq)
data Types = Types [Type] [Pos] deriving (Show,Eq) -- [TYPE, ..., TYPE]
data InstOpName = InstOpName UninstOpName [Types] deriving (Show,Eq)
-- ----------------------------------------------------------------------------
-- ids
-- ----------------------------------------------------------------------------
type TypeName = Id
type UninstOpName = Id
type Var = Id
type TypeVar = Token
type ClassName = Token