Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » DSL with XText for PlantUML class diagrams
DSL with XText for PlantUML class diagrams [message #1724059] Sat, 20 February 2016 11:38 Go to next message
Tobias Schmidt is currently offline Tobias SchmidtFriend
Messages: 5
Registered: February 2016
Junior Member
Hey there,

currently I'm trying to create a DSL for PlantUML class diagrams and I already covered most of the features. Unfortunately I'm not able to get associations between classes to be parsed correctly. Some examples for the syntax:

Alice *-- Bob
Alice -[#ff0022]- Bob
Alice --|> Bob
Alice .. Bob
Alice <-[#Red]- Bob


I've already asked at Stackoverflow but the response doesn't really solve my problem for associations.
The part of the grammar currently looks like that:

Class:
	{Class}
	'class' name=ID;

Association:
	{Association}
	(classLeft=[Class]
	associationArrow=AssociationArrow
	classRight=[Class])
	(':' text+=(ID)*)?;

AssociationArrow:
	{AssociationArrow}
	leftType=AssociationTypeLeft?
	('-'|'.') ("[" color=ColorTag "]")? ('-'|'.')
	rightType=AssociationTypeRight?;

ColorTag:
	COLOR | HEXCODE;

enum AssociationTypeLeft:
	UNDEFINED
	| DIRECTIONAL='<'
	| INHERITANCE='<|'
	| AGGREGATION='o'
	| COMPOSITION='*';

enum AssociationTypeRight:
	UNDEFINED
	| DIRECTIONAL='>'
	| INHERITANCE='|>'
	| AGGREGATION='o'
	| COMPOSITION='*';

terminal COLOR:
	"#" ('Red','Blue', ... );

terminal HEXCODE:
	"#"
	('A' .. 'F'|'0' .. '9')('A' .. 'F'|'0' .. '9')('A' .. 'F'|'0' .. '9')
	('A' .. 'F'|'0' .. '9')('A' .. 'F'|'0' .. '9')('A' .. 'F'|'0' .. '9');

terminal ID:
	('a'..'z' | 'A'..'Z' | '_' | '0'..'9' | '\"\"' | '//' | '\\')
	('a'..'z' | 'A'..'Z' | '_' | '0'..'9' | '\"\"' | '//' | '\\' | ':')*;


I'm out of options what I could try next, so any help is appreciated!
Re: DSL with XText for PlantUML class diagrams [message #1724061 is a reply to message #1724059] Sat, 20 February 2016 12:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14076
Registered: July 2009
Senior Member
hi,

the way to go is to use datatype rules and do the range checks in valueconverters


Class:
	{Class}
	'class' name=ID;

Association:
	{Association}
	(classLeft=[Class]
	associationArrow=AssociationArrow
	classRight=[Class])
	(':' text+=(ID)*)?;

AssociationArrow:
	{AssociationArrow}
	leftType=AssociationTypeLeft?
	('-'|'.') ("[" color=ColorTag "]")? ('-'|'.')
	rightType=AssociationTypeRight?;

ColorTag:
	COLOR | HEXCODE;

enum AssociationTypeLeft:
	UNDEFINED
	| DIRECTIONAL='<'
	| INHERITANCE='<|'
	| AGGREGATION='o'
	| COMPOSITION='*';

enum AssociationTypeRight:
	UNDEFINED
	| DIRECTIONAL='>'
	| INHERITANCE='|>'
	| AGGREGATION='o'
	| COMPOSITION='*';

COLOR:
	"#" ('Red'|'Blue');
	
HEXCODE: "#" ID;	
	

terminal ID:
	('a'..'z' | 'A'..'Z' | '_' | '0'..'9' | '\"\"' | '//' | '\\')
	('a'..'z' | 'A'..'Z' | '_' | '0'..'9' | '\"\"' | '//' | '\\' | ':')*;



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DSL with XText for PlantUML class diagrams [message #1724070 is a reply to message #1724061] Sat, 20 February 2016 16:59 Go to previous messageGo to next message
Tobias Schmidt is currently offline Tobias SchmidtFriend
Messages: 5
Registered: February 2016
Junior Member
Thanks for the hint but I have no clue how it should be done concretely.

Alice <-[#FFFFFF]-* Bob

What's in my mind:
1) divide the association in it's colored parts.
2) use an value converter for both of its edges to check which AssociationType it is and return the enum constant.

I'm already stuck on the division. How do I get each colored part and check for valid characters before passing them to a value converter? Or should I pass the whole arrow?
I'm like totally lost and the basic examples I found for value converters didn't help me either.
Re: DSL with XText for PlantUML class diagrams [message #1724072 is a reply to message #1724070] Sat, 20 February 2016 18:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14076
Registered: July 2009
Senior Member
The value converter gives you the whole thing
As string. Please post what you have


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DSL with XText for PlantUML class diagrams [message #1724076 is a reply to message #1724072] Sat, 20 February 2016 19:28 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 83
Registered: January 2016
Location: Kiel
Member

Why a value converter?
A simple validation would be a better way to give the user feedback.

[Updated on: Sat, 20 February 2016 19:29]

Report message to a moderator

Re: DSL with XText for PlantUML class diagrams [message #1724080 is a reply to message #1724076] Sat, 20 February 2016 19:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14076
Registered: July 2009
Senior Member
that would work in this case as well (asuming this is a editor only)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: DSL with XText for PlantUML class diagrams [message #1724138 is a reply to message #1724072] Sun, 21 February 2016 16:24 Go to previous messageGo to next message
Tobias Schmidt is currently offline Tobias SchmidtFriend
Messages: 5
Registered: February 2016
Junior Member
Christian Dietrich wrote on Sat, 20 February 2016 18:25
The value converter gives you the whole thing
As string. Please post what you have

That's the problem. I don't know how to continue and my open post is my current status.
I'm familiar with the value converter and validator concepts but I can't transfer it in a working manner to my problem. Confused

I tried to pass the first and last part of the arrow to a value converter to return an AssociationType Enum but that didn't work at all.
If I pass the whole arrow string to a value converter: how I'm able to identify all components (left type, color, right type) in my model? I know that I can check each part in the converter, but I'm only able to return one information?

Association:
  {Association}
  leftClass=[Class]
  type=ARROW;
  rightClass=[Class]

terminal ARROW returns AssociationEnum:
  ('<','>','-','[',']','.','|')*;

enum AssociationEnum:
  UNDEFINED,
  INHERITANCE,
  COMPOSITION,
  ... ;

(+ the value converter for the ARROW terminal)

That's not working (or just I can't get it to work) and I guess the ARROW terminal is a very bad idea (or at least how i defined it). It's my first time working with Xtext (and DSLs in general) so I guess that I lack basic understanding.
Re: DSL with XText for PlantUML class diagrams [message #1724143 is a reply to message #1724138] Sun, 21 February 2016 16:53 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14076
Registered: July 2009
Senior Member
hi and what is your paricular problem with the value converter is what ?!?!?!?!?

public class ArrowValueConverter implements IValueConverter<AssociationEnum>{

	@Override
	public AssociationEnum toValue(String string, INode node) throws ValueConverterException {
		System.out.println(string);
		//TODO implement me
		return null;
	}

	@Override
	public String toString(AssociationEnum value) throws ValueConverterException {
		System.out.println(value);
		// TODO implement me
		return null;
	}

}



public class MyDslValueConverters extends DefaultTerminalConverters {
	
	@Inject
	private ArrowValueConverter arrowValueConverter;

	@ValueConverter(rule = "ARROW")
	public IValueConverter<AssociationEnum> ARROW() {
		return arrowValueConverter;
	}

}


class MyDslRuntimeModule extends AbstractMyDslRuntimeModule {
	
	override Class<? extends org.eclipse.xtext.conversion.IValueConverterService> bindIValueConverterService() {
		return MyDslValueConverters;
	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Disable language support for project
Next Topic:close crossreference for certain occurrences
Goto Forum:
  


Current Time: Fri Oct 22 04:39:10 GMT 2021

Powered by FUDForum. Page generated in 0.01773 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top