1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: remove unused enum value and improve error message for @ tokens in scanner (#6751)

This commit is contained in:
Larpon 2020-11-05 11:59:49 +01:00 committed by GitHub
parent 785bf40f67
commit 4051ce869c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 5 deletions

View File

@ -3053,8 +3053,9 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) table.Type {
}
node.val = c.vmod_file_content
}
.unknown, ._end_ {
c.error('unknown @ identifier: $node.name', node.pos)
.unknown {
c.error('unknown @ identifier: ${node.name}. Available identifiers: $token.valid_at_tokens',
node.pos)
}
}
return table.string_type

View File

@ -760,7 +760,12 @@ fn (mut s Scanner) text_scan() token.Token {
return s.new_token(.at, '@' + name, name.len + 1)
}
if !token.is_key(name) {
s.error('@ must be used before keywords (e.g. `@type string`)')
mut at_error_msg := '@ must be used before keywords or compile time variables (e.g. `@type string` or `@FN`)'
// If name is all uppercase, the user is probably looking for a compile time variable ("at-token")
if name.is_upper() {
at_error_msg += '\nAvailable compile time variables:\n$token.valid_at_tokens'
}
s.error(at_error_msg)
}
return s.new_token(.name, name, name.len)
}

View File

@ -164,11 +164,9 @@ pub enum AtKind {
column_nr
vhash
vmod_file
_end_
}
const (
valid_at_tokens = ['@FN','@MOD','@STRUCT','@VEXE','@FILE','@LINE','@COLUMN','@VHASH','@VMOD_FILE']
//valid_at_tokens_len = int(AtKind._end_)
)
// build_keys genereates a map with keywords' string values: