hare::parse+x86_64 +linux
parse: parser for the Hare grammar
hare::parse provides a parser for Hare source code. The subunit function will parse a single Hare source file and return a hare::ast::subunit. Other functions provide parsers for various important Hare sub-terminals, such as decls and imports. See the Hare specification for more details:
https://harelang.org/specification
Most of these functions require the caller to provide a Hare lexer, see hare::lex:: for details.
Submodules
Index
Errors
type error;
Functions
fn _type(lexer: *lex::lexer) (ast::_type | error); fn decl(lexer: *lex::lexer) (ast::decl | error); fn decls(lexer: *lex::lexer) ([]ast::decl | error); fn define(lexer: *lex::lexer) (ast::decl_const | error); fn expr(lexer: *lex::lexer) (ast::expr | error); fn ident(lexer: *lex::lexer) (ast::ident | error); fn ident_trailing(lexer: *lex::lexer) ((ast::ident, bool) | error); fn identstr(in: str) (ast::ident | error); fn imports(lexer: *lex::lexer) ([]ast::import | error); fn initializer(lexer: *lex::lexer) (ast::expr | error); fn peek(lexer: *lex::lexer, want: lex::ltok...) (lex::token | error | void); fn strerror(err: error) str; fn subunit(lexer: *lex::lexer) (ast::subunit | error); fn synassert(loc: lex::location, cond: bool, msg: str) (void | error); fn try(lexer: *lex::lexer, want: lex::ltok...) (lex::token | error | void); fn want(lexer: *lex::lexer, want: lex::ltok...) (lex::token | error);
Errors
type error[permalink] [source]
type error = !lex::error;
All possible error types.
Functions
fn _type[permalink] [source]
fn _type(lexer: *lex::lexer) (ast::_type | error);
Parses a type, e.g. '[]int'.
fn decl[permalink] [source]
fn decl(lexer: *lex::lexer) (ast::decl | error);
Parses a declaration.
fn decls[permalink] [source]
fn decls(lexer: *lex::lexer) ([]ast::decl | error);
Parses the declarations for a sub-unit.
fn define[permalink] [source]
fn define(lexer: *lex::lexer) (ast::decl_const | error);
Parses a command-line definition
fn expr[permalink] [source]
fn expr(lexer: *lex::lexer) (ast::expr | error);
Parses an expression.
fn ident[permalink] [source]
fn ident(lexer: *lex::lexer) (ast::ident | error);
Parses a single identifier, i.e. 'foo::bar::baz'.
fn ident_trailing[permalink] [source]
fn ident_trailing(lexer: *lex::lexer) ((ast::ident, bool) | error);
Parses a single identifier, possibly with a trailing ::, i.e. 'foo::bar::'. Returns the identifier and whether there's a trailing ::.
fn identstr[permalink] [source]
fn identstr(in: str) (ast::ident | error);
A convenience function which parses an identifier from a string, so the caller needn't provide a lexer instance.
fn imports[permalink] [source]
fn imports(lexer: *lex::lexer) ([]ast::import | error);
Parses the import list for a sub-unit
fn initializer[permalink] [source]
fn initializer(lexer: *lex::lexer) (ast::expr | error);
Parses an initializer.
fn peek[permalink] [source]
fn peek(lexer: *lex::lexer, want: lex::ltok...) (lex::token | error | void);
Looks for a matching ltok from the lexer, unlexes the token, and returns it; or void if it was not an ltok.
fn strerror[permalink] [source]
fn strerror(err: error) str;
Convert an error into a human-friendly string. The result may be statically allocated.
fn subunit[permalink] [source]
fn subunit(lexer: *lex::lexer) (ast::subunit | error);
Parses an entire subunit (i.e. one Hare source file).
fn synassert[permalink] [source]
fn synassert(loc: lex::location, cond: bool, msg: str) (void | error);
Returns a syntax error if cond is false and void otherwise
fn try[permalink] [source]
fn try(lexer: *lex::lexer, want: lex::ltok...) (lex::token | error | void);
Looks for a matching ltok from the lexer, and if not present, unlexes the token and returns void. If found, the token is consumed from the lexer and is returned.
fn want[permalink] [source]
fn want(lexer: *lex::lexer, want: lex::ltok...) (lex::token | error);
Requires the next token to have a matching ltok. Returns that token, or an error.