Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Captured feature values for Case Insensitive Keywords are not Case Insensitive during serialization
Captured feature values for Case Insensitive Keywords are not Case Insensitive during serialization [message #995749] Mon, 31 December 2012 02:34 Go to next message
Barrie Treloar is currently offline Barrie TreloarFriend
Messages: 52
Registered: July 2009
Member
I'm oversimplifying the example, but here is an excerpt from my grammar

Edit:
    "EDIT" type="Time" |
    "EDIT" type="ListOf"
;


And here is an excerpt from my xtend junit test.

val input = '''EDIT LISTOF'''

val expectedFormed = '''EDIT ListOf"

assertEquals(expectedFormat, input.parse.serialize(SaveOptions::newBuilder.format().getOptions()))


Where I am expecting that I should be able to use a different case for "ListOf" than what is specified in the grammar.

Instead of getting an assertion failure I get an error:

java.lang.RuntimeException: Could not serialize EObject via backtracking.
Constraint: null (type='Time' | type='ListOf') null
Values: type(1)
Semantic Object: ...->Edit


If I keep everything the same as the grammar, then I dont get this exception.

If I keep everything the same as the grammar and change EDIT to any other case, I dont get this exception.

If I keep everything the same as the grammar and change ListOf to any other case then I get this exception.

I've tried attaching a IValueConverter for the Edit rule (hoping I could normalize the input to the grammar values) but it is not being invoked for serialization.

Note the failure only occurs on serialization.
Parsing and formatting work fine with any case for the ListOf. (i.e I can run this in a the IDE and it recognizes the tokens correctly and will format the text editor).

What is special about capturing the string in a feature that causes it to fail during serialization?
Re: Captured feature values for Case Insensitive Keywords are not Case Insensitive during serializat [message #995798 is a reply to message #995749] Mon, 31 December 2012 06:15 Go to previous message
Barrie Treloar is currently offline Barrie TreloarFriend
Messages: 52
Registered: July 2009
Member
This may be my lack of understanding of what ValueConverting should be doing.

Adding in a sprinkling of debugging into my ValueConverting service to override
public Object toValue(String string, String lexerRule, INode node)

shows that the lexerRule is "Name", which is not what I expected.

Where:
Name:
    UNQUOTED_STRING | STRING;


Hacking some more to change my rule base to:

Edit:
    "EDIT" type=EditType dictionaryType=[DictionaryClass|Name]?;

EditType:
    "Boolean" | "Date" | 'ExpressionOf "Data"' | "ListOf" | "Minispec" | "Numeric" | "OneOf" | "Text" | "Time";


Gave me a new class I thought I could hook onto for validation, but I noticed that my debugs stopped appearing.

Which is obvious, since the Parser rules and handling this for me now and there is no need for value converting.

After more googling, I found http://stackoverflow.com/questions/8486003/how-to-make-enum-literal-case-insensitive-in-xtext which kind of makes sense.

So I tried pushing this problem out of the rule base into the checking code:
Edit:
    "EDIT" type=STRING dictionaryType=[DictionaryClass|Name]?;


One of my valid types is 'ExpressionOf "Data"' (note the space and use of quotes...)
Which lead me to try
Edit:
    "EDIT" type=UNQUOTED_STRING data=STRING? dictionaryType=[DictionaryClass|Name]?;


But both data and dictionaryType are optional so I get the warnings:
Decision can match input such as "RULE_STRING" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input

So I think I am back to my original way of doing things:


  • Define the values in the rule base.
  • The formatter is happy to understand case insensitive text.
  • Live with the serializer problems and make my test cases the same case as the rule base.



Previous Topic:PDF Doc does not open or download.
Next Topic:Using xText with existing model and Resource
Goto Forum:
  


Current Time: Mon Nov 24 21:55:10 GMT 2014

Powered by FUDForum. Page generated in 0.09876 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software