Location metavariables are attached to a token with the '@' characted.
A position metavariable contain the following information relative to its token:
| Field | Information |
|---|---|
| file | the name of the current source file |
| current_element | the name of the function currently proceed |
| line | the starting line number of the token |
| column | the starting character position of the token |
| line_end | the ending line number of the token |
| column_end | the ending character position of the token |
All of these are represented as strings, even the line and column numbers.
The ending position is useful when a position p is attached to expression E by E@p.
In that case, the expression matched may span over several lines.
The following pattern:
@ if_stmt1
disable neg_if
@
expression E_1;
statement S_1, S_e;
position p_1;
@@
if@p_1 (E_1)
S_1
else
S_e
@
script:python @ expr_1 << if_stmt1.E_1;
loc_1 << if_stmt1.p_1;
@@
print loc_1[0].file, " ", loc_1[0].line, " ", loc_1[0].column, " ", expr_1
will print the name of the file, line number and column number of every if-statement in the source (along with its controlling expression).