12#ifndef COMPILER_AST_PARSER_HPP
13#define COMPILER_AST_PARSER_HPP
53 Parser(
unsigned debug, uint16_t options,
const std::vector<std::string>& lib_env)
noexcept;
68 const Node&
ast()
const noexcept;
77 const std::vector<std::string>&
getImports()
const noexcept;
101 void sugar(std::vector<Token>& tokens)
noexcept;
112 Node parse(std::list<Token>& tokens,
bool authorize_capture =
false,
bool authorize_field_read =
false,
bool in_macro =
false);
160 std::string
seekFile(
const std::string& file);
169 void expect(
bool pred,
const std::string& message,
Token token);
Constants used by ArkScript.
AST node used by the parser, optimizer and compiler.
The lexer, in charge of creating a list of tokens.
A node of an Abstract Syntax Tree for ArkScript.
The parser is responsible of constructing the Abstract Syntax Tree from a token list.
void parseImport(Node &, std::list< Token > &)
void parseBegin(Node &, std::list< Token > &, bool)
void parseLetMut(Node &, Token &, std::list< Token > &, bool)
void parseDel(Node &, std::list< Token > &)
Node atom(const Token &token)
Convert a token to a node.
void sugar(std::vector< Token > &tokens) noexcept
Applying syntactic sugar: {...} => (begin...), [...] => (list ...)
friend std::ostream & operator<<(std::ostream &os, const Parser &P) noexcept
void expect(bool pred, const std::string &message, Token token)
Throw a parse exception is the given predicated is false.
const Node & ast() const noexcept
Return the generated AST.
void parseQuote(Node &, std::list< Token > &, bool)
void feed(const std::string &code, const std::string &filename=ARK_NO_NAME_FILE)
Give the code to parse.
void throwParseError(const std::string &message, Token token)
Throw a parse error related to a token (seek it in the related file and highlight the error)
std::string seekFile(const std::string &file)
Seek a file in the lib folder and everywhere.
std::vector< std::string > m_libenv
void parseFun(Node &, Token &, std::list< Token > &, bool)
void parseSet(Node &, Token &, std::list< Token > &, bool)
void checkForInvalidTokens(Node &, Token &, bool, bool, bool)
void parseIf(Node &, std::list< Token > &, bool)
Node parse(std::list< Token > &tokens, bool authorize_capture=false, bool authorize_field_read=false, bool in_macro=false)
Parse a list of tokens recursively.
std::vector< std::string > m_parent_include
void parseWhile(Node &, Token &, std::list< Token > &, bool)
bool checkForInclude(Node &n, Node &parent, std::size_t pos=0)
Search for all the includes in a given node, in its sub-nodes and replace them by the code of the inc...
Node parseShorthand(Token &, std::list< Token > &, bool)
Token nextToken(std::list< Token > &tokens)
Get the next token if possible, from a list of tokens.
const std::vector< std::string > & getImports() const noexcept
Return the list of files imported by the code given to the parser.
NodeType
The different node types available.
NodeType similarNodetypeFromTokentype(TokenType tt)