pub trait TokenTrait:
Debug
+ Clone
+ Into<SyntaxKind>
+ From<SyntaxKind>
+ PartialEq
+ Eq
+ Hash
+ 'static {
const ERROR: Self;
const ROOT: Self;
// Required methods
fn branch(&self) -> u32;
fn skips(&self) -> bool;
fn starting_tokens(&self) -> &'static [Self];
fn ending_tokens(&self) -> &'static [Self];
// Provided methods
fn min_error_for_token(&self, _tok: &Self) -> isize { ... }
fn max_error_value(&self) -> isize { ... }
fn min_completion_cost(&self) -> isize { ... }
fn deletion_cost(&self) -> isize { ... }
fn bracket_delta(&self) -> i8 { ... }
}Required Associated Constants§
Required Methods§
fn branch(&self) -> u32
fn skips(&self) -> bool
fn starting_tokens(&self) -> &'static [Self]
fn ending_tokens(&self) -> &'static [Self]
Provided Methods§
Sourcefn min_error_for_token(&self, _tok: &Self) -> isize
fn min_error_for_token(&self, _tok: &Self) -> isize
Returns the minimum error cost this rule must incur when tok is the
current token. Returns 0 if tok is reachable anywhere inside the
rule or the rule is nullable (can match zero tokens). Returns a
positive value otherwise — the rule cannot make progress without
producing at least that much error cost.
Used by add_element_checked to pre-charge elements before adding
them to the A* search. Defaults to 0 (no pre-charging).
Sourcefn max_error_value(&self) -> isize
fn max_error_value(&self) -> isize
Maximum error_value for this token kind across all grammar rules that
may match it.
Must always return > 0: the A* cost model adds error_value on a miss
and nothing on a match, so matching is strictly cheaper when
error_value > 0.
Defaults to 2, matching the minimum terminal weight used in codegen.
Sourcefn min_completion_cost(&self) -> isize
fn min_completion_cost(&self) -> isize
Minimum cost to complete this rule via insertions. This is the sum of
error_values for all required terminals on the cheapest path through the
rule. Used by add_element_checked to pre-charge elements that push
a rule the current token cannot start. Defaults to max_error_value().
Sourcefn deletion_cost(&self) -> isize
fn deletion_cost(&self) -> isize
Cost of deleting (skipping) this token during error recovery.
Defaults to 5 × max_error_value(). Must be high enough that
matching tokens is always cheaper than deleting them, while still
cheaper than long cascades of error insertions.
Sourcefn bracket_delta(&self) -> i8
fn bracket_delta(&self) -> i8
Bracket nesting delta for this token kind.
Returns +1 for opening brackets ({, [, (), -1 for closing
brackets (}, ], )), and 0 for all other tokens. Used by the
incremental A* to track the bracket nesting depth at which each token
was parsed, enabling a one-time “context-shift” cost when a block of
tokens moves to a different nesting level between edits.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.