nw::script::NssParser

struct NssParser

Public Functions

explicit NssParser(StringView view, Context *ctx, Nss *parent = nullptr)
NssToken advance()

Advances the token stream.

bool check(std::initializer_list<NssTokenType> types) const

Checks if next token matches a particular type.

Note

Does not advance the token stream

Parameters:

types – An initializer list of token types

Returns:

True if there is a match

bool check_is_type() const

Checks if next token matches a particular type.

Note

Does not advance the token stream

Returns:

True if there is a match

NssToken consume(NssTokenType type, StringView error)

Consumes a token.

Parameters:
  • typeType of token to consume

  • error – Error message if token type is not matched

Returns:

Matched token

void diagnostic(StringView msg, NssToken token, bool is_warning = false)

Report diagnostic

Parameters:

msg – Message to report

bool is_end() const

Checks if at end of token stream.

bool match(std::initializer_list<NssTokenType> types)

Checks if next token matches a particular type.

Note

Advances the token stream

Parameters:

types – An initializer list of token types

Returns:

True if there is a match

void lex()

Lexes the file.

NssToken lookahead(size_t index) const

Looks ahead in the token stream

Parameters:

index – Index to look ahead to, from current token

NssToken peek() const

Next token in the token stream.

NssToken previous()

Previous token in the token stream.

void synchronize(bool allow_rbrace = false)

Advances token stream after an error.

Expression *parse_expr()
Expression *parse_expr_assign()
Expression *parse_expr_conditional()
Expression *parse_expr_or()
Expression *parse_expr_and()
Expression *parse_expr_bitwise()
Expression *parse_expr_equality()
Expression *parse_expr_relational()
Expression *parse_expr_shift()
Expression *parse_expr_additive()
Expression *parse_expr_multiplicative()
Expression *parse_expr_unary()
Expression *parse_expr_postfix()
Expression *parse_expr_primary()
Expression *parse_expr_group()
Statement *parse_stmt()
BlockStatement *parse_stmt_block()
DoStatement *parse_stmt_do()
ExprStatement *parse_stmt_expr()
IfStatement *parse_stmt_if()
ForStatement *parse_stmt_for()
LabelStatement *parse_stmt_label()
JumpStatement *parse_stmt_jump()
SwitchStatement *parse_stmt_switch()
WhileStatement *parse_stmt_while()
Type parse_type()
Statement *parse_decl()
StructDecl *parse_decl_struct()
Declaration *parse_decl_function_def()
FunctionDecl *parse_decl_function()
VarDecl *parse_decl_param()
Ast parse_program()

Parses script.

Public Members

Context *ctx_ = nullptr
Nss *parent_ = nullptr
StringView view_
Ast ast_
Vector<NssToken> tokens
size_t current_ = 0