mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.token: correct some comments, and add some missing comments (#8542)
This commit is contained in:
parent
162c42dbe9
commit
a976876211
@ -5,13 +5,13 @@ module token
|
||||
|
||||
pub struct Token {
|
||||
pub:
|
||||
kind Kind // the token number/enum; for quick comparisons
|
||||
kind Kind // the token number/enum; for quick comparisons
|
||||
lit string // literal representation of the token
|
||||
line_nr int // the line number in the source where the token occured
|
||||
line_nr int // the line number in the source where the token occured
|
||||
// name_idx int // name table index for O(1) lookup
|
||||
pos int // the position of the token in scanner text
|
||||
len int // length of the literal
|
||||
tidx int // the index of the token
|
||||
pos int // the position of the token in scanner text
|
||||
len int // length of the literal
|
||||
tidx int // the index of the token
|
||||
}
|
||||
|
||||
pub enum Kind {
|
||||
@ -22,31 +22,31 @@ pub enum Kind {
|
||||
string // 'foo'
|
||||
str_inter // 'name=$user.name'
|
||||
chartoken // `A` - rune
|
||||
plus
|
||||
minus
|
||||
mul
|
||||
div
|
||||
mod
|
||||
plus // +
|
||||
minus // -
|
||||
mul // *
|
||||
div // /
|
||||
mod // %
|
||||
xor // ^
|
||||
pipe // |
|
||||
inc // ++
|
||||
dec // --
|
||||
and // &&
|
||||
logical_or
|
||||
not
|
||||
bit_not
|
||||
question
|
||||
comma
|
||||
semicolon
|
||||
colon
|
||||
logical_or // ||
|
||||
not // !
|
||||
bit_not // ~
|
||||
question // ?
|
||||
comma // ,
|
||||
semicolon // ;
|
||||
colon // :
|
||||
arrow // <-
|
||||
amp
|
||||
hash
|
||||
dollar
|
||||
amp // &
|
||||
hash // #
|
||||
dollar // $
|
||||
at // @
|
||||
str_dollar
|
||||
left_shift
|
||||
right_shift
|
||||
left_shift // <<
|
||||
right_shift // >>
|
||||
not_in // !in
|
||||
not_is // !is
|
||||
assign // =
|
||||
@ -58,26 +58,26 @@ pub enum Kind {
|
||||
xor_assign // ^=
|
||||
mod_assign // %=
|
||||
or_assign // |=
|
||||
and_assign
|
||||
right_shift_assign
|
||||
left_shift_assign // {} () []
|
||||
lcbr
|
||||
rcbr
|
||||
lpar
|
||||
rpar
|
||||
lsbr
|
||||
rsbr // == != <= < >= >
|
||||
eq
|
||||
ne
|
||||
gt
|
||||
lt
|
||||
ge
|
||||
le
|
||||
and_assign // &=
|
||||
right_shift_assign // <<=
|
||||
left_shift_assign // >>=
|
||||
lcbr // {
|
||||
rcbr // }
|
||||
lpar // (
|
||||
rpar // )
|
||||
lsbr // [
|
||||
rsbr // ]
|
||||
eq // ==
|
||||
ne // !=
|
||||
gt // >
|
||||
lt // <
|
||||
ge // >=
|
||||
le // <=
|
||||
comment
|
||||
nl
|
||||
dot
|
||||
dotdot
|
||||
ellipsis // keywords
|
||||
dot // .
|
||||
dotdot // ..
|
||||
ellipsis // ...
|
||||
keyword_beg
|
||||
key_as
|
||||
key_asm
|
||||
@ -99,7 +99,7 @@ pub enum Kind {
|
||||
key_import
|
||||
key_in
|
||||
key_interface
|
||||
key_is // key_it
|
||||
key_is
|
||||
key_match
|
||||
key_module
|
||||
key_mut
|
||||
@ -132,7 +132,7 @@ pub const (
|
||||
)
|
||||
|
||||
const (
|
||||
nr_tokens = int(Kind._end_)
|
||||
nr_tokens = int(Kind._end_)
|
||||
)
|
||||
|
||||
// @FN => will be substituted with the name of the current V function
|
||||
@ -174,7 +174,7 @@ pub const (
|
||||
fn build_keys() map[string]Kind {
|
||||
mut res := map[string]Kind{}
|
||||
for t in int(Kind.keyword_beg) + 1 .. int(Kind.keyword_end) {
|
||||
key := token_str[t]
|
||||
key := token.token_str[t]
|
||||
res[key] = Kind(t)
|
||||
}
|
||||
return res
|
||||
@ -182,7 +182,7 @@ fn build_keys() map[string]Kind {
|
||||
|
||||
// TODO remove once we have `enum Kind { name('name') if('if') ... }`
|
||||
fn build_token_str() []string {
|
||||
mut s := []string{len: nr_tokens}
|
||||
mut s := []string{len: token.nr_tokens}
|
||||
s[Kind.unknown] = 'unknown'
|
||||
s[Kind.eof] = 'eof'
|
||||
s[Kind.name] = 'name'
|
||||
@ -297,11 +297,11 @@ const (
|
||||
)
|
||||
|
||||
pub const (
|
||||
keywords = build_keys()
|
||||
keywords = build_keys()
|
||||
)
|
||||
|
||||
pub fn key_to_token(key string) Kind {
|
||||
return Kind(keywords[key])
|
||||
return Kind(token.keywords[key])
|
||||
}
|
||||
|
||||
pub fn is_key(key string) bool {
|
||||
@ -309,16 +309,17 @@ pub fn is_key(key string) bool {
|
||||
}
|
||||
|
||||
pub fn is_decl(t Kind) bool {
|
||||
return t in
|
||||
[.key_enum, .key_interface, .key_fn, .key_struct, .key_type, .key_const, .key_pub, .eof]
|
||||
return t in [.key_enum, .key_interface, .key_fn, .key_struct, .key_type, .key_const, .key_pub,
|
||||
.eof,
|
||||
]
|
||||
}
|
||||
|
||||
pub fn (t Kind) is_assign() bool {
|
||||
return t in assign_tokens
|
||||
return t in token.assign_tokens
|
||||
}
|
||||
|
||||
pub fn (t Kind) str() string {
|
||||
return token_str[int(t)]
|
||||
return token.token_str[int(t)]
|
||||
}
|
||||
|
||||
pub fn (t Token) str() string {
|
||||
@ -405,7 +406,7 @@ const (
|
||||
|
||||
// precedence returns a tokens precedence if defined, otherwise lowest_prec
|
||||
pub fn (tok Token) precedence() int {
|
||||
return int(precedences[tok.kind])
|
||||
return int(token.precedences[tok.kind])
|
||||
}
|
||||
|
||||
// is_scalar returns true if the token is a scalar
|
||||
@ -416,7 +417,7 @@ pub fn (tok Token) is_scalar() bool {
|
||||
// is_unary returns true if the token can be in a unary expression
|
||||
pub fn (tok Token) is_unary() bool {
|
||||
// `+` | `-` | `!` | `~` | `*` | `&` | `<-`
|
||||
return tok.kind in [ .plus, .minus, .not, .bit_not, .mul, .amp, .arrow]
|
||||
return tok.kind in [.plus, .minus, .not, .bit_not, .mul, .amp, .arrow]
|
||||
}
|
||||
|
||||
pub fn (tok Kind) is_relational() bool {
|
||||
@ -433,8 +434,9 @@ pub fn (kind Kind) is_prefix() bool {
|
||||
}
|
||||
|
||||
pub fn (kind Kind) is_infix() bool {
|
||||
return kind in
|
||||
[.plus, .minus, .mod, .mul, .div, .eq, .ne, .gt, .lt, .key_in, .key_as, .ge, .le, .logical_or, .xor, .not_in, .key_is, .not_is, .and, .dot, .pipe, .amp, .left_shift, .right_shift, .arrow]
|
||||
return kind in [.plus, .minus, .mod, .mul, .div, .eq, .ne, .gt, .lt, .key_in, .key_as, .ge,
|
||||
.le, .logical_or, .xor, .not_in, .key_is, .not_is, .and, .dot, .pipe, .amp, .left_shift,
|
||||
.right_shift, .arrow]
|
||||
}
|
||||
|
||||
// Pass table.builtin_type_names
|
||||
|
Loading…
Reference in New Issue
Block a user