Skip to content

Token text messed up in C target #107

@martinfschaefer

Description

@martinfschaefer

With a parser rule like this:

foo: '(' bar ')' -> ^(T_BAR[$bar.text] bar);

The returned string in the BAR token is corrupted.
The reason is that the following code is generated in the parser:

root_1 = (pANTLR3_BASE_TREE)(ADAPTOR->becomeRoot(ADAPTOR,
(pANTLR3_BASE_TREE)ADAPTOR->createTypeText(ADAPTOR, T_BAR,
(pANTLR3_UINT8)(STRSTREAM->toStringTT(STRSTREAM, bar90.start, bar90.stop))),
root_1));

The toStringTT() method returns a pANTLR3_STRING pointer.
But the createTypeText() method (and the createToken() method that it calls) expects a UTF-8 char string.
The pANTLR3_STRING is eventually cast to pANTLR3_UCHAR and the text state set to ANTLR3_TEXT_CHARP.
Reading the token text from the token results in gibberish.

Tested with both ANTLR 3.4 and 3.5.
Is there any workaround available?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions