parser,checker: support @METHOD, replaced by 'ReceiverType.MethodName'
parent
d30f94507c
commit
25a3873019
|
@ -3516,6 +3516,7 @@ V also gives your code access to a set of pseudo string variables,
|
||||||
that are substituted at compile time:
|
that are substituted at compile time:
|
||||||
|
|
||||||
- `@FN` => replaced with the name of the current V function
|
- `@FN` => replaced with the name of the current V function
|
||||||
|
- `@METHOD` => replaced with ReceiverType.MethodName
|
||||||
- `@MOD` => replaced with the name of the current V module
|
- `@MOD` => replaced with the name of the current V module
|
||||||
- `@STRUCT` => replaced with the name of the current V struct
|
- `@STRUCT` => replaced with the name of the current V struct
|
||||||
- `@FILE` => replaced with the path of the V source file
|
- `@FILE` => replaced with the path of the V source file
|
||||||
|
|
|
@ -3911,6 +3911,15 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) table.Type {
|
||||||
.fn_name {
|
.fn_name {
|
||||||
node.val = c.cur_fn.name.all_after_last('.')
|
node.val = c.cur_fn.name.all_after_last('.')
|
||||||
}
|
}
|
||||||
|
.method_name {
|
||||||
|
fname := c.cur_fn.name.all_after_last('.')
|
||||||
|
if c.cur_fn.is_method {
|
||||||
|
node.val = c.table.type_to_str(c.cur_fn.receiver.typ).all_after_last('.') + '.' +
|
||||||
|
fname
|
||||||
|
} else {
|
||||||
|
node.val = fname
|
||||||
|
}
|
||||||
|
}
|
||||||
.mod_name {
|
.mod_name {
|
||||||
node.val = c.cur_fn.mod
|
node.val = c.cur_fn.mod
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,6 +255,7 @@ fn (mut p Parser) at() ast.AtExpr {
|
||||||
name := p.tok.lit
|
name := p.tok.lit
|
||||||
kind := match name {
|
kind := match name {
|
||||||
'@FN' { token.AtKind.fn_name }
|
'@FN' { token.AtKind.fn_name }
|
||||||
|
'@METHOD' { token.AtKind.method_name }
|
||||||
'@MOD' { token.AtKind.mod_name }
|
'@MOD' { token.AtKind.mod_name }
|
||||||
'@STRUCT' { token.AtKind.struct_name }
|
'@STRUCT' { token.AtKind.struct_name }
|
||||||
'@VEXE' { token.AtKind.vexe_path }
|
'@VEXE' { token.AtKind.vexe_path }
|
||||||
|
|
|
@ -51,11 +51,13 @@ fn (mut t TestFn) tst_1() {
|
||||||
|
|
||||||
fn (mut t TestFn) tst_2(cb fn (int)) {
|
fn (mut t TestFn) tst_2(cb fn (int)) {
|
||||||
assert @FN == 'tst_2'
|
assert @FN == 'tst_2'
|
||||||
|
assert @METHOD == 'TestFn.tst_2'
|
||||||
cb(1)
|
cb(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fn_name_mod_level() {
|
fn fn_name_mod_level() {
|
||||||
assert @FN == 'fn_name_mod_level'
|
assert @FN == 'fn_name_mod_level'
|
||||||
|
assert @METHOD == 'fn_name_mod_level'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fn_name_mod_level_high_order(cb fn (int)) {
|
fn fn_name_mod_level_high_order(cb fn (int)) {
|
||||||
|
|
|
@ -136,6 +136,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// @FN => will be substituted with the name of the current V function
|
// @FN => will be substituted with the name of the current V function
|
||||||
|
// @METHOD => will be substituted with ReceiverType.MethodName
|
||||||
// @MOD => will be substituted with the name of the current V module
|
// @MOD => will be substituted with the name of the current V module
|
||||||
// @STRUCT => will be substituted with the name of the current V struct
|
// @STRUCT => will be substituted with the name of the current V struct
|
||||||
// @VEXE => will be substituted with the path to the V compiler
|
// @VEXE => will be substituted with the path to the V compiler
|
||||||
|
@ -153,6 +154,7 @@ const (
|
||||||
pub enum AtKind {
|
pub enum AtKind {
|
||||||
unknown
|
unknown
|
||||||
fn_name
|
fn_name
|
||||||
|
method_name
|
||||||
mod_name
|
mod_name
|
||||||
struct_name
|
struct_name
|
||||||
vexe_path
|
vexe_path
|
||||||
|
@ -164,9 +166,8 @@ pub enum AtKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
valid_at_tokens = ['@FN', '@MOD', '@STRUCT', '@VEXE', '@FILE', '@LINE', '@COLUMN', '@VHASH',
|
valid_at_tokens = ['@FN', '@METHOD', '@MOD', '@STRUCT', '@VEXE', '@FILE', '@LINE', '@COLUMN',
|
||||||
'@VMOD_FILE',
|
'@VHASH', '@VMOD_FILE']
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// build_keys genereates a map with keywords' string values:
|
// build_keys genereates a map with keywords' string values:
|
||||||
|
|
Loading…
Reference in New Issue