hare::unparse+x86_64 +linux
unparse: convert hare::ast:: objects into Hare source code
hare::unparse provides an unparser for Hare. All functions take in some part of the AST and write formatted Hare source code to an io::handle.
Index
Types
type context; type stack; type synfunc; type synkind;
Functions
fn _type(out: io::handle, syn: *synfunc, t: *ast::_type) (size | io::error); fn builtin_type(b: ast::builtin_type) str; fn decl(out: io::handle, syn: *synfunc, d: *ast::decl) (size | io::error); fn expr(out: io::handle, syn: *synfunc, e: *ast::expr) (size | io::error); fn ident(out: io::handle, id: ast::ident) (size | io::error); fn identstr(id: ast::ident) str; fn import(out: io::handle, syn: *synfunc, import: *ast::import) (size | io::error); fn subunit(out: io::handle, syn: *synfunc, s: ast::subunit) (size | io::error); fn syn_nowrap(ctx: *context, s: str, kind: synkind) (size | io::error); fn syn_wrap(ctx: *context, s: str, kind: synkind) (size | io::error);
Types
type context[permalink] [source]
type context = struct { out: io::handle, stack: nullable *stack, linelen: size, indent: size, };
Context about the unparsing state supplied to a synfunc. The linelen and indent fields may be mutated.
type stack[permalink] [source]
type stack = struct { cur: (*ast::decl | *ast::expr | *ast::_type | *ast::import), up: nullable *stack, extra: nullable *opaque, };
A linked list of AST nodes currently being unparsed.
type synfunc[permalink] [source]
type synfunc = fn(ctx: *context, s: str, kind: synkind) (size | io::error);
A user-supplied function which writes unparsed Hare source code to a handle, optionally including extra stylistic features. The function is expected to write to, at the minimum, write the provided string to ctx.out, and update ctx.linelen based on how much data was written.
syn_nowrap and syn_wrap are provided for when no additional styling is desired.
type synkind[permalink] [source]
type synkind = enum { IDENT, COMMENT, CONSTANT, FUNCTION, GLOBAL, TYPEDEF, IMPORT_ALIAS, SECONDARY, KEYWORD, TYPE, ATTRIBUTE, OPERATOR, PUNCTUATION, RUNE_STRING, NUMBER, LABEL, };
The kind of thing being unparsed.
Functions
fn _type[permalink] [source]
fn _type(out: io::handle, syn: *synfunc, t: *ast::_type) (size | io::error);
Unparses a hare::ast::_type.
fn builtin_type[permalink] [source]
fn builtin_type(b: ast::builtin_type) str;
Returns a builtin type as a string.
fn decl[permalink] [source]
fn decl(out: io::handle, syn: *synfunc, d: *ast::decl) (size | io::error);
Unparses a hare::ast::decl.
fn expr[permalink] [source]
fn expr(out: io::handle, syn: *synfunc, e: *ast::expr) (size | io::error);
Unparses a hare::ast::expr.
fn ident[permalink] [source]
fn ident(out: io::handle, id: ast::ident) (size | io::error);
Unparses an identifier.
fn identstr[permalink] [source]
fn identstr(id: ast::ident) str;
Unparses an identifier into a string. The caller must free the return value.
fn import[permalink] [source]
fn import(out: io::handle, syn: *synfunc, import: *ast::import) (size | io::error);
Unparses a hare::ast::import.
fn subunit[permalink] [source]
fn subunit(out: io::handle, syn: *synfunc, s: ast::subunit) (size | io::error);
Unparses a hare::ast::subunit.
fn syn_nowrap[permalink] [source]
fn syn_nowrap(ctx: *context, s: str, kind: synkind) (size | io::error);
A synfunc implementation which unparses without additional styling, and without wrapping any long lines.
fn syn_wrap[permalink] [source]
fn syn_wrap(ctx: *context, s: str, kind: synkind) (size | io::error);
A synfunc implementation which unparses without additional styling, but which wraps some long lines at 80 columns, in accordance with the style guide.