Andrea Sindico
Andrea Sindico

Reputation: 7440

XText: first and last character truncated in custom STRING terminals

I have redefined the STRING terminal this way

terminal STRING : ('.'|'+'|'('|')'|'a'..'z'|'A'..'Z'|'_'|'0'..'9')*;

because I have to recognize STRING not delimited by " or '

the problem is that, though the generated parser works, it truncates the first and the last character of the recognized string. What am I missing?

Upvotes: 0

Views: 390

Answers (1)

Sebastian Zarnekow
Sebastian Zarnekow

Reputation: 6729

If you customize the STRING rule, you'll have to adapt the respective value converter, too.

Something like this has to be bound in your runtime module:

public class MyStringValueConverter extends STRINGValueConverter {

    @Override
    protected String toEscapedString(String value) {
        return value;
    }

    public String toValue(String string, INode node) {
        if (string == null)
            return null;
        return string;
    }
}

See the docs for details.

Upvotes: 1

Related Questions