|
Re: DSL with XText for PlantUML class diagrams [message #1724061 is a reply to message #1724059] |
Sat, 20 February 2016 12:05 |
|
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' | '\"\"' | '//' | '\\' | ':')*;
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 |
Tobias Schmidt Messages: 5 Registered: February 2016 |
Junior Member |
|
|
Christian Dietrich wrote on Sat, 20 February 2016 18:25The 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.
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 |
|
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;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Powered by
FUDForum. Page generated in 0.02324 seconds