SaplParser.dcl 1.58 KB
Newer Older
1
definition module Sapl.SaplParser
2

3
import Sapl.SaplTokenizer, Sapl.SaplStruct
4
import Data.Error
5
from Data.Map import :: Map
6 7 8

// Cannot be abstract because code generator uses it
:: ParserState = { ps_level 		:: Int
9
				 , ps_constructors  :: Map String ConstructorDef
10
				 , ps_functions		:: Map String [SaplTypedVar]
11
				 , ps_CAFs			:: Map String ()
12
				 , ps_genFuns		:: [FuncType] 			// generated functions during parsing				 
13 14
		      	 }

15
:: ConstructorDef = { index		:: !Int
16
					, nr_cons   :: !Int
17
					, nr_args	:: !Int			// for efficiency
18
					, args		:: [SaplTypedVar]
19 20
					}

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
:: ErrorMsg :== String

/**
* Convert a list of position wrapped tokens into a list of AST per function.
* On error an error message is provided. It is assumed that the tokens encode
* function definitions.
*
* @param a token stream
* @return an [AST] or an error message
*/			
parse :: [PosToken] -> MaybeError ErrorMsg ([FuncType], ParserState) 

/**
* Convert a list of position wrapped tokens into an AST.
* On error an error message is provided. It is assumed that the tokens encode
* a simple expression.
*
* @param a token stream
* @return an AST, ParserState pair or an error message
*/
parseExpr :: [PosToken] -> MaybeError ErrorMsg (SaplTerm, ParserState) 

/**
* Merge a ParserState record into another, by adding the elements of the Map fields
* to the Map fields of the other structure.
*
* @param first parser state
48
* @param second parser state (supposed to be bigger)
49 50 51
* @return merged parser state
*/
mergeParserStates :: ParserState (Maybe ParserState) -> ParserState