v.token: correct some comments, and add some missing comments (#8542)

pull/8549/head
yuyi 2021-02-04 15:18:38 +08:00 committed by GitHub
parent 162c42dbe9
commit a976876211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 56 additions and 54 deletions

View File

@ -22,31 +22,31 @@ pub enum Kind {
string // 'foo' string // 'foo'
str_inter // 'name=$user.name' str_inter // 'name=$user.name'
chartoken // `A` - rune chartoken // `A` - rune
plus plus // +
minus minus // -
mul mul // *
div div // /
mod mod // %
xor // ^ xor // ^
pipe // | pipe // |
inc // ++ inc // ++
dec // -- dec // --
and // && and // &&
logical_or logical_or // ||
not not // !
bit_not bit_not // ~
question question // ?
comma comma // ,
semicolon semicolon // ;
colon colon // :
arrow // <- arrow // <-
amp amp // &
hash hash // #
dollar dollar // $
at // @ at // @
str_dollar str_dollar
left_shift left_shift // <<
right_shift right_shift // >>
not_in // !in not_in // !in
not_is // !is not_is // !is
assign // = assign // =
@ -58,26 +58,26 @@ pub enum Kind {
xor_assign // ^= xor_assign // ^=
mod_assign // %= mod_assign // %=
or_assign // |= or_assign // |=
and_assign and_assign // &=
right_shift_assign right_shift_assign // <<=
left_shift_assign // {} () [] left_shift_assign // >>=
lcbr lcbr // {
rcbr rcbr // }
lpar lpar // (
rpar rpar // )
lsbr lsbr // [
rsbr // == != <= < >= > rsbr // ]
eq eq // ==
ne ne // !=
gt gt // >
lt lt // <
ge ge // >=
le le // <=
comment comment
nl nl
dot dot // .
dotdot dotdot // ..
ellipsis // keywords ellipsis // ...
keyword_beg keyword_beg
key_as key_as
key_asm key_asm
@ -99,7 +99,7 @@ pub enum Kind {
key_import key_import
key_in key_in
key_interface key_interface
key_is // key_it key_is
key_match key_match
key_module key_module
key_mut key_mut
@ -174,7 +174,7 @@ pub const (
fn build_keys() map[string]Kind { fn build_keys() map[string]Kind {
mut res := map[string]Kind{} mut res := map[string]Kind{}
for t in int(Kind.keyword_beg) + 1 .. int(Kind.keyword_end) { 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) res[key] = Kind(t)
} }
return res return res
@ -182,7 +182,7 @@ fn build_keys() map[string]Kind {
// TODO remove once we have `enum Kind { name('name') if('if') ... }` // TODO remove once we have `enum Kind { name('name') if('if') ... }`
fn build_token_str() []string { fn build_token_str() []string {
mut s := []string{len: nr_tokens} mut s := []string{len: token.nr_tokens}
s[Kind.unknown] = 'unknown' s[Kind.unknown] = 'unknown'
s[Kind.eof] = 'eof' s[Kind.eof] = 'eof'
s[Kind.name] = 'name' s[Kind.name] = 'name'
@ -301,7 +301,7 @@ pub const (
) )
pub fn key_to_token(key string) Kind { pub fn key_to_token(key string) Kind {
return Kind(keywords[key]) return Kind(token.keywords[key])
} }
pub fn is_key(key string) bool { 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 { pub fn is_decl(t Kind) bool {
return t in return t in [.key_enum, .key_interface, .key_fn, .key_struct, .key_type, .key_const, .key_pub,
[.key_enum, .key_interface, .key_fn, .key_struct, .key_type, .key_const, .key_pub, .eof] .eof,
]
} }
pub fn (t Kind) is_assign() bool { pub fn (t Kind) is_assign() bool {
return t in assign_tokens return t in token.assign_tokens
} }
pub fn (t Kind) str() string { pub fn (t Kind) str() string {
return token_str[int(t)] return token.token_str[int(t)]
} }
pub fn (t Token) str() string { pub fn (t Token) str() string {
@ -405,7 +406,7 @@ const (
// precedence returns a tokens precedence if defined, otherwise lowest_prec // precedence returns a tokens precedence if defined, otherwise lowest_prec
pub fn (tok Token) precedence() int { 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 // is_scalar returns true if the token is a scalar
@ -433,8 +434,9 @@ pub fn (kind Kind) is_prefix() bool {
} }
pub fn (kind Kind) is_infix() bool { pub fn (kind Kind) is_infix() bool {
return kind in return kind in [.plus, .minus, .mod, .mul, .div, .eq, .ne, .gt, .lt, .key_in, .key_as, .ge,
[.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] .le, .logical_or, .xor, .not_in, .key_is, .not_is, .and, .dot, .pipe, .amp, .left_shift,
.right_shift, .arrow]
} }
// Pass table.builtin_type_names // Pass table.builtin_type_names