Help with expressions, pretty please? [message #755884] |
Thu, 10 November 2011 01:33 |
Alex Ruiz Messages: 103 Registered: March 2011 |
Senior Member |
|
|
Greetings,
I apologize in advance for the length of this question
I've struggling for a couple of days trying to figure out how to add expressions to the protobuf-dt grammar. I read Sven's post on expressions and it was great! I think I understood it. The problem is that I don't know how to apply what I learned.
What I'm trying to accomplish is something called "message notation" in protocol buffer grammar. For example:
option (abc) = 3;
option (spanner.database_options) = {
acls: {
owner: "chubby!*"
admin: "chubby!*"
field_acls: {
reader: "chubby!*"
writer: "chubby!*"
}
}
};
whose grammar can be defined as (this doesn't work in Xtext, but it is the simplest way to describe it)
ValueRef:
MessageNotation | SimpleRef;
// { foo: 1, bar: 2 }
MessageNotation:
'{'
fields+=FieldNotation ((',')? fields+=FieldNotation)*
'}'
;
FieldNotation:
name=Name ':' value=SimpleRef;
SimpleRef:
LiteralRef | BooleanRef | NumberRef | StringRef;
The value of an option can be a simple value (SimpleRef) or message notation (MessageNotation). MessageNotation has fields, and the value of each field can be a SimpleRef or another MessageNotation.
I have tried everything I could image, and nothing. Whatever I try fails when I generate Java code from the grammar.
Any help will be greatly, greatly, greatly appreciated!
Many thanks in advance,
-Alex
|
|
|
|
Re: Help with expressions, pretty please? [message #756084 is a reply to message #755885] |
Thu, 10 November 2011 19:45 |
Max Goltzsche Messages: 40 Registered: November 2011 |
Member |
|
|
Hey Alex,
you may want to write sth like:
FieldNotation:
name=Name ':' (simpleRef=SimpleRef|msgNotation=MessageNotation);
or
FieldNotation:
name=Name ':' Property;
Property:
Attribute | MessageNotation;
Attribute:
type=SimpleRef;
...
Always be aware of what the generator makes of it. As far as I know you cannot extend a Java class from an enum so that you have to use a container class.
regards,
Max
[Updated on: Thu, 10 November 2011 19:46] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06461 seconds