Keyword/name=ID conflicts [message #639647] |
Wed, 17 November 2010 10:50 |
Chris Ainsley Messages: 78 Registered: March 2010 Location: UK |
Member |
|
|
I was just wondering if there is a way to specify an the value of an ID to the name of an existing keyword without using the '^' (or any other arbitrary prefix/suffix)?
A snippet follows:
RECORD:
'record ' name=ID '{' (fields+=Field)+ '}';
I want to be able to have a record ID of 'record' without having to specify a prefix of '^'. The reason is that the context makes it clear that I'm not trying to declare a sub-record and the grammar doesn't permit that at this point anyway.
I assume there must be very good technical reasons for the '^' value converter but I really dislike having to document an unergonomic convention ('^') unless I am sure that there is no alternative.
Note, I don't want to make fields into STRING types either if at all possible.
[Updated on: Wed, 17 November 2010 10:51] Report message to a moderator
|
|
|
|
|
|
|
Re: Keyword/name=ID conflicts [message #1790776 is a reply to message #639873] |
Sat, 16 June 2018 11:04 |
Alex Mising name Messages: 149 Registered: March 2010 |
Senior Member |
|
|
I came across this post while looking to achieve the same. In my case however, I am happy to use the circum (^) character as an escape which I saw mentioned above. Indeed ID is defined to have an optional circum at the start:
terminal ID: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
What I am not clear on though, is whether there is something which will remove that circum by default, or if one is supposed to do it manually. In my case when I tried it out it, the circum seemed to remain. Al my rules use "name=Name" to indirectly point to ID via this Name rule:
So in order to achieve that, I manually added a value converter as follows:
@ValueConverter(rule="Name")
def IValueConverter<String> IDValueConverter() {
return new AbstractToStringConverter<String>() {
override protected internalToValue(String value, INode node) throws ValueConverterException {
if (value.startsWith("^")) value.substring(1)
else value
}
};
}
This way when a keyword is escaped using ^, the escape is dropped. Is this how escaping is supposed to work, or have I done something wrong? I am just not sure if there is already something off-the-shelf for doing this, which I have somehow "broken" forcing me to manually add a value converter...
|
|
|
|
Powered by
FUDForum. Page generated in 0.02729 seconds