pub enum UniversalTokenRole {
Keyword,
Name,
Literal,
Escape,
Operator,
Punctuation,
Comment,
Whitespace,
Error,
None,
Eof,
}Expand description
Represents the general syntactic role of a token across diverse languages.
§Universal Grammar
This mechanism is inspired by Noam Chomsky’s Universal Grammar theory. It posits that while the “Surface Structure” (specific token kinds) of languages may vary wildly, they share a common “Deep Structure” (syntactic roles).
In the Oak framework:
- Surface Structure: Refers to specific token kinds defined by a language (e.g., Rust’s
PubKeyword). - Deep Structure: Refers to the universal roles defined in this enum (e.g.,
UniversalTokenRole::Keyword).
By mapping to these roles, generic tools can identify names, literals, or operators across 100+ languages without needing to learn the specifics of each grammar.
Variants§
Keyword
Language reserved words or built-in commands (e.g., ‘SELECT’, ‘let’, ‘MOV’).
Name
Identifiers, labels, keys, tags, or any name-like token.
Literal
Literal values like strings, numbers, booleans, or nulls.
Escape
An escape sequence or a special character representation within a literal.
Operator
Mathematical, logical, or structural operators (e.g., ‘+’, ‘=>’, ‘LIKE’).
Punctuation
Structural characters like brackets, commas, semicolons.
Comment
Developer annotations or documentation.
Whitespace
Formatting characters like spaces or tabs.
Error
Malformed or unrecognized content.
None
No specific role assigned.
Eof
End of stream marker.
Trait Implementations§
Source§impl Clone for UniversalTokenRole
impl Clone for UniversalTokenRole
Source§fn clone(&self) -> UniversalTokenRole
fn clone(&self) -> UniversalTokenRole
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more