|
Yume
|
#include <parser.hpp>

Classes | |
| struct | FnArg |
Public Member Functions | |
| auto | clamped_iterator (const TokenIterator &iter) const -> TokenIterator |
| auto | emit_note (int offset=0, diagnostic::Severity severity=diagnostic::Severity::Note) const -> diagnostic::Note |
| auto | emit_fatal_and_terminate (int offset=0) const noexcept(false) -> diagnostic::Note |
| auto | ts (const VectorTokenIterator &entry) const -> span< Token > |
| template<typename T , typename... Args> | |
| auto | ast_ptr (const VectorTokenIterator &entry, Args &&... args) |
| template<typename T , typename... Args> | |
| auto | ast_ptr (TokenRange &&range, Args &&... args) |
| template<typename T , typename... Args> | |
| auto | make_ast (const VectorTokenIterator &entry, Args &&... args) |
| auto | make_guard (const string &message) const -> ParserStackTrace |
| auto | ignore_separator (source_location location=source_location::current()) -> bool |
Ignore any Separator tokens if any are present. More... | |
| void | expect (Token::Type token_type, source_location location=source_location::current()) const |
If the next token doesn't have the type, token_type, throw a runtime exception. More... | |
| void | require_separator (source_location location=source_location::current()) |
Consume all subsequent Separator tokens. Throws if none were found. More... | |
| void | consume (TokenAtom token_atom, source_location location=source_location::current()) |
| Consume a token of the given type and payload. Throws if it wasn't encountered. More... | |
| auto | try_consume (TokenAtom token_atom, source_location location=source_location::current()) -> bool |
| Attempt to consume a token of the given type and payload. Returns false if it wasn't encountered. More... | |
| auto | try_peek (int ahead, TokenAtom token_atom, source_location location=source_location::current()) const -> bool |
Check if the token ahead by ahead is of the given type and payload. More... | |
| auto | try_peek (int ahead, Token::Type token_type, source_location location=source_location::current()) const -> bool |
Check if the token ahead by ahead is of type token_type. More... | |
| void | consume_with_commas_until (TokenAtom token_atom, std::invocable auto action, const source_location location=source_location::current()) |
Consume tokens until a token of the given type and payload is encountered. action (a no-arg function) is called every time. Between each call, a comma is expected. More... | |
| template<typename T , std::convertible_to< T > U> | |
| void | collect_with_commas_until (TokenAtom token_atom, U(Parser::*action)(), vector< T > &vec, const source_location location=source_location::current()) |
Consume tokens until a token of the given type and payload is encountered. action (a no-arg member function) is called every time and its result is appended to vec. Between each call, a comma is expected. More... | |
| template<typename T , std::convertible_to< T > U> | |
| auto | collect_with_commas_until (TokenAtom token_atom, U(Parser::*action)(), const source_location location=source_location::current()) -> vector< T > |
Consume tokens until a token of the given type and payload is encountered. action (a no-arg member function) is called every time. Between each call, a comma is expected. Returns a vector of all the results of calling action. More... | |
| auto | next (source_location location=source_location::current()) -> Token |
| Return the next token and increment the iterator. More... | |
| auto | assert_payload_next (source_location location=source_location::current()) -> Atom |
| Returns the payload of the next token and increment the iterator. More... | |
| auto | consume_word (source_location location=source_location::current()) -> string |
Return the payload of the next token. Throws if the next token isn't a Word. More... | |
| auto | try_peek_uword (int ahead, source_location location=source_location::current()) const -> bool |
Check if the ahead by ahead is a capitalized word. More... | |
| auto | parse_stmt (bool require_sep=true) -> unique_ptr< Stmt > |
| auto | parse_expr () -> unique_ptr< Expr > |
| auto | parse_fn_arg () -> FnArg |
| auto | parse_generic_type_params () -> vector< GenericParam > |
| auto | try_parse_function_type () -> optional< unique_ptr< FunctionType > > |
| auto | try_parse_type () -> optional< unique_ptr< Type > > |
| auto | parse_type (bool implicit_self=false) -> unique_ptr< Type > |
| auto | parse_type_name () -> unique_ptr< TypeName > |
| auto | parse_fn_name () -> string |
| auto | parse_struct_decl () -> unique_ptr< StructDecl > |
| auto | parse_fn_or_ctor_decl () -> unique_ptr< Stmt > |
| auto | parse_fn_decl () -> unique_ptr< FnDecl > |
| auto | parse_ctor_decl () -> unique_ptr< CtorDecl > |
| auto | parse_var_decl () -> unique_ptr< VarDecl > |
| auto | parse_const_decl () -> unique_ptr< ConstDecl > |
| auto | parse_while_stmt () -> unique_ptr< WhileStmt > |
| auto | parse_return_stmt () -> unique_ptr< ReturnStmt > |
| auto | parse_if_stmt () -> unique_ptr< IfStmt > |
| auto | parse_number_expr () -> unique_ptr< NumberExpr > |
| auto | parse_string_expr () -> unique_ptr< StringExpr > |
| auto | parse_char_expr () -> unique_ptr< CharExpr > |
| auto | parse_primary () -> unique_ptr< Expr > |
| auto | parse_receiver (unique_ptr< Expr > receiver, VectorTokenIterator receiver_entry) -> unique_ptr< Expr > |
| auto | parse_receiver () -> unique_ptr< Expr > |
| auto | parse_unary () -> unique_ptr< Expr > |
| auto | parse_lambda () -> unique_ptr< LambdaExpr > |
| auto | parse_logical_or () -> unique_ptr< Expr > |
| auto | parse_logical_and () -> unique_ptr< Expr > |
| template<size_t N = 0> | |
| auto | parse_operator () -> unique_ptr< Expr > |
Static Public Member Functions | |
| template<typename T , typename U > | |
| static auto | ts (T &&begin, U &&end) -> span< Token > |
| static auto | operators () |
| static auto | unary_operators () |
| static auto | to_string (Token token) -> string |
| static auto | is_uword (string_view word) -> bool |
| Check if the string begins with a capital letter. Used for types, as all types must be capitalized. More... | |
Public Attributes | |
| TokenIterator & | tokens |
| diagnostic::NotesHolder & | notes |
Static Public Attributes | |
| static constexpr auto | Symbol = Token::Type::Symbol |
| static constexpr auto | Word = Token::Type::Word |
| static constexpr auto | Separator = Token::Type::Separator |
| static constexpr auto | Number = Token::Type::Number |
Definition at line 144 of file parser.hpp.
| auto yume::ast::parser::Parser::assert_payload_next | ( | source_location | location = source_location::current() | ) | -> Atom |
Returns the payload of the next token and increment the iterator.
| if | the next token has no payload |
Definition at line 124 of file parser.cpp.
References yume::at().
|
inline |
Definition at line 171 of file parser.hpp.
References yume::ast::TokenIterator::begin(), and tokens.
|
inline |
Definition at line 175 of file parser.hpp.
|
inline |
Definition at line 148 of file parser.hpp.
References yume::ast::TokenIterator::end(), and tokens.
Referenced by emit_fatal_and_terminate(), and emit_note().
|
inline |
Consume tokens until a token of the given type and payload is encountered. action (a no-arg member function) is called every time. Between each call, a comma is expected. Returns a vector of all the results of calling action.
Definition at line 270 of file parser.hpp.
References consume(), yume::ast::parser::SYM_COMMA, and try_consume().
|
inline |
Consume tokens until a token of the given type and payload is encountered. action (a no-arg member function) is called every time and its result is appended to vec. Between each call, a comma is expected.
Definition at line 256 of file parser.hpp.
References consume(), yume::ast::parser::SYM_COMMA, and try_consume().
| void yume::ast::parser::Parser::consume | ( | TokenAtom | token_atom, |
| source_location | location = source_location::current() |
||
| ) |
Consume a token of the given type and payload. Throws if it wasn't encountered.
Definition at line 45 of file parser.cpp.
References yume::at(), yume::ast::TokenIterator::at_end(), emit_fatal_and_terminate(), ignore_separator(), to_string(), tokens, and yume::Token::type_name().
Referenced by collect_with_commas_until(), and consume_with_commas_until().
|
inline |
Consume tokens until a token of the given type and payload is encountered. action (a no-arg function) is called every time. Between each call, a comma is expected.
Definition at line 242 of file parser.hpp.
References consume(), yume::ast::parser::SYM_COMMA, and try_consume().
| auto yume::ast::parser::Parser::consume_word | ( | source_location | location = source_location::current() | ) | -> string |
Return the payload of the next token. Throws if the next token isn't a Word.
Definition at line 136 of file parser.cpp.
References yume::at(), and yume::ast::parser::Word.
|
inlinenoexcept |
Definition at line 159 of file parser.hpp.
References clamped_iterator(), yume::diagnostic::NotesHolder::emit(), yume::diagnostic::Fatal, notes, and tokens.
|
inline |
Definition at line 154 of file parser.hpp.
References clamped_iterator(), yume::diagnostic::NotesHolder::emit(), notes, and tokens.
| void yume::ast::parser::Parser::expect | ( | Token::Type | token_type, |
| source_location | location = source_location::current() |
||
| ) | const |
If the next token doesn't have the type, token_type, throw a runtime exception.
Definition at line 23 of file parser.cpp.
References yume::at(), yume::ast::TokenIterator::at_end(), emit_fatal_and_terminate(), to_string(), tokens, and yume::Token::type_name().
Referenced by require_separator().
| auto yume::ast::parser::Parser::ignore_separator | ( | source_location | location = source_location::current() | ) | -> bool |
Ignore any Separator tokens if any are present.
Definition at line 11 of file parser.cpp.
References yume::at().
Referenced by consume(), yume::ast::Program::parse(), and require_separator().
|
inlinestatic |
Check if the string begins with a capital letter. Used for types, as all types must be capitalized.
Definition at line 294 of file parser.hpp.
|
inline |
Definition at line 179 of file parser.hpp.
References yume::ast::TokenIterator::begin(), and tokens.
|
inline |
Definition at line 193 of file parser.hpp.
References tokens.
| auto yume::ast::parser::Parser::next | ( | source_location | location = source_location::current() | ) | -> Token |
Return the next token and increment the iterator.
Definition at line 116 of file parser.cpp.
References yume::at().
|
inlinestatic |
Definition at line 195 of file parser.hpp.
References yume::ast::parser::SYM_AND, yume::ast::parser::SYM_EQ_EQ, yume::ast::parser::SYM_GT, yume::ast::parser::SYM_LT, yume::ast::parser::SYM_MINUS, yume::ast::parser::SYM_NEQ, yume::ast::parser::SYM_PERCENT, yume::ast::parser::SYM_PLUS, yume::ast::parser::SYM_SLASH_SLASH, and yume::ast::parser::SYM_STAR.
Referenced by parse_operator().
| auto yume::ast::parser::Parser::parse_char_expr | ( | ) | -> unique_ptr<CharExpr> |
Definition at line 713 of file parser.cpp.
References yume::Token::Char.
| auto yume::ast::parser::Parser::parse_const_decl | ( | ) | -> unique_ptr<ConstDecl> |
Definition at line 592 of file parser.cpp.
References yume::ast::parser::KWD_CONST, and yume::ast::parser::SYM_EQ.
| auto yume::ast::parser::Parser::parse_ctor_decl | ( | ) | -> unique_ptr<CtorDecl> |
Definition at line 548 of file parser.cpp.
References yume::ast::parser::KWD_DEF, yume::ast::parser::KWD_END, yume::ast::parser::KWD_NEW, yume::ast::parser::SYM_COLON, yume::ast::parser::SYM_LPAREN, and yume::ast::parser::SYM_RPAREN.
| auto yume::ast::parser::Parser::parse_expr | ( | ) | -> unique_ptr<Expr> |
Definition at line 352 of file parser.cpp.
Referenced by parse_primary(), and parse_receiver().
| auto yume::ast::parser::Parser::parse_fn_arg | ( | ) | -> FnArg |
Definition at line 427 of file parser.cpp.
References yume::ast::parser::SYM_COLON_COLON.
| auto yume::ast::parser::Parser::parse_fn_decl | ( | ) | -> unique_ptr<FnDecl> |
Definition at line 470 of file parser.cpp.
References yume::ast::parser::KWD_ABSTRACT, yume::ast::parser::KWD_DEF, yume::ast::parser::KWD_END, yume::ast::parser::KWD_EXTERN, yume::ast::parser::KWD_PRIMITIVE, yume::ast::parser::KWD_VARARGS, yume::ast::parser::SYM_AT, yume::ast::parser::SYM_EQ, yume::ast::parser::SYM_LPAREN, and yume::ast::parser::SYM_RPAREN.
| auto yume::ast::parser::Parser::parse_fn_name | ( | ) | -> string |
Definition at line 354 of file parser.cpp.
References yume::ast::parser::SYM_BANG, yume::ast::parser::SYM_EQ, yume::ast::parser::SYM_LBRACKET, yume::ast::parser::SYM_RBRACKET, yume::ast::parser::Symbol, and yume::ast::parser::Word.
| auto yume::ast::parser::Parser::parse_fn_or_ctor_decl | ( | ) | -> unique_ptr<Stmt> |
Definition at line 464 of file parser.cpp.
References yume::ast::parser::SYM_COLON.
| auto yume::ast::parser::Parser::parse_generic_type_params | ( | ) | -> vector<GenericParam> |
Definition at line 444 of file parser.cpp.
References yume::ast::parser::KWD_TYPE, yume::ast::parser::SYM_LBRACE, yume::ast::parser::SYM_RBRACE, and yume::diagnostic::Warn.
| auto yume::ast::parser::Parser::parse_if_stmt | ( | ) | -> unique_ptr<IfStmt> |
Definition at line 638 of file parser.cpp.
References yume::ast::parser::KWD_ELSE, yume::ast::parser::KWD_END, yume::ast::parser::KWD_IF, and yume::ast::parser::KWD_THEN.
| auto yume::ast::parser::Parser::parse_lambda | ( | ) | -> unique_ptr<LambdaExpr> |
Definition at line 850 of file parser.cpp.
References yume::ast::parser::KWD_DEF, yume::ast::parser::KWD_END, yume::ast::parser::SYM_AT, yume::ast::parser::SYM_EQ, yume::ast::parser::SYM_LPAREN, and yume::ast::parser::SYM_RPAREN.
| auto yume::ast::parser::Parser::parse_logical_and | ( | ) | -> unique_ptr<Expr> |
Definition at line 342 of file parser.cpp.
References parse_logical_and(), and yume::ast::parser::SYM_AND_AND.
Referenced by parse_logical_and().
| auto yume::ast::parser::Parser::parse_logical_or | ( | ) | -> unique_ptr<Expr> |
Definition at line 332 of file parser.cpp.
References yume::ast::parser::SYM_OR_OR.
| auto yume::ast::parser::Parser::parse_number_expr | ( | ) | -> unique_ptr<NumberExpr> |
Definition at line 692 of file parser.cpp.
|
inline |
Definition at line 348 of file parser.hpp.
References yume::ast::TokenIterator::begin(), operators(), parse_unary(), tokens, and try_consume().
| auto yume::ast::parser::Parser::parse_primary | ( | ) | -> unique_ptr<Expr> |
Definition at line 722 of file parser.cpp.
References yume::Token::Char, yume::ast::parser::KWD_FALSE, yume::ast::parser::KWD_TRUE, yume::Token::Literal, parse_expr(), yume::ast::parser::SYM_COLON, yume::ast::parser::SYM_COLON_COLON, yume::ast::parser::SYM_DOLLAR, yume::ast::parser::SYM_DOT, yume::ast::parser::SYM_LBRACKET, yume::ast::parser::SYM_LPAREN, yume::ast::parser::SYM_RBRACKET, yume::ast::parser::SYM_RPAREN, and yume::ast::parser::Word.
| auto yume::ast::parser::Parser::parse_receiver | ( | ) | -> unique_ptr<Expr> |
Definition at line 890 of file parser.cpp.
References yume::ast::parser::KWD_DEF.
| auto yume::ast::parser::Parser::parse_receiver | ( | unique_ptr< Expr > | receiver, |
| VectorTokenIterator | receiver_entry | ||
| ) | -> unique_ptr<Expr> |
Definition at line 795 of file parser.cpp.
References parse_expr(), yume::ast::parser::SYM_ARROW, yume::ast::parser::SYM_COLON_COLON, yume::ast::parser::SYM_DOT, yume::ast::parser::SYM_EQ, yume::ast::parser::SYM_LBRACKET, yume::ast::parser::SYM_LPAREN, yume::ast::parser::SYM_RBRACKET, and yume::ast::parser::SYM_RPAREN.
| auto yume::ast::parser::Parser::parse_return_stmt | ( | ) | -> unique_ptr<ReturnStmt> |
Definition at line 626 of file parser.cpp.
References yume::ast::parser::KWD_RETURN.
| auto yume::ast::parser::Parser::parse_stmt | ( | bool | require_sep = true | ) | -> unique_ptr<Stmt> |
Definition at line 157 of file parser.cpp.
References yume::ast::parser::KWD_CONST, yume::ast::parser::KWD_DEF, yume::ast::parser::KWD_IF, yume::ast::parser::KWD_INTERFACE, yume::ast::parser::KWD_LET, yume::ast::parser::KWD_RETURN, yume::ast::parser::KWD_STRUCT, and yume::ast::parser::KWD_WHILE.
| auto yume::ast::parser::Parser::parse_string_expr | ( | ) | -> unique_ptr<StringExpr> |
Definition at line 704 of file parser.cpp.
References yume::Token::Literal.
| auto yume::ast::parser::Parser::parse_struct_decl | ( | ) | -> unique_ptr<StructDecl> |
Definition at line 389 of file parser.cpp.
References yume::ast::parser::KWD_END, yume::ast::parser::KWD_IS, yume::ast::parser::KWD_STRUCT, yume::ast::parser::SYM_AT, yume::ast::parser::SYM_LPAREN, and yume::ast::parser::SYM_RPAREN.
| auto yume::ast::parser::Parser::parse_type | ( | bool | implicit_self = false | ) | -> unique_ptr<Type> |
Definition at line 210 of file parser.cpp.
References yume::ast::parser::KWD_MUT, yume::ast::parser::KWD_PTR, yume::ast::parser::KWD_REF, yume::ast::parser::KWD_SELF_TYPE, yume::ast::parser::KWD_TYPE, yume::Mut, yume::Ptr, yume::Ref, yume::ast::parser::SYM_LBRACE, yume::ast::parser::SYM_LBRACKET, yume::ast::parser::SYM_RBRACE, yume::ast::parser::SYM_RBRACKET, and yume::Type.
| auto yume::ast::parser::Parser::parse_type_name | ( | ) | -> unique_ptr<TypeName> |
Definition at line 321 of file parser.cpp.
References yume::ast::parser::KWD_SELF_ITEM.
| auto yume::ast::parser::Parser::parse_unary | ( | ) | -> unique_ptr<Expr> |
Definition at line 898 of file parser.cpp.
Referenced by parse_operator().
| auto yume::ast::parser::Parser::parse_var_decl | ( | ) | -> unique_ptr<VarDecl> |
Definition at line 578 of file parser.cpp.
References yume::ast::parser::KWD_LET, and yume::ast::parser::SYM_EQ.
| auto yume::ast::parser::Parser::parse_while_stmt | ( | ) | -> unique_ptr<WhileStmt> |
Definition at line 606 of file parser.cpp.
References yume::ast::parser::KWD_END, and yume::ast::parser::KWD_WHILE.
| void yume::ast::parser::Parser::require_separator | ( | source_location | location = source_location::current() | ) |
Consume all subsequent Separator tokens. Throws if none were found.
Definition at line 33 of file parser.cpp.
References yume::ast::TokenIterator::at_end(), yume::Token::EndOfFile, expect(), ignore_separator(), Separator, and tokens.
|
static |
Definition at line 39 of file parser.cpp.
| auto yume::ast::parser::Parser::try_consume | ( | TokenAtom | token_atom, |
| source_location | location = source_location::current() |
||
| ) | -> bool |
Attempt to consume a token of the given type and payload. Returns false if it wasn't encountered.
Definition at line 69 of file parser.cpp.
References yume::at().
Referenced by collect_with_commas_until(), consume_with_commas_until(), and parse_operator().
| auto yume::ast::parser::Parser::try_parse_function_type | ( | ) | -> optional<unique_ptr<FunctionType>> |
Definition at line 182 of file parser.cpp.
References yume::ast::parser::KWD_PTR, yume::ast::parser::SYM_ARROW, yume::ast::parser::SYM_COMMA, yume::ast::parser::SYM_LPAREN, and yume::ast::parser::SYM_RPAREN.
| auto yume::ast::parser::Parser::try_parse_type | ( | ) | -> optional<unique_ptr<Type>> |
Definition at line 264 of file parser.cpp.
References yume::ast::parser::KWD_MUT, yume::ast::parser::KWD_PTR, yume::ast::parser::KWD_REF, yume::ast::parser::KWD_SELF_TYPE, yume::ast::parser::KWD_TYPE, yume::make_atom(), yume::Mut, yume::Ptr, yume::Ref, yume::ast::parser::SYM_LBRACE, yume::ast::parser::SYM_LBRACKET, yume::ast::parser::SYM_RBRACE, yume::ast::parser::SYM_RBRACKET, try_parse_type(), yume::Type, and yume::ast::parser::Word.
Referenced by try_parse_type().
| auto yume::ast::parser::Parser::try_peek | ( | int | ahead, |
| Token::Type | token_type, | ||
| source_location | location = source_location::current() |
||
| ) | const -> bool |
Check if the token ahead by ahead is of type token_type.
Definition at line 99 of file parser.cpp.
References yume::at(), and yume::Token::type_name().
| auto yume::ast::parser::Parser::try_peek | ( | int | ahead, |
| TokenAtom | token_atom, | ||
| source_location | location = source_location::current() |
||
| ) | const -> bool |
Check if the token ahead by ahead is of the given type and payload.
Definition at line 82 of file parser.cpp.
References yume::at(), and yume::Token::type_name().
| auto yume::ast::parser::Parser::try_peek_uword | ( | int | ahead, |
| source_location | location = source_location::current() |
||
| ) | const -> bool |
Check if the ahead by ahead is a capitalized word.
Definition at line 146 of file parser.cpp.
References yume::at(), and yume::ast::parser::Word.
|
inline |
Definition at line 167 of file parser.hpp.
References yume::ast::TokenIterator::begin(), and tokens.
|
inlinestatic |
Definition at line 163 of file parser.hpp.
References end.
|
inlinestatic |
Definition at line 205 of file parser.hpp.
References yume::ast::parser::SYM_BANG, yume::ast::parser::SYM_MINUS, and yume::ast::parser::SYM_PLUS.
| diagnostic::NotesHolder& yume::ast::parser::Parser::notes |
Definition at line 146 of file parser.hpp.
Referenced by emit_fatal_and_terminate(), and emit_note().
|
staticconstexpr |
Definition at line 191 of file parser.hpp.
|
staticconstexpr |
Definition at line 190 of file parser.hpp.
Referenced by require_separator().
|
staticconstexpr |
Definition at line 188 of file parser.hpp.
| TokenIterator& yume::ast::parser::Parser::tokens |
Definition at line 145 of file parser.hpp.
Referenced by ast_ptr(), clamped_iterator(), consume(), emit_fatal_and_terminate(), emit_note(), expect(), make_ast(), make_guard(), parse_operator(), require_separator(), and ts().
|
staticconstexpr |
Definition at line 189 of file parser.hpp.