Yes, through the following technique:
- Make sure the
}
does not get omitted from the AST.- If you are using the rewrite operator
->
, this means the}
token needs to appear on the right hand side. - If you are using the AST operators
^
and!
, this means you can't use the!
operator on your}
token.
- If you are using the rewrite operator
- Find the
CommonTree
corresponding to the}
token, and callgetLine()
on the token to get the line number.
Edit: Here is the current block
rule in the grammar:
block
: LCURLY blockStatement* RCURLY
-> ^(BLOCK_SCOPE[$LCURLY, "BLOCK_SCOPE"] blockStatement*)
;
As you can see, the rewrite rule does not include the RCURLY
token, so information about the position of the end of the block is omitted. The rule can be modified to include the token:
block
: LCURLY blockStatement* RCURLY
-> ^(BLOCK_SCOPE[$LCURLY, "BLOCK_SCOPE"] blockStatement* RCURLY)
;
Note that this requires updating the corresponding in the tree grammar as well.
block
: ^(BLOCK_SCOPE blockStatement* RCURLY)
;