| License | MIT |
|---|---|
| Maintainer | maxence.pierre@epitech.eu, florian.grave@epitech.eu, hugo.duda@epitech.eu |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
ParserHelper
Description
Provides helper functions for parsing tokens
If an unexpected token is found or if the syntax is invalid, the parsing functions return an pretty formatted error message.
Synopsis
- parseBuiltinType :: Parser BuiltinType
- parseIdentifier :: Parser Identifier
- parsePVDE :: Parser ParmVarDeclExpr
- parsePVDEList :: Parser [ParmVarDeclExpr]
- parseAssignOp :: Parser AssignOp
- parseParmCallDecl :: Decl -> Parser ParmCallDecl
- parseCallExprDecl :: Decl -> Parser CallExprDecl
- parseVarDeclStmt :: Decl -> Parser VarDeclStmt
- parseDeclStmt :: Decl -> Parser DeclStmt
- parseBinaryOp :: Parser BinaryOp
- parseListLiteral :: Parser Literal
- parseListElements :: Parser [Literal]
- errorAt :: (Int, Int) -> String -> Either String a
- expectToken :: Token -> String -> Parser ()
- parseMaybe :: Parser a -> Parser (Maybe a)
- getPos :: Int -> [SingleToken] -> (Int, Int)
- addIfVarExpr :: (Int, Int) -> Stmt -> [ParmVarDeclExpr] -> Either String [ParmVarDeclExpr]
- findString :: Eq a => [a] -> [a] -> Maybe Int
Documentation
parseBuiltinType :: Parser BuiltinType Source #
Takes a '[SingleToken]' as parameter and
returns a Either String.BuiltinType
On success, this function returns a .BuiltinType
On failure, this function returns a pretty formatted message error.
This function is used to parse a Rizz Builtin type (Int, Bool, Char, ...).
parseIdentifier :: Parser Identifier Source #
Takes a '[SingleToken]' as parameter and
returns a Either String.Identifier
On success, this function returns a .Identifier
On failure, this function returns a pretty formatted message error.
This function is used to parse an Identifier (e.g.: foo, bar, a, ...).
parsePVDE :: Parser ParmVarDeclExpr Source #
Takes a '[SingleToken]' as parameter and
returns a Either String.ParmVarDeclExpr
On success, this function returns a .ParmVarDeclExpr
On failure, this function returns a pretty formatted message error.
This function is used to parse a ParmVarDeclExpr (composed of a BuiltinType and an Identifier).
parsePVDEList :: Parser [ParmVarDeclExpr] Source #
Takes a '[SingleToken]' as parameter and
returns a Either String'[A.ParmVarDeclExpr]'.
On success, this function returns a '[A.ParmVarDeclExpr]'.
On failure, this function returns a pretty formatted message error.
This function is used to parse a list of ParmVarDeclExpr, typically function parameters.
parseAssignOp :: Parser AssignOp Source #
Takes a '[SingleToken]' as parameter and
returns a Either String'[T.AssignOp]'.
On success, this function returns a .AssignOp
On failure, this function returns a pretty formatted message error.
This function is used to parse an assignment operator.
parseParmCallDecl :: Decl -> Parser ParmCallDecl Source #
Takes an and a Decl'[SingleToken]' as parameter and
returns a Either String.ParmCallDecl
On success, this function returns a .ParmCallDecl
On failure, this function returns a pretty formatted message error.
This function is used to parse the a single parameter of a function call (e.g.: 4, c, foo(), ...).
parseCallExprDecl :: Decl -> Parser CallExprDecl Source #
Takes an and a Decl'[SingleToken]' as parameter and
returns a Either String.CallExprDecl
On success, this function returns a .CallExprDecl
On failure, this function returns a pretty formatted message error.
This function is used to parse a function call.
parseVarDeclStmt :: Decl -> Parser VarDeclStmt Source #
Takes an and a Decl'[SingleToken]' as parameter and
returns a Either String.VarDeclStmt
On success, this function returns a .VarDeclStmt
On failure, this function returns a pretty formatted message error.
This function is used to parse a variable declaration statement.
parseDeclStmt :: Decl -> Parser DeclStmt Source #
parseBinaryOp :: Parser BinaryOp Source #
Takes a '[SingleToken]' as parameter and
returns a Either String'[T.BinaryOp]'.
On success, this function returns a .BinaryOp
On failure, this function returns a pretty formatted message error.
This function is used to parse a binary operator.
parseListLiteral :: Parser Literal Source #
parseListElements :: Parser [Literal] Source #
Takes a '[SingleToken]' as parameter and
returns a Either String'[T.Literal]'.
On success, this function returns a '[T.Litteral]'.
On failure, this function returns a pretty formatted message error.
This function is used to parse a list of literal values.
expectToken :: Token -> String -> Parser () Source #
Takes a , a Token message and a StringParser list as parameters and returns a Either SingleToken ((), [String]).SingleToken
On success, this function returns a tuple containing the rest of the stream
On failure, this function returns a pretty formatted error message with line & col position.
parseMaybe :: Parser a -> Parser (Maybe a) Source #
Takes a Parser and a list as parameters and
returns a Either a (Maybe String, [a]).SingleToken
On success, this function returns a tuple containing Just and the rest of the stream.a
On failure, this function returns a tuple containing Nothing and the rest of the stream.
This function is used to parse a expression that can be empty. (e.g.: a forExpr can either be "for(Int a = 0; a < 0; a++)" and "for(;;)" )
getPos :: Int -> [SingleToken] -> (Int, Int) Source #
Takes an and a stream of Integer as parameters,
and returns a tuple of SingleTokenInteger
this function serves as a helper function to get the position of the first or last token in the stream.
addIfVarExpr :: (Int, Int) -> Stmt -> [ParmVarDeclExpr] -> Either String [ParmVarDeclExpr] Source #
Takes a (, Int), an Int'A.Stmt and a list of as parameters and
returns a Either ParmVarDeclExprString'[A.ParmVarDeclExpr]'.
On success, this function returns a '[A.ParmVarDeclExpr]', with the newly added variable in the list.
On failure, this function returns a pretty formatted message error.
This function is used to add a variable to the defined variables.
findString :: Eq a => [a] -> [a] -> Maybe Int Source #