]> granicus.if.org Git - icinga2/commitdiff
Implement the current_filename and current_line keywords
authorGunnar Beutner <gunnar@beutner.name>
Tue, 3 Nov 2015 15:34:34 +0000 (16:34 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 3 Nov 2015 15:34:34 +0000 (16:34 +0100)
fixes #10243

doc/18-language-reference.md
lib/base/configwriter.cpp
lib/config/config_lexer.ll
lib/config/config_parser.yy

index fbdaa5ffd4f06e1436a302efc58365c7a3d205e6..4100948a96c9e77effebeb246cd69cda09310ec9 100644 (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
index 1f4eecd88d476a1b281112a0ad05fd2e6af95dbc..bb160a97a4409ccfa4a45b3c4f7f544077e17318 100644 (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");
index 7827a183d7d37e2741db0dca6c35c631f603e696..7343a7635b64e2ea3a9f4866e55a906286d4ff05 100644 (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;
index a0f83b66362d81b36dcf46a026c8a6ddee15ecaa..271a22830ade379eedf974397b35e46b90b54824 100644 (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
        {