pub trait Alteratorwhere
Self: Checker,{
// Provided methods
fn alterate(
node: &Node<'_>,
code: &[u8],
span: bool,
field_name: Option<&'static str>,
children: Vec<AstNode>,
) -> AstNode { ... }
fn get_text_span(
node: &Node<'_>,
code: &[u8],
span: bool,
text: bool,
) -> (String, Option<Span>) { ... }
fn get_default(
node: &Node<'_>,
code: &[u8],
span: bool,
field_name: Option<&'static str>,
children: Vec<AstNode>,
) -> AstNode { ... }
fn keeps_children<'a>(
_node: &Node<'a>,
_code: &[u8],
_ancestors: Ancestors<'a, '_>,
) -> bool { ... }
fn get_ast_node<'a>(
node: &Node<'a>,
code: &[u8],
span: bool,
comment: bool,
field_name: Option<&'static str>,
children: Vec<AstNode>,
ancestors: Ancestors<'a, '_>,
) -> Option<AstNode> { ... }
}Expand description
A trait to create a richer AST node for a programming language, mainly
thought to be sent on the network. Crate-internal extension over
[Checker], used only by the per-language Parser<T> impls.
Provided Methods§
Sourcefn alterate(
node: &Node<'_>,
code: &[u8],
span: bool,
field_name: Option<&'static str>,
children: Vec<AstNode>,
) -> AstNode
fn alterate( node: &Node<'_>, code: &[u8], span: bool, field_name: Option<&'static str>, children: Vec<AstNode>, ) -> AstNode
Creates a new AST node containing the code associated to the node,
its span, the grammar field name through which the parent reaches
it (if any), and its children.
This function can be overloaded according to the needs of each programming language.
Sourcefn get_text_span(
node: &Node<'_>,
code: &[u8],
span: bool,
text: bool,
) -> (String, Option<Span>)
fn get_text_span( node: &Node<'_>, code: &[u8], span: bool, text: bool, ) -> (String, Option<Span>)
Gets the code as text and the span associated to a node.
Sourcefn get_default(
node: &Node<'_>,
code: &[u8],
span: bool,
field_name: Option<&'static str>,
children: Vec<AstNode>,
) -> AstNode
fn get_default( node: &Node<'_>, code: &[u8], span: bool, field_name: Option<&'static str>, children: Vec<AstNode>, ) -> AstNode
Gets a default AST node containing the code associated to the
node, its span, its grammar field name (if any), and its
children.
Sourcefn keeps_children<'a>(
_node: &Node<'a>,
_code: &[u8],
_ancestors: Ancestors<'a, '_>,
) -> bool
fn keeps_children<'a>( _node: &Node<'a>, _code: &[u8], _ancestors: Ancestors<'a, '_>, ) -> bool
Whether node must keep its children even though
Self::alterate would flatten it into a verbatim leaf.
The flattening arms are keyed on node kind, which is the right
question for a language whose string literals have a kind of
their own. The Tcl family is the exception: braced_word is both
the literal of lappend x {a b} and the script of a proc
body or an iRules when handler, so flattening by kind dropped
every script body from the dump — the whole body collapsed into
one leaf holding its text (#1381).
It is a veto rather than an extra alterate arm so that
alterate keeps its byte-and-kind signature: only this question
needs the ancestor chain, and threading it through all twenty-odd
alterate impls to serve two of them would make every language
pay for one grammar’s ambiguity. ancestors is the chain the
dump walk descended through, for Node::parent’s O(depth)
reason (#1084) — off an unknown chain this question took
Ast::dump on 8 KB of nested Tcl braces from 10 ms to 418 ms —
the run ast.rs records beside the chain this reads, not a
second measurement.
Sourcefn get_ast_node<'a>(
node: &Node<'a>,
code: &[u8],
span: bool,
comment: bool,
field_name: Option<&'static str>,
children: Vec<AstNode>,
ancestors: Ancestors<'a, '_>,
) -> Option<AstNode>
fn get_ast_node<'a>( node: &Node<'a>, code: &[u8], span: bool, comment: bool, field_name: Option<&'static str>, children: Vec<AstNode>, ancestors: Ancestors<'a, '_>, ) -> Option<AstNode>
Gets a new AST node if and only if the code is not a comment,
otherwise None is returned.
Parameter order mirrors Self::alterate and Self::get_default
(the flags-before-data convention span, comment, field_name, children) so positional confusion between adjacent boolean
toggles is harder to introduce on the next edit. ancestors is
last, matching every other chain-taking predicate in the crate.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".