Module SQLParserTypes

Defines datatypes and corresponding constructor functions, combinators and selectors used by the SQLParser

Author: Julia Krone

Version: 0.1

Summary of exported operations:

newSPM :: Pos -> a -> [Token] -> SPM a  Deterministic 
constructor function for SPM
newEmptySPM :: Pos -> [Token] -> EmptySPM  Deterministic 
constructor function for an EmptySPM
initializeSPM :: a -> EmptySPM -> SPM a  Deterministic 
initializes a SPM - return function of SPMParser Symboltable are passed from the EmptySPM
concatSPMs :: (a -> b -> c) -> SPM a -> SPM b -> SPM c  Deterministic 
hasToken :: EmptySPM -> Bool  Deterministic 
Returns whether the List of Token contained by the given EmptySPM is not empty
setToken :: [Token] -> EmptySPM -> EmptySPM  Deterministic 
Sets the List of Token.
token :: EmptySPM -> [Token]  Deterministic 
Returns the list of Token.
headToken :: EmptySPM -> Token  Deterministic 
Partially defined! Returns first token of the non-empty List of Token.
continue :: EmptySPM -> EmptySPM  Deterministic 
Cuts the first Token of the List without doing anything else.
liftSPM :: (a -> b) -> (EmptySPM -> SPM a) -> EmptySPM -> SPM b  Deterministic 
Lift: Applies a given function to the result of the given parser.
bindSPM :: (EmptySPM -> SPM a) -> (a -> EmptySPM -> SPM b) -> [Token] -> EmptySPM -> SPM b  Deterministic 
Bind-function for SPMParser.
bindDefSPM :: (EmptySPM -> SPM a) -> a -> (a -> EmptySPM -> SPM b) -> [Token] -> EmptySPM -> SPM b  Deterministic 
Bind-function for SPMParser with superior error menagement.
(.~>.) :: (EmptySPM -> Either EmptySPM (SPM a)) -> (EmptySPM -> SPM a) -> EmptySPM -> SPM a  Deterministic 
Concats a terminal-Parser to a SPMParser.
(.<~.) :: (EmptySPM -> SPM a) -> (EmptySPM -> Either EmptySPM (SPM a)) -> EmptySPM -> SPM a  Deterministic 
Concats a SPMParser to a following terminal-Parser.
combineSPMs :: (a -> b -> c) -> (EmptySPM -> SPM a) -> (EmptySPM -> SPM b) -> EmptySPM -> SPM c  Deterministic 
Combines two SPMParsers in an alternate manner: Both parsers are applied independently , the second one taking the list of token altered by the first one.
proceedWith :: Token -> EmptySPM -> EmptySPM  Deterministic 
Drop token until given token or Semi is reached.
proceedWithOneOf :: [Token] -> EmptySPM -> EmptySPM  Deterministic 
Drop Token until one of the token in the list or Semi is reached.
proceedAfter :: Token -> EmptySPM -> EmptySPM  Deterministic 
Drop Token including the given one.
terminal :: Token -> EmptySPM -> Either EmptySPM (SPM a)  Deterministic 
Parses a terminal.
terminalOrProc :: Token -> [Token] -> EmptySPM -> Either EmptySPM (SPM a)  Deterministic 
Alternate terminal-parser: Additionally takes token with which to proceed in case of an error.
terminalOrConsume :: Token -> EmptySPM -> Either EmptySPM (SPM a)  Deterministic 
alternative terminal parser which in case of error consumes all token including the given one
parseError :: String -> EmptySPM -> SPM a  Deterministic 
Returns Error with given message.
emptyTkErr :: EmptySPM -> SPM a  Deterministic 
Returns Standarderror in case the TokenList is empty.

Exported datatypes:


SPM

Datatype for organization of the parsing process used in the monadic structure SPMParser (therefore its name). Note that the SPM itself is not used as a monad here although corresponding functions (satisfying monadic laws) could easily be defined. Consists of the position of integrated Code, a PM which contains the result/errors and warnings that were calculated before and the list of SQLToken which to parse. It is parameterized over a, which represents the result type.

Constructors:


EmptySPM

Datatype for an Empty SQLParserMonad. Same as SPM but without a result.

Constructors:


SPMParser

Monadic structure which is the basic type for parsing process. Takes an EmptySPM and passes it down, parsing the Token and generating the result which is finally passed back. Returns the SPM with the result which is constructed bottom-up.

Type synonym: SPMParser a = EmptySPM -> SPM a


Exported operations:

newSPM :: Pos -> a -> [Token] -> SPM a  Deterministic 

constructor function for SPM

Example call:
(newSPM pos ele tks)
Parameters:
  • pos : position of the integrated Code
  • ele : a value of type a to initialize the PM
  • tks : list of Token which to parse
Returns:
an initialized SQLParserMonad with initialized PM

newEmptySPM :: Pos -> [Token] -> EmptySPM  Deterministic 

constructor function for an EmptySPM

Example call:
(newEmptySPM pos tks)
Parameters:
  • pos : position of the integrated code
  • tks : list of Token which to parse
Returns:
an EmptySPM
Further infos:
  • solution complete, i.e., able to compute all solutions

initializeSPM :: a -> EmptySPM -> SPM a  Deterministic 

initializes a SPM - return function of SPMParser Symboltable are passed from the EmptySPM

concatSPMs :: (a -> b -> c) -> SPM a -> SPM b -> SPM c  Deterministic 

hasToken :: EmptySPM -> Bool  Deterministic 

Returns whether the List of Token contained by the given EmptySPM is not empty

Example call:
(hasToken espm)
Parameters:
  • espm : the EmptySPM
Returns:
False if list is empty, true otherwise

setToken :: [Token] -> EmptySPM -> EmptySPM  Deterministic 

Sets the List of Token.

Example call:
(setToken tks espm)
Parameters:
  • tks : the list of Token
  • espm : the EmptySPM
Returns:
the altered EmptySPM
Further infos:
  • solution complete, i.e., able to compute all solutions

token :: EmptySPM -> [Token]  Deterministic 

Returns the list of Token.

Example call:
(token espm)
Parameters:
  • espm : the EmptySPM
Further infos:
  • solution complete, i.e., able to compute all solutions

headToken :: EmptySPM -> Token  Deterministic 

Partially defined! Returns first token of the non-empty List of Token.

Further infos:
  • partially defined
  • solution complete, i.e., able to compute all solutions

continue :: EmptySPM -> EmptySPM  Deterministic 

Cuts the first Token of the List without doing anything else. Does Nothing if List of Token is empty.

Further infos:
  • solution complete, i.e., able to compute all solutions

liftSPM :: (a -> b) -> (EmptySPM -> SPM a) -> EmptySPM -> SPM b  Deterministic 

Lift: Applies a given function to the result of the given parser.

bindSPM :: (EmptySPM -> SPM a) -> (a -> EmptySPM -> SPM b) -> [Token] -> EmptySPM -> SPM b  Deterministic 

Bind-function for SPMParser. The additional list of Token is for error recovery, normally the follow set of the piece of code that is parsed by the first parser. In case the first parser fails the second one is never invoked, the list of remaining tokes is cut until the first token that is member of the follow set.

bindDefSPM :: (EmptySPM -> SPM a) -> a -> (a -> EmptySPM -> SPM b) -> [Token] -> EmptySPM -> SPM b  Deterministic 

Bind-function for SPMParser with superior error menagement. In case the first parser fails, the second one is invoked with a default value and the tokens set to the next one that is element of the given list (typically the follow-set).

Example call:
(bindDefSPM parserA defEle f toks)
Parameters:
  • parserA : first parser with result type a
  • defEle : default value of type a that is used if first parser fails
  • f : second parser binding the result of the first one
  • toks : list of token to follow with if first parser fails
Returns:
SPM - result of second parser

(.~>.) :: (EmptySPM -> Either EmptySPM (SPM a)) -> (EmptySPM -> SPM a) -> EmptySPM -> SPM a  Deterministic 

Concats a terminal-Parser to a SPMParser. Invokes the second one just if the first one did not fail.

Further infos:
  • defined as non-associative infix operator with precedence 2

(.<~.) :: (EmptySPM -> SPM a) -> (EmptySPM -> Either EmptySPM (SPM a)) -> EmptySPM -> SPM a  Deterministic 

Concats a SPMParser to a following terminal-Parser. If the terminal-Parser fails, the errors are concatenated to the former otherwise the result of the SPMParser is returned.

Further infos:
  • defined as non-associative infix operator with precedence 2

combineSPMs :: (a -> b -> c) -> (EmptySPM -> SPM a) -> (EmptySPM -> SPM b) -> EmptySPM -> SPM c  Deterministic 

Combines two SPMParsers in an alternate manner: Both parsers are applied independently , the second one taking the list of token altered by the first one. The resulting PMs are combined afterwards.

Example call:
(combineSPMs f)
Parameters:
  • f : function to combine results
Returns:
The resulting SPM

proceedWith :: Token -> EmptySPM -> EmptySPM  Deterministic 

Drop token until given token or Semi is reached.

proceedWithOneOf :: [Token] -> EmptySPM -> EmptySPM  Deterministic 

Drop Token until one of the token in the list or Semi is reached. Tokens are tried in given order. As soon as one token is found, the remaining ones are not tried anymore.

proceedAfter :: Token -> EmptySPM -> EmptySPM  Deterministic 

Drop Token including the given one.

terminal :: Token -> EmptySPM -> Either EmptySPM (SPM a)  Deterministic 

Parses a terminal.

Returns:
EmptySPM with corresponding token consumed if there was no error. A SPM containing the error message otherwise.

terminalOrProc :: Token -> [Token] -> EmptySPM -> Either EmptySPM (SPM a)  Deterministic 

Alternate terminal-parser: Additionally takes token with which to proceed in case of an error.

terminalOrConsume :: Token -> EmptySPM -> Either EmptySPM (SPM a)  Deterministic 

alternative terminal parser which in case of error consumes all token including the given one

parseError :: String -> EmptySPM -> SPM a  Deterministic 

Returns Error with given message.

Example call:
(parseError errMsg espm)
Parameters:
  • errMsg : the error message
  • espm : the EmptySPM
Further infos:
  • solution complete, i.e., able to compute all solutions

emptyTkErr :: EmptySPM -> SPM a  Deterministic 

Returns Standarderror in case the TokenList is empty. Inserts a single semicolon as Tokenlist to avoid subsequent errors.

Further infos:
  • solution complete, i.e., able to compute all solutions