Skip to main content

Module functions

Module functions 

Source
Expand description

Auto-generated module

🤖 Generated with SplitRS

Modules§

ansi
ANSI color codes for syntax highlighting.

Functions§

adjacent_pairs
Find all pairs of adjacent tokens.
annotate_tokens
Annotate a token slice with depth and category information.
annotate_with_meta
Annotate a token slice with metadata from source text.
are_adjacent
Check if two token spans are adjacent (no gap between them in source).
can_start_decl
Return true if kind can begin a declaration.
can_start_expr
Return true if kind can begin a term / expression.
categorise
Assign a TokenCategory to a TokenKind.
check_bracket_balance
Verify that all brackets in tokens are balanced.
closing_bracket
Return the closing bracket kind for a TokenKind, if any.
closing_for
Given an opening bracket kind, return the matching closing TokenKind.
collect_idents
Collect all identifier names from a token slice.
colorize_token
Apply ANSI coloring to a token based on its category.
compute_depths
Count the nesting depth at each token position.
contains_ident
Return true if the token list contains any identifier with the given name.
count_bigrams
Count bigrams (pairs of consecutive tokens) in a slice. Returns counts keyed by (debug_repr_a, debug_repr_b) string pairs.
count_kind
Count tokens with the given kind.
covering_span
Return the span covering the entire slice of tokens, or a dummy span if empty.
describe_token
Deserialize a debug token description (best-effort, for tests only).
enrich_tokens
Convert a slice of tokens to a Vec<RichToken>.
extract_bracketed
Extract the content between matched brackets (exclusive).
filter_tokens
Return all tokens matching a predicate.
find_by_category
Find the first token with the given category.
find_matching_close
Find the index of the matching closing bracket for an opening bracket at open_idx.
has_operator
Check if the token slice contains any operator.
ident_of
Extract the identifier string from a token, if it is one.
infix_precedence
Return the precedence of an infix operator, or None if not an operator.
is_assign
Check whether a token is a := (assign) token.
is_colon
Check whether a token is a : (colon) token.
is_ident_token
Check whether a token is an identifier.
is_infix_op
Return true if kind represents an infix binary operator.
is_keyword_token
Returns true if the token kind string represents a keyword.
is_right_assoc
Return true if kind is a right-associative operator.
longest_run
Return the longest run of consecutive tokens with the same kind.
max_bracket_depth
Return the maximum depth of bracket nesting in a token slice.
nat_lit_of
Extract a natural-number literal value from a token, if it is one.
opening_bracket
Return the opening bracket kind for a TokenKind, if any.
opening_for
Given a closing bracket kind, return the matching opening TokenKind.
operator_arity
Determine the arity of an operator token.
operator_priority
Look up the binding priority of an operator token.
reconstruct_source
Reconstruct source text from tokens and original source.
reformat
Reformat a token stream to a normalized string.
render_colored
Render a token slice as a colorized string.
serialize_tokens
Serialize a token slice to a compact string representation (for debugging).
span_char_count
Count the total number of characters spanned by a token slice.
split_at_kind
Split a token slice at every occurrence of sep, returning the groups.
starts_with_valid_decl_head
Validate that a token slice represents a well-formed declaration head.
starts_with_valid_expr_head
Validate that a token slice represents a well-formed expression head.
strip_comments
Strip all comment tokens from a token list.
strip_eof
Strip leading and trailing EOF tokens.
structurally_equal
Compare two token slices for structural equality (same kinds in same order).
token_edit_distance
Compute the edit distance between two token sequences (by kind).
token_frequencies
Tokenize frequencies: return (kind_string, count) pairs sorted by count.
token_hash
Compute a simple hash of a token sequence (by kind only).
token_kind_display
Format a token kind for use in error messages.
token_kind_display_name
Returns the display name for a token kind.
token_lcs_length
Find the longest common subsequence (by kind) of two token slices.
token_ngrams
Produce N-grams of size n from a token slice.
type_token_ratio
Compute the type-token ratio (distinct kinds / total tokens).
vocabulary
Compute the vocabulary (set of distinct token kinds) in a slice.