Files
lib_ruby_parser
bytes
containers
error
lexer
loc
nodes
node_enum
types
alias
and
and_asgn
arg
args
array
array_pattern
array_pattern_with_tail
back_ref
begin
block
block_pass
blockarg
break_
c_send
case
case_match
casgn
cbase
class
complex
const_
const_pattern
cvar
cvasgn
def
defined
defs
dstr
dsym
e_flip_flop
empty_else
encoding
ensure
erange
false_
file
find_pattern
float
for_
forward_arg
forwarded_args
gvar
gvasgn
hash
hash_pattern
heredoc
i_flip_flop
if_
if_guard
if_mod
if_ternary
in_pattern
index
index_asgn
int
irange
ivar
ivasgn
kw_begin
kwarg
kwargs
kwnilarg
kwoptarg
kwrestarg
kwsplat
lambda
line
lvar
lvasgn
masgn
match_alt
match_as
match_current_line
match_nil_pattern
match_pattern
match_pattern_p
match_rest
match_var
match_with_lvasgn
mlhs
module
next
nil
nth_ref
numblock
op_asgn
optarg
or
or_asgn
pair
pin
postexe
preexe
procarg0
rational
redo
reg_opt
regexp
rescue
rescue_body
restarg
retry
return_
s_class
self_
send
shadowarg
splat
str_
super_
sym
true_
undef
unless_guard
until
until_post
when
while_
while_post
x_heredoc
xstr
yield_
z_super
parser
parser_options
parser_result
reserved_words
source
token
traverse
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use crate::{Bytes, LexState, Loc};

/// A token that is emitted by a lexer and consumed by a parser
#[derive(Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Token {
    /// Numeric representation of the token type,
    /// e.g. 42 (for example) for tINTEGER
    token_type: i32,

    /// Value of the token,
    /// e.g "42" for 42
    token_value: Bytes,

    /// Location of the token
    loc: Loc,

    /// Lex state **before** reading the token
    lex_state_before: LexState,

    /// Lex state **after** reading the token
    lex_state_after: LexState,
}

impl Token {
    /// Constructor
    pub fn new(
        token_type: i32,
        token_value: Bytes,
        loc: Loc,
        lex_state_before: LexState,
        lex_state_after: LexState,
    ) -> Self {
        Self {
            token_type,
            token_value,
            loc,
            lex_state_before,
            lex_state_after,
        }
    }

    /// Returns type of the token
    pub fn token_type(&self) -> i32 {
        self.token_type
    }

    /// Returns type of the token
    pub fn token_value(&self) -> &Bytes {
        &self.token_value
    }

    /// Sets token value
    pub fn set_token_value(&mut self, token_value: Bytes) {
        self.token_value = token_value
    }

    /// Consumes self, returns owned values of the token
    pub fn into_token_value(self) -> Bytes {
        self.token_value
    }

    /// Returns location of the token
    pub fn loc(&self) -> &Loc {
        &self.loc
    }

    /// Returns lex state **before** reading the token
    pub fn lex_state_before(&self) -> LexState {
        self.lex_state_before
    }

    /// Returns lex state **after** reading the token
    pub fn lex_state_after(&self) -> LexState {
        self.lex_state_after
    }
}