pub enum Token {
Leaf {
token_type: TokenType,
token_str: String,
},
Branch {
token_type: TokenType,
children: Vec<Token>,
},
}
Expand description
Used for tokenizing Suiron source.
Variants§
Leaf
- Valid
token_type
s are:
Subgoal, Comma, Semicolon, LParen, RParen token_str
holds the item being parsed,
such as(
,;
, ora_subgoal(term1, term2)
.
Branch
This is a parent node.
- Valid
token_type
s are: Group, And, Or children
is a vector of child tokens
Implementations§
Source§impl Token
impl Token
Sourcepub fn number_of_children(&self) -> usize
pub fn number_of_children(&self) -> usize
Gets the number of children of a branch (parent) token.
§Arguments
self
§Return
number of children
§Panics
- If the token is not a branch token.
§Usage
use suiron::*;
let l1 = make_leaf_token("subgoal1()");
let l2 = make_leaf_token("subgoal2()");
let branch = make_branch_token(TokenType::And, vec![l1, l2]);
let n = branch.number_of_children(); // n = 2
Sourcepub fn get_token_str(&self) -> String
pub fn get_token_str(&self) -> String
Sourcepub fn get_children(&self) -> Vec<Token>
pub fn get_children(&self) -> Vec<Token>
Gets the child tokens of a parent (branch) token.
§Arguments
self
§Return
vector of tokens
§Panics
- If the token is not a branch token.
§Usage
use suiron::*;
let t1 = make_leaf_token("left");
let t2 = make_leaf_token("right");
let t3 = make_branch_token(TokenType::Or, vec![t1, t2]);
let children = t3.get_children();
println!("{:?}", children);
The above prints: [Leaf { token_type: Subgoal, token_str: "left" }, Leaf { token_type: Subgoal, token_str: "right" }]
Trait Implementations§
impl StructuralPartialEq for Token
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
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
Mutably borrows from an owned value. Read more