token: minor clean up (#7163)

pull/7170/head
yuyi 2020-12-06 23:48:23 +08:00 committed by GitHub
parent 853dcc33c7
commit bac6be2273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions

View File

@ -179,7 +179,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: 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'
@ -295,8 +295,7 @@ const (
) )
pub fn key_to_token(key string) Kind { pub fn key_to_token(key string) Kind {
a := Kind(keywords[key]) return Kind(keywords[key])
return a
} }
pub fn is_key(key string) bool { pub fn is_key(key string) bool {
@ -353,7 +352,7 @@ pub enum Precedence {
} }
pub fn build_precedences() []Precedence { pub fn build_precedences() []Precedence {
mut p := []Precedence{len: int(Kind._end_), cap: int(Kind._end_)} mut p := []Precedence{len: int(Kind._end_)}
p[Kind.lsbr] = .index p[Kind.lsbr] = .index
p[Kind.dot] = .call p[Kind.dot] = .call
// `++` | `--` | `?` // `++` | `--` | `?`