Handling semantic whitespace: forcefully avoiding it [message #1768792] |
Mon, 24 July 2017 00:12 |
David Black Messages: 33 Registered: June 2017 |
Member |
|
|
Hi,
I'm trying to apply what I've read in the official docs and on this forum to handle semantic whitespace, but I'm not able to make it work.
My case is simple: accepting strings like "variable_name$" and rejecting strings like "variable_name $". That is: there cannot be any blank between a variable's name and the "$" postfix operator.
(In reality, "variable_name" is a complex datatype rule, not a terminal, in my real language. I'm assuming it's a terminal here just for demo purposes.)
My demo-purposes grammar looks like this:
grammar org.xtext.example.mydsl.MyDsl
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model hidden(WS):
source+=Expression*;
Expression hidden():
ID '$';
terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal WS : (' '|'\t'|'\r'|'\n')+;
But that grammar accepts e.g. both "variable1$" and "variable2 $", what is not what I want (accepting 'variable1$' is OK, but 'variable2 $' is illegal because it contains blanks between the identifier and the operator). And I don't know why.
Can anyone point out what I'm doing wrong?
Thanks in advance.
David
[Updated on: Mon, 24 July 2017 00:13] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04270 seconds