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.
Index
Errors
type error;
Functions
fn _type(*lex::lexer) (ast::_type | error);
fn decl(*lex::lexer) (ast::decl | error);
fn decls(*lex::lexer) ([]ast::decl | error);
fn expr(*lex::lexer) (ast::expr | error);
fn ident(*lex::lexer) (ast::ident | error);
fn identstr(str) (ast::ident | error);
fn imports(*lex::lexer) ([]ast::import | error);
fn strerror(error) const str;
fn subunit(*lex::lexer) (ast::subunit | 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 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 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 strerror
fn strerror(err: error) const str;
Convert an error into a human-friendly string.
fn subunit
fn subunit(lexer: *lex::lexer) (ast::subunit | error);
Parses an entire subunit (i.e. one Hare source file).