Allow using { $__loc__ } as shorthand for { __loc__: $__loc__ }
n.b.: { $__loc__: "foo" } is still not allowed.
$__loc__ cannot be overwritten, and it is always an object.
Using { $x: "foo" } where $x is not a string is an error, so there is
not much of a point in supporting that.
This commit is contained in:
1 parent
841445eea7
commit
6ca7973d49
3 files changed
+1059
-1029
No files matched your search
+10
-2
@@ -300,6 +300,11 @@ static block gen_update(block object, block val, int optype) {
|
||||
optype)))));
|
||||
}
|
||||
|
||||
static block gen_loc_object(location *loc, struct locfile *locations) {
|
||||
return gen_const(JV_OBJECT(jv_string("file"), jv_copy(locations->fname),
|
||||
jv_string("line"), jv_number(locfile_get_line(locations, loc->start) + 1)));
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%%
|
||||
@@ -780,8 +785,7 @@ BINDING {
|
||||
jv_free($1);
|
||||
} |
|
||||
"$__loc__" {
|
||||
$$ = gen_const(JV_OBJECT(jv_string("file"), jv_copy(locations->fname),
|
||||
jv_string("line"), jv_number(locfile_get_line(locations, @$.start) + 1)));
|
||||
$$ = gen_loc_object(&@$, locations);
|
||||
} |
|
||||
IDENT {
|
||||
const char *s = jv_string_value($1);
|
||||
@@ -981,6 +985,10 @@ IDENT ':' ExpD {
|
||||
$$ = gen_dictpair(gen_const(jv_copy($1)),
|
||||
gen_index(gen_noop(), gen_const($1)));
|
||||
}
|
||||
| "$__loc__" {
|
||||
$$ = gen_dictpair(gen_const(jv_string("__loc__")),
|
||||
gen_loc_object(&@$, locations));
|
||||
}
|
||||
| Keyword {
|
||||
$$ = gen_dictpair(gen_const(jv_copy($1)),
|
||||
gen_index(gen_noop(), gen_const($1)));
|
||||
|
||||
Reference in new issue
Block a user