|
|
|
Re: How to use reference and enumerated list in xtext grammar and parser [message #743940 is a reply to message #743906] |
Fri, 21 October 2011 20:58 |
|
Hi,
all of your problems should be mentioned in the docs
(0) am not quite sure about your model rule
you grammar in general may suffer by the low precedence of |
do you mean something like
Model:
(Atomic|Network)
name = ID
author = ID
description = STRING
'port_list_open{'
ports += Port*
'}port_list_close'
;
same for
Transition:
Internal_transition|Exteral_transition
computation = STRING
description = STRING
;
what do you mean by that
currently this is the same a
Transition:
Internal_transition|(Exteral_transition
computation = STRING
description = STRING
);
(1) sub_Models += [Atomic]+
you can only reference stuff that has a name (direct or via IQualifiedNameProvider)
your Atomic has (without the fix mentioned above) not a name
(2) port_type = ID
you want to have a enum so use one
port_type = PortType
enum PortType : input| output;
(3) output_port = [Port])?
the ports may have a FQN (name of Atomic|Network) . name of port
=> customize IQualifiedNameProvider
or change grammar to output_port = [Port|FQN])?
FQN: ID ("." ID)*;
(4)time = INT
time=Real
Real: INT "." INT;
with real being a string in the model you can change this using a valueconverter
(5) the states is the same than the ports
(6) the xtend class looks ok
besides some strage stuff like «IF("«port.port_type»".equalsIgnoreCase("input"))»
which is by definion false maybe you mean port.port_type.equalsIgnoreCase("input")
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Fri, 21 October 2011 21:13] Report message to a moderator
|
|
|
|
Re: How to use reference and enumerated list in xtext grammar and parser [message #744745 is a reply to message #744708] |
Sat, 22 October 2011 09:59 |
|
Hi,
with the change to the grammar i suggested you the atomic now has a name. so let us have a
a look at the port problem / the problem in general.
let us take this grammar:
Model:
packages+=Package+
;
Package:
"package" name=ID "{"
elements+=Element*
"}"
;
Element:
notname=ID ("refs" refs=[Element])?
;
as you can see the Entity has no name. so out of the box the referencing will never ever work
you can fix by changing the grammar to
Element:
name=ID ("refs" refs=[Element])?
;
or use a IQualifiedNameProvider like this one (dont forget to bind it in the runtime module)
public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
QualifiedName qualifiedName(Element e) {
return QualifiedName.create(e.getNotname());
}
}
we choose to do the first variant as you did.
now the problem is how Xtext build the Qualified Names by default:
it will qn=be packagename.elementname
but the qn contains a dot.
in the grammar we have refs=[Element] which is shot
for refs=[Element|ID] wich means: refernce to an Element and therefore parse an ID
this is why i sugested the FQN Stuff
Element:
notname=ID ("refs" refs=[Element|FQN])?
;
FQN: ID ("." ID)*;
of course the custom qualfiedNameProvider as shown above
would do the name trick -> but then you would not be
able to have the name element name in different packages.
so this will help you to solve the referecing problem.
reaching the web/form for IQualifiedNameProvider / Scoping
will give you 1000 more examples / blog posts etc
the enum problem is easier to solve «IF(port.port_type == PortType::INPUT)»
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.03385 seconds