pub struct ConcreteSyntaxTree { /* private fields */ }Expand description
A Concrete Syntax Tree for VB6 code.
This structure wraps the rowan library’s GreenNode internally but provides
a public API that doesn’t expose rowan types.
Implementations§
Source§impl ConcreteSyntaxTree
impl ConcreteSyntaxTree
Sourcepub fn debug_tree(&self) -> String
pub fn debug_tree(&self) -> String
Get a textual representation of the tree structure (for debugging)
Sourcepub fn child_count(&self) -> usize
pub fn child_count(&self) -> usize
Get the number of children of the root node
Sourcepub fn children(&self) -> Vec<CstNode>
pub fn children(&self) -> Vec<CstNode>
Get the children of the root node
Returns a vector of child nodes with their kind and text content.
Sourcepub fn children_by_kind(
&self,
kind: SyntaxKind,
) -> impl Iterator<Item = CstNode>
pub fn children_by_kind( &self, kind: SyntaxKind, ) -> impl Iterator<Item = CstNode>
Get an iterator over direct children of a specific kind
This method returns an iterator for better performance and composability.
If you need a Vec, call .collect() on the result.
§Arguments
kind- TheSyntaxKindto search for
§Returns
An iterator over child nodes matching the specified kind
§Example
// Use iterator directly
for dim_stmt in cst.children_by_kind(SyntaxKind::DimStatement) {
println!("Found: {}", dim_stmt.text());
}
// Or collect into a Vec
let dim_stmts: Vec<_> = cst.children_by_kind(SyntaxKind::DimStatement).collect();Sourcepub fn first_child_by_kind(&self, kind: SyntaxKind) -> Option<CstNode>
pub fn first_child_by_kind(&self, kind: SyntaxKind) -> Option<CstNode>
Sourcepub fn contains_kind(&self, kind: SyntaxKind) -> bool
pub fn contains_kind(&self, kind: SyntaxKind) -> bool
Sourcepub fn first_child(&self) -> Option<CstNode>
pub fn first_child(&self) -> Option<CstNode>
Get the first child node (including tokens)
§Returns
The first child node if it exists, None otherwise
Sourcepub fn last_child(&self) -> Option<CstNode>
pub fn last_child(&self) -> Option<CstNode>
Get the last child node (including tokens)
§Returns
The last child node if it exists, None otherwise
Sourcepub fn find(&self, kind: SyntaxKind) -> Option<CstNode>
pub fn find(&self, kind: SyntaxKind) -> Option<CstNode>
Find the first descendant node of a specific kind (depth-first search)
This searches recursively through the entire tree, unlike first_child_by_kind()
which only searches direct children.
§Arguments
kind- TheSyntaxKindto search for
§Returns
The first descendant node matching the kind, or None if not found
Sourcepub fn find_all(&self, kind: SyntaxKind) -> Vec<CstNode>
pub fn find_all(&self, kind: SyntaxKind) -> Vec<CstNode>
Sourcepub fn non_token_children(&self) -> impl Iterator<Item = CstNode>
pub fn non_token_children(&self) -> impl Iterator<Item = CstNode>
Get an iterator over non-token children (structural nodes only)
Sourcepub fn token_children(&self) -> impl Iterator<Item = CstNode>
pub fn token_children(&self) -> impl Iterator<Item = CstNode>
Get an iterator over token children only
Sourcepub fn first_non_whitespace_child(&self) -> Option<CstNode>
pub fn first_non_whitespace_child(&self) -> Option<CstNode>
Get the first non-whitespace child
Sourcepub fn significant_children(&self) -> impl Iterator<Item = CstNode>
pub fn significant_children(&self) -> impl Iterator<Item = CstNode>
Get an iterator over significant children (excluding whitespace and newlines)
Sourcepub fn find_if<F>(&self, predicate: F) -> Option<CstNode>
pub fn find_if<F>(&self, predicate: F) -> Option<CstNode>
Find the first descendant node matching a predicate (depth-first search)
This allows flexible searching with custom logic beyond just matching kinds.
§Arguments
predicate- A closure that takes a&CstNodeand returnsbool
§Returns
The first descendant node for which the predicate returns true, or None if not found
Sourcepub fn find_all_if<F>(&self, predicate: F) -> Vec<CstNode>
pub fn find_all_if<F>(&self, predicate: F) -> Vec<CstNode>
Sourcepub fn descendants(&self) -> DepthFirstIterOwned
pub fn descendants(&self) -> DepthFirstIterOwned
Get an iterator over all descendants (depth-first, pre-order)
This visits every node in the tree.
§Returns
An iterator that yields owned copies of all descendants in depth-first order
Sourcepub fn depth_first_iter(&self) -> DepthFirstIterOwned
pub fn depth_first_iter(&self) -> DepthFirstIterOwned
Get a depth-first iterator over the tree
This is an alias for descendants() for compatibility with common tree APIs.
§Returns
An iterator that yields owned copies of all descendants in depth-first order
Source§impl ConcreteSyntaxTree
impl ConcreteSyntaxTree
Sourcepub fn from_source(source_file: &SourceFile) -> ParseResult<'_, Self>
pub fn from_source(source_file: &SourceFile) -> ParseResult<'_, Self>
Sourcepub fn from_text<S>(file_name: S, contents: &str) -> ParseResult<'_, Self>
pub fn from_text<S>(file_name: S, contents: &str) -> ParseResult<'_, Self>
Sourcepub fn root_kind(&self) -> SyntaxKind
pub fn root_kind(&self) -> SyntaxKind
Get the kind of the root node
Sourcepub fn to_serializable(&self) -> SerializableTree
pub fn to_serializable(&self) -> SerializableTree
Convert the CST to a serializable representation.
This method creates a SerializableTree that can be used with
snapshot testing tools like insta. The serializable tree contains
the complete tree structure as a hierarchy of CstNode instances.
§Example
use vb6parse::ConcreteSyntaxTree;
let source = "Sub Test()\nEnd Sub\n";
let result = ConcreteSyntaxTree::from_text("test.bas", source);
let (cst_opt, failures) = result.unpack();
let cst = cst_opt.expect("Failed to parse source");
if !failures.is_empty() {
for failure in failures.iter() {
failure.print();
}
panic!("Failed to parse source with {} errors.", failures.len());
};
let serializable = cst.to_serializable();
// Can now be used with insta::assert_yaml_snapshot!Sourcepub fn to_root_node(&self) -> CstNode
pub fn to_root_node(&self) -> CstNode
Convert the internal rowan tree to a root CstNode.
§Returns
The root CstNode representing the entire CST.
Sourcepub fn without_kinds(&self, kinds_to_remove: &[SyntaxKind]) -> Self
pub fn without_kinds(&self, kinds_to_remove: &[SyntaxKind]) -> Self
Create a new CST with specified node kinds removed from the root level.
This method filters out direct children of the root node that match any of the specified kinds. This is useful for removing nodes that have already been parsed into structured data (like version statements, attributes, etc.) to avoid duplication.
§Arguments
kinds_to_remove- A slice ofSyntaxKindvalues to filter out
§Returns
A new ConcreteSyntaxTree with the specified kinds removed from the root level.
§Example
use vb6parse::ConcreteSyntaxTree;
use vb6parse::parsers::SyntaxKind;
let source = "VERSION 5.00\nSub Test()\nEnd Sub\n";
let result = ConcreteSyntaxTree::from_text("test.bas", source);
let (cst_opt, failures) = result.unpack();
let cst = cst_opt.expect("Failed to parse source");
// Remove version statement since it's already parsed
let filtered = cst.without_kinds(&[SyntaxKind::VersionStatement]);
assert!(!filtered.contains_kind(SyntaxKind::VersionStatement));Trait Implementations§
Source§impl Clone for ConcreteSyntaxTree
impl Clone for ConcreteSyntaxTree
Source§fn clone(&self) -> ConcreteSyntaxTree
fn clone(&self) -> ConcreteSyntaxTree
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConcreteSyntaxTree
impl Debug for ConcreteSyntaxTree
Source§impl Hash for ConcreteSyntaxTree
impl Hash for ConcreteSyntaxTree
Source§impl PartialEq for ConcreteSyntaxTree
impl PartialEq for ConcreteSyntaxTree
impl Eq for ConcreteSyntaxTree
impl StructuralPartialEq for ConcreteSyntaxTree
Auto Trait Implementations§
impl Freeze for ConcreteSyntaxTree
impl RefUnwindSafe for ConcreteSyntaxTree
impl Send for ConcreteSyntaxTree
impl Sync for ConcreteSyntaxTree
impl Unpin for ConcreteSyntaxTree
impl UnsafeUnpin for ConcreteSyntaxTree
impl UnwindSafe for ConcreteSyntaxTree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);