hssqlppp-0.0.6: Sql parser and type checkerSource codeContentsIndex
Database.HsSqlPpp.TypeChecking.TypeChecker
Contents
Annotation type
SQL types
Type errors
Statement info
Additional types
Annotation functions
Annotated tree utils
Description

Contains the data types and functions for annotating an ast and working with annotated trees, including the representations of SQL data types.

Annotations:

  • are attached to some of the ast node data types, but not all of them (yet?);
  • types annotations are attached to most nodes;
  • type errors are attached to the lowest down node that the type error is detected at;
  • nodes who fail the type check or whose type depends on a node with a type error are given the type TypeCheckFailed;
  • each statement has an additional StatementInfo annotation attached to it;
  • the parser fills in the source position nodes, but doesn't do a great job yet.
Synopsis
type Annotation = [AnnotationElement]
data AnnotationElement
= SourcePos String Int Int
| TypeAnnotation Type
| TypeErrorA TypeError
| StatementInfoA StatementInfo
data Type
= ScalarType String
| ArrayType Type
| SetOfType Type
| CompositeType String
| UnnamedCompositeType [(String, Type)]
| DomainType String
| EnumType String
| RowCtor [Type]
| Pseudo PseudoType
| TypeCheckFailed
| UnknownStringLit
data PseudoType
= Any
| AnyArray
| AnyElement
| AnyEnum
| AnyNonArray
| Cstring
| Record
| Trigger
| Void
| Internal
| LanguageHandler
| Opaque
data TypeError
= WrongTypes Type [Type]
| UnknownTypeError Type
| UnknownTypeName String
| NoMatchingOperator String [Type]
| TypelessEmptyArray
| IncompatibleTypeSet [Type]
| IncompatibleTypes Type Type
| ValuesListsMustBeSameLength
| NoRowsGivenForValues
| UnrecognisedIdentifier String
| UnrecognisedRelation String
| UnrecognisedCorrelationName String
| AmbiguousIdentifier String
| ContextError String
| MissingJoinAttribute
| ExpressionMustBeBool
| WrongNumberOfColumns
| MiscError String
data StatementInfo
= DefaultStatementInfo Type
| RelvarInfo CompositeDef
| CreateFunctionInfo FunctionPrototype
| SelectInfo Type
| InsertInfo String Type
| UpdateInfo String Type
| DeleteInfo String
| CreateDomainInfo String Type
| DropInfo [(String, String)]
| DropFunctionInfo [(String, [Type])]
type DomainDefinition = (Type, Type)
type FunctionPrototype = (String, [Type], Type)
data CastContext
type CompositeDef = (String, CompositeFlavour, Type)
data CompositeFlavour
annotateAst :: StatementList -> StatementList
annotateAstScope :: Scope -> StatementList -> StatementList
annotateExpression :: Scope -> Expression -> Expression
getTopLevelTypes :: Annotated a => [a] -> [Type]
getTopLevelInfos :: Annotated a => [a] -> [StatementInfo]
getTypeErrors :: Annotated a => [a] -> [TypeError]
stripAnnotations :: Annotated a => a -> a
Annotation type
type Annotation = [AnnotationElement]Source
Annotation type - one of these is attached to most of the data types used in the ast.
data AnnotationElement Source
the elements of an annotation. Source positions are generated by the parser, the rest come from the separate ast annotation process.
Constructors
SourcePos String Int Int
TypeAnnotation Type
TypeErrorA TypeError
StatementInfoA StatementInfo
show/hide Instances
SQL types
data Type Source
Constructors
ScalarType String
ArrayType Type
SetOfType Type
CompositeType String
UnnamedCompositeType [(String, Type)]
DomainType String
EnumType String
RowCtor [Type]
Pseudo PseudoType
TypeCheckFailed
UnknownStringLit
show/hide Instances
data PseudoType Source
Constructors
Any
AnyArray
AnyElement
AnyEnum
AnyNonArray
Cstring
Record
Trigger
Void
Internal
LanguageHandler
Opaque
show/hide Instances
Type errors
data TypeError Source
Constructors
WrongTypes Type [Type]
UnknownTypeError Type
UnknownTypeName String
NoMatchingOperator String [Type]
TypelessEmptyArray
IncompatibleTypeSet [Type]
IncompatibleTypes Type Type
ValuesListsMustBeSameLength
NoRowsGivenForValues
UnrecognisedIdentifier String
UnrecognisedRelation String
UnrecognisedCorrelationName String
AmbiguousIdentifier String
ContextError String
MissingJoinAttribute
ExpressionMustBeBool
WrongNumberOfColumns
MiscError String
show/hide Instances
Statement info
This is the main annotation attached to each statement. Early days at the moment but will be expanded to provide any type errors lurking inside a statement, any useful types, e.g. the types of each select and subselect/sub query in a statement, any changes to the catalog the statement makes, and possibly much more information.
data StatementInfo Source
Constructors
DefaultStatementInfo Type
RelvarInfo CompositeDef
CreateFunctionInfo FunctionPrototype
SelectInfo Type
InsertInfo String Type
UpdateInfo String Type
DeleteInfo String
CreateDomainInfo String Type
DropInfo [(String, String)]
DropFunctionInfo [(String, [Type])]
show/hide Instances
Additional types
Used in Scope and type checking.
type DomainDefinition = (Type, Type)Source
type FunctionPrototype = (String, [Type], Type)Source
data CastContext Source
show/hide Instances
type CompositeDef = (String, CompositeFlavour, Type)Source
data CompositeFlavour Source
show/hide Instances
Annotation functions
annotateAst :: StatementList -> StatementListSource
Takes an ast, and adds annotations, including types, type errors, and statement info. Type checks against defaultScope.
annotateAstScope :: Scope -> StatementList -> StatementListSource
As annotateAst but you supply an additional scope to add to the defaultScope to type check against. See Scope module for how to read a scope from an existing database so you can type check against it.
annotateExpression :: Scope -> Expression -> ExpressionSource
Testing utility, mainly used to check an expression for type errors or to get its type.
Annotated tree utils
getTopLevelTypesSource
:: Annotated a
=> [a]the type annotations, this list should be the same length as the argument
-> [Type]
run through the ast, and pull the type annotation from each of the top level items.
getTopLevelInfosSource
:: Annotated a
=> [a]
-> [StatementInfo]
Run through the ast given and return a list of statementinfos from the top level items.
getTypeErrors :: Annotated a => [a] -> [TypeError]Source
runs through the ast given and returns a list of all the type errors in the ast. Recurses into all ast nodes to find type errors. This is the function to use to see if an ast has passed the type checking process. Source position information will be added to the return type at some point
stripAnnotations :: Annotated a => a -> aSource
strip all the annotations from a tree. E.g. can be used to compare two asts are the same, ignoring any source position annotation differences.
Produced by Haddock version 2.6.0