In my XText DSL, I want to be able to use three different kinds of text terminals. They are all used for adding comments on top of arrows drawn in a UML diagram:
Actor -> Actor: WORD
Actor -> Actor: A sequence of words on a single line
Actor -> Actor: A series of words on multiple lines
My initial approach was to use the ID terminal from the
org.eclipse.xtext.common.Terminals as my WORD terminal, and then just have SL_STRINGS be
(WORD)*, and ML_STRINGS be
(NEWLINE? WORD)*, but this creates a lot of problems with ambiguity between the rules.
How would I go about structuring this in a good way?
More information about the project. (And as this is the first time working with XText, please bear with me):
I am trying to implement a DSL to be used together with the Eclipse Plugin for PlantUML http://plantuml.sourceforge.net/sequence.html mainly for Syntax Checking and Colorization. Currently my grammar works as such:
Model: (diagrams+=Diagram)*; Diagram: [email protected]' NEWLINE (instructions+=(Instruction))* [email protected]' NEWLINE* ;
An instruction can be lots of things:
Instruction: ((name1=ID SEQUENCE name2=ID (':' ID)?) | Definition (Color)? | AutoNumber | Title | Legend | Newpage | AltElse | GroupingMessages | Note | Divider | Reference | Delay | Space | Hidefootbox | Lifeline | ParticipantCreation | Box)? NEWLINE ;
Example of rules that need different kinds of text terminals:
Group: 'group' TEXT ; Reference: 'ref over' ID (',' ID)* ((':' SL_TEXT)|((ML_TEXT) NEWLINE 'end ref')) ;
For Group, the text can only be on one line, while for Reference, the text can be on two lines if there is no ":" follwing the rule call.
Currently my terminals look like this:
terminal NEWLINE : ('\r'? '\n'); // Multiline comment begins with /', and ends with '/ terminal ML_COMMENT : '/\'' -> '\'/'; // Singleline comment begins with ', and continues until end of line. terminal SL_COMMENT : '\'' !('\n'|'\r')* ('\r'? '\n')?; // INT is a sequence of numbers 0-9. terminal INT returns ecore::EInt: ('0'..'9')+; terminal WS : (' '|'\t')+; terminal ANY_OTHER: .;
And I want on top of this to add to this add three new terminals that takes care of the text.