Implement the current_filename and current_line keywords

fixes #10243
This commit is contained in:
Gunnar Beutner 2015-11-03 16:34:34 +01:00
parent ae23e456a6
commit 51f473d08a
4 changed files with 26 additions and 0 deletions

View File

@ -859,6 +859,15 @@ supports:
Additional documentation on type methods is available in the
[library reference](19-library-reference.md#library-reference).
## <a id="location-information"></a> Location Information
The location of the currently executing script can be obtained using the
`current_filename` and `current_line` keywords.
Example:
log("Hello from '" + current_filename + "' in line " + current_line)
## <a id="reserved-keywords"></a> Reserved Keywords
These keywords are reserved and must not be used as constants or custom attributes.
@ -867,6 +876,7 @@ These keywords are reserved and must not be used as constants or custom attribut
template
include
include_recursive
ignore_on_error
library
null
true
@ -887,6 +897,8 @@ These keywords are reserved and must not be used as constants or custom attribut
if
else
in
current_filename
current_line
You can escape reserved keywords using the `@` character. The following example
tries to set `vars.include` which references a reserved keyword and generates

View File

@ -232,6 +232,8 @@ const std::vector<String>& ConfigWriter::GetKeywords(void)
keywords.push_back("locals");
keywords.push_back("use");
keywords.push_back("ignore_on_error");
keywords.push_back("current_filename");
keywords.push_back("current_line");
keywords.push_back("apply");
keywords.push_back("to");
keywords.push_back("where");

View File

@ -196,6 +196,8 @@ else return T_ELSE;
while return T_WHILE;
throw return T_THROW;
ignore_on_error return T_IGNORE_ON_ERROR;
current_filename return T_CURRENT_FILENAME;
current_line return T_CURRENT_LINE;
=\> return T_FOLLOWS;
\<\< return T_SHIFT_LEFT;
\>\> return T_SHIFT_RIGHT;

View File

@ -144,6 +144,8 @@ static void MakeRBinaryOp(Expression** result, Expression *left, Expression *rig
%token T_LOCALS "locals (T_LOCALS)"
%token T_CONST "const (T_CONST)"
%token T_IGNORE_ON_ERROR "ignore_on_error (T_IGNORE_ON_ERROR)"
%token T_CURRENT_FILENAME "current_filename (T_CURRENT_FILENAME)"
%token T_CURRENT_LINE "current_line (T_CURRENT_LINE)"
%token T_USE "use (T_USE)"
%token T_OBJECT "object (T_OBJECT)"
%token T_TEMPLATE "template (T_TEMPLATE)"
@ -799,6 +801,14 @@ rterm_no_side_effect: T_STRING
{
$$ = new GetScopeExpression(ScopeLocal);
}
| T_CURRENT_FILENAME
{
$$ = MakeLiteral(@$.Path);
}
| T_CURRENT_LINE
{
$$ = MakeLiteral(@$.FirstLine);
}
| rterm_array
| rterm_scope_require_side_effect
{