glados-2.0.0: Generic Language And Data Operand Syntax
LicenseMIT
Maintainermaxence.pierre@epitech.eu, florian.grave@epitech.eu, hugo.duda@epitech.eu
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

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 Decl and a '[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 Decl and a '[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 Decl and a '[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 #

Takes an Decl and a '[SingleToken]' as parameter and returns a Either String Stmt.

On success, this function returns a Stmt.

On failure, this function returns a pretty formatted message error.

This function is used to parse an operation on an existing variable.

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 #

Takes a '[SingleToken]' as parameter and returns a Either String Token.

On success, this function returns a Litteral.

On failure, this function returns a pretty formatted message error.

This function is used to parse a list of literal values.

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.

errorAt :: (Int, Int) -> String -> Either String a Source #

Takes a (Int, Int) position and a String message as parameters and returns a Either String a.

This function returns a pretty formatted error message with line & col position.

NOTE: This function is used as an helper to format error messages.

expectToken :: Token -> String -> Parser () Source #

Takes a Token, a String message and a Parser SingleToken list as parameters and returns a Either 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 a and a list as parameters and returns a Either String (Maybe a, [SingleToken]).

On success, this function returns a tuple containing Just a and the rest of the stream.

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 Integer and a stream of SingleToken as parameters, and returns a tuple of Integer

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, Int), an 'A.Stmt and a list of ParmVarDeclExpr as parameters and returns a Either String '[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 #