dsl - XTEXT: Controlling when whitespace is allowed -
i have custom scripting language, attempting use xtext syntax checking. boils down single line commands in format
command:parameters
for part, xtext working great. problem have run how handle wanted (or unwanted) white spaces. language cannot have space begin line, , there cannot space following colon. well, need allow white space in parameters, string of text, or similar.
i have used datatype allow white space in parameter:
unquoted_string: (id | int | ws | '.' )+ ;
this works, has side effect of allowing spaces throughout line.
does know way limit white spaces allowed?
thanks in advance advice!
you can disallow whitespace globally grammar using empty set of hidden tokens, e.g.
grammar org.xyz.mydsl org.eclipse.xtext.common.terminals hidden()
then can enable @ specific rules, e.g.
xparameter hidden(ws): 'x' '=' value=id ;
note allow linebreaks well. if don't want can either pass custom terminal rule or overwrite default ws
rule.
here more complete example (not perfect):
grammar org.xtext.example.mydsl.mydsl org.eclipse.xtext.common.terminals hidden() generate mydsl "http://www.xtext.org/example/mydsl/mydsl" model: (commands+=command '\r'? '\n')+ ; command: samplecommand ; samplecommand: command='get' ':' parameter=parameter ; parameter: '{' x=xparameter '}' ; xparameter hidden(ws): 'x' '=' value=id ;
this parse commands such as:
get:{x=test} get:{ x = test}
but reject:
get:{x=test} get: {x=test}
hope gives idea. can other way around limiting whitespace rules, e.g.
commandlist hidden(): (commands+=command '\r'? '\n')+ ;
if works better grammar.
Comments
Post a Comment