Selectively disable call setTokenBoundaries

11 views
Skip to first unread message

Nickolas Pohilets

unread,
Dec 20, 2014, 1:55:13 PM12/20/14
to antlr-di...@googlegroups.com
I have a problem with this grammar snippet:
cppClassBodyBlock
    : NEWLINE+ accessLevel ':' INDENT
      ( NEWLINE+ cppMember[$accessLevel.tree])+
      DEDENT
      -> cppMember+
    ;

cppMember[antlr3::ItemPtr accessLevel]
    : declaration -> ^(MEMBER {$accessLevel} declaration)
    ;

When there are multiple members in the block, setTokenBoundaries call in the cppClassBodyBlock is applied to nil node, that is discarded later, and I'm perfectly ok with this behavior. But if there is only one member, rulePostProcessing unwraps member tree from nil node and setTokenBoundaries is applied to member node itself. This results into corrupted location information.

How can I skip call to setTokenBoundaries or removal of the nil node?


Nickolas Pohilets

unread,
Dec 20, 2014, 3:38:57 PM12/20/14
to antlr-di...@googlegroups.com
I've solved the problem by subclassing tree adaptor and overriding setTokenBoundaries - customized version does nothing if token boundaries are already set.

Субота, 20 грудня 2014 р. 19:55:13 UTC+1 користувач Nickolas Pohilets написав:
Reply all
Reply to author
Forward
0 new messages