[XTEND] Code generation [message #775657] |
Fri, 06 January 2012 13:26 |
Peter Johnsen Messages: 60 Registered: January 2012 |
Member |
|
|
Hi,
I have a grammar that looks something like this (simplified):
Y:
('optional')? 'X' name = ID ...
In my template I would like to add optional to the generated file if this word
is present in the source file, e.g.:
optional X somename
should yield:
optional X somename
in the generated file as well. However, is it possible to test whether optional is used in the source file? This would probably appear at ??? below.
def compile( Y y )
'''
??? X <<y.name>>
'''
Any idea guys? Or would I need to rewrite the grammar?
Thanks!
[Updated on: Fri, 06 January 2012 13:27] Report message to a moderator
|
|
|
|
|
|
|
Re: [XTEND] Code generation [message #775743 is a reply to message #775732] |
Fri, 06 January 2012 16:04 |
|
Hi,
let us say your grammar is a bit "strange since the or (|) has implications on the type hierarchy too in your case
never the less you can test in your case if the ClassOrType is a Type and then ask it for its name or if not for its type and the type for its name
maybe a grammar like:
ClassOrType:
ClassRef | Type;
Type:
name = ('int' | 'float');
ClassRef: type = [Class] ;
makes it more easy for you.
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: [XTEND] Code generation [message #775803 is a reply to message #775789] |
Fri, 06 January 2012 17:39 |
Peter Johnsen Messages: 60 Registered: January 2012 |
Member |
|
|
I see. But if I have methods for generating operation and parameter code like this:
def compile( Operation o )
'''
(«FOR p : o.params» «p.compile» «ENDFOR»)
'''
def compile( Param p )
'''
«p.type.compile» «p.name»
'''
How can I format it differently so that new lines don't appear in the parameter list?
[Updated on: Fri, 06 January 2012 17:39] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04369 seconds