Search code examples
grammarxtext

Ignore whitespace in Xtext rule


I have the following rule:

ASTMin:
    MinKeyword '(' expression=ASTSimple ')';

MinKeyword: 'min';

For an expression like min (4) the parser creates the error message:

extraneous input ' ' expecting '('

Where can I disable the whitespace behaviour?


Solution

  • To solve it just add the terminal rule "WS" in hidden in the top of your grammar as following:

    grammar org.your.Dsl hidden(WS, ML_COMMENT, SL_COMMENT)
    

    If you are using the Xtext Terminals grammar :

    grammar org.your.Dsl with org.eclipse.xtext.common.Terminals hidden(WS, ML_COMMENT, SL_COMMENT)