mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
token: add @FILE_LEN (#15661)
This commit is contained in:
parent
d0d5f1d4e0
commit
90c2c5b8a4
@ -5580,8 +5580,9 @@ that are substituted at compile time:
|
||||
- `@METHOD` => replaced with ReceiverType.MethodName
|
||||
- `@MOD` => replaced with the name of the current V module
|
||||
- `@STRUCT` => replaced with the name of the current V struct
|
||||
- `@FILE` => replaced with the path of the V source file
|
||||
- `@FILE` => replaced with the absolute path of the V source file
|
||||
- `@LINE` => replaced with the V line number where it appears (as a string).
|
||||
- `@FILE_LINE` => like `@FILE:@LINE`, but the file part is a relative path
|
||||
- `@COLUMN` => replaced with the column where it appears (as a string).
|
||||
- `@VEXE` => replaced with the path to the V compiler
|
||||
- `@VEXEROOT` => will be substituted with the *folder*,
|
||||
|
@ -2643,6 +2643,9 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
|
||||
.line_nr {
|
||||
node.val = (node.pos.line_nr + 1).str()
|
||||
}
|
||||
.file_path_line_nr {
|
||||
node.val = os.file_name(c.file.path) + ':' + (node.pos.line_nr + 1).str()
|
||||
}
|
||||
.column_nr {
|
||||
node.val = (node.pos.col + 1).str()
|
||||
}
|
||||
|
@ -319,6 +319,7 @@ fn (mut p Parser) at() ast.AtExpr {
|
||||
'@STRUCT' { token.AtKind.struct_name }
|
||||
'@FILE' { token.AtKind.file_path }
|
||||
'@LINE' { token.AtKind.line_nr }
|
||||
'@FILE_LINE' { token.AtKind.file_path_line_nr }
|
||||
'@COLUMN' { token.AtKind.column_nr }
|
||||
'@VHASH' { token.AtKind.vhash }
|
||||
'@VMOD_FILE' { token.AtKind.vmod_file }
|
||||
|
@ -71,6 +71,12 @@ fn test_at_file() {
|
||||
assert f == 'comptime_at_test.v'
|
||||
}
|
||||
|
||||
fn test_at_file_len() {
|
||||
// Test @FILE_LINE
|
||||
line1, line2 := '${@LINE}', '${@FILE_LINE}'
|
||||
assert os.file_name(@FILE) + ':' + line1.str() == line2
|
||||
}
|
||||
|
||||
fn test_at_fn() {
|
||||
// Test @FN
|
||||
assert @FN == 'test_at_fn'
|
||||
|
@ -173,6 +173,7 @@ pub enum AtKind {
|
||||
vmodroot_path
|
||||
vroot_path // obsolete
|
||||
vexeroot_path
|
||||
file_path_line_nr
|
||||
}
|
||||
|
||||
pub const (
|
||||
@ -181,7 +182,7 @@ pub const (
|
||||
.unsigned_right_shift_assign]
|
||||
|
||||
valid_at_tokens = ['@VROOT', '@VMODROOT', '@VEXEROOT', '@FN', '@METHOD', '@MOD', '@STRUCT',
|
||||
'@VEXE', '@FILE', '@LINE', '@COLUMN', '@VHASH', '@VMOD_FILE']
|
||||
'@VEXE', '@FILE', '@LINE', '@COLUMN', '@VHASH', '@VMOD_FILE', '@FILE_LINE']
|
||||
|
||||
token_str = build_token_str()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user