hare::parse
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 = !lex::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 peek(lexer: *lex::lexer, want: lex::ltok...) (lex::token | error | void);
fn strerror(err: error) const str;
fn subunit(lexer: *lex::lexer) (ast::subunit | 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
type error = !lex::error;
All possible error types.
Functions
fn _type
fn _type(lexer: *lex::lexer) (ast::_type | error);
Parses a type, e.g. '[]int'.
fn decl
fn decl(lexer: *lex::lexer) (ast::decl | error);
Parses a declaration.
fn decls
fn decls(lexer: *lex::lexer) ([]ast::decl | error);
Parses the declarations for a sub-unit.
fn define
fn define(lexer: *lex::lexer) (ast::decl_const | error);
Parses a command-line definition
fn expr
fn expr(lexer: *lex::lexer) (ast::expr | error);
Parses an expression.
fn ident
fn ident(lexer: *lex::lexer) (ast::ident | error);
Parses a single identifier, i.e. 'foo::bar::baz'.
fn ident_trailing
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
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
fn imports(lexer: *lex::lexer) ([]ast::import | error);
Parses the import list for a sub-unit
fn peek
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
fn strerror(err: error) const str;
Convert an error into a human-friendly string. The result may be statically allocated.
fn subunit
fn subunit(lexer: *lex::lexer) (ast::subunit | error);
Parses an entire subunit (i.e. one Hare source file).
fn try
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
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.