Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.2] How to support multi-line qualified names?
[Xtext 2.2] How to support multi-line qualified names? [message #778766] Fri, 13 January 2012 19:46 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

I have spent a considerable amount of time trying to get multi-line qualified names, without success. Here is an example;

optional proto2.google.rpc.
Name name = 1;

Here the FQN is 'proto2.google.rpc.Name'. Here is how I have defined QualifiedName in the grammar, hoping it would work (but it didn't)

QualifiedName:
  '.'? SafeId (FQN_SEPARATOR SafeId)*;

SafeId:
  ID | ReservedWord;

terminal FQN_SEPARATOR:
  '.' (WS)*;

ReservedWord:
  'package' | 'import' | 'public' | 'option' | 'extend' | 'message' | 'optional' | 'required' | 'repeated' |
  'enum' | 'service' | 'rpc' | 'returns' | 'default' | 'extensions' | 'to' | 'max' | 'true' | 'false' |
  'double' | 'float' | 'int32' | 'int64' | 'uint32' | 'uint64' | 'sint32' | 'sint64' | 'fixed32' | 'fixed64' |
  'sfixed32' | 'sfixed64' | 'bool' | 'string' | 'bytes';


Then I tried to create a value converter for the terminal 'FQN_SEPARATOR' that removes any whitespace from the given String. Again, this didn't work Sad

Any help will be greatly appreciated Smile

Cheers,
-Alex
Re: [Xtext 2.2] How to support multi-line qualified names? [message #779041 is a reply to message #778766] Sat, 14 January 2012 13:46 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Alex,

your value converter for the rule QualifiedName should take care of
that. Please note that the QualifiedNameConverter that ships with Xtext
will not handle the terminal rule FQN_SEPARATOR correctly. You'll have
to strip the WS on your own.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 13.01.12 20:46, schrieb Alex Ruiz:
> Greetings,
>
> I have spent a considerable amount of time trying to get multi-line
> qualified names, without success. Here is an example;
>
> optional proto2.google.rpc.
> Name name = 1;
>
> Here the FQN is 'proto2.google.rpc.Name'. Here is how I have defined
> QualifiedName in the grammar, hoping it would work (but it didn't)
>
>
> QualifiedName:
> '.'? SafeId (FQN_SEPARATOR SafeId)*;
>
> SafeId:
> ID | ReservedWord;
>
> terminal FQN_SEPARATOR:
> '.' (WS)*;
>
> ReservedWord:
> 'package' | 'import' | 'public' | 'option' | 'extend' | 'message' |
> 'optional' | 'required' | 'repeated' |
> 'enum' | 'service' | 'rpc' | 'returns' | 'default' | 'extensions' | 'to'
> | 'max' | 'true' | 'false' |
> 'double' | 'float' | 'int32' | 'int64' | 'uint32' | 'uint64' | 'sint32'
> | 'sint64' | 'fixed32' | 'fixed64' |
> 'sfixed32' | 'sfixed64' | 'bool' | 'string' | 'bytes';
>
>
> Then I tried to create a value converter for the terminal
> 'FQN_SEPARATOR' that removes any whitespace from the given String.
> Again, this didn't work :(
>
> Any help will be greatly appreciated :)
>
> Cheers,
> -Alex
Re: [Xtext 2.2] How to support multi-line qualified names? [message #779506 is a reply to message #779041] Sun, 15 January 2012 23:16 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Thanks Sebastian.

I did create my own value converter:

public class FQN_SEPARATORValueConverter extends AbstractLexerBasedConverter<String> {

  @Override public String toValue(String string, INode node) throws ValueConverterException {
    if (string == null) {
      return null;
    }
    return removeLineBreaksFrom(string).trim();
  }
}


and I did "register" it in my own subclass of DefaultTerminalConverters:

  @ValueConverter(rule = "FQN_SEPARATOR")
  public IValueConverter<String> FQN_SEPARATOR() {
    return fqnSeparatorValueConverter;
  }


but when I set a breakpoint in my value converter, it never gets called when debugging Sad

-Alex

Re: [Xtext 2.2] How to support multi-line qualified names? [message #779636 is a reply to message #779506] Mon, 16 January 2012 08:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi Alex,

QualifiedNameConverter != ValueConverter

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtext 2.2] How to support multi-line qualified names? [message #779667 is a reply to message #779506] Mon, 16 January 2012 09:39 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Alex,

sorry for my misleading answer. You have to provide the value converter
for the data type rule 'QualifiedName' instead of the FQN_SEPARATOR.
Data type rules have to be converted by themselves. The individual parts
will not be converted by the framework since that would break the
semantics because each part could become an instance of something which
is not a string (but e.g. an int).

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 16.01.12 00:16, schrieb Alex Ruiz:
> Thanks Sebastian.
>
> I did create my own value converter:
>
>
> public class FQN_SEPARATORValueConverter extends
> AbstractLexerBasedConverter<String> {
>
> @Override public String toValue(String string, INode node) throws
> ValueConverterException {
> if (string == null) {
> return null;
> }
> return removeLineBreaksFrom(string).trim();
> }
> }
>
>
> and I did "register" it in my own subclass of DefaultTerminalConverters:
>
>
> @ValueConverter(rule = "FQN_SEPARATOR")
> public IValueConverter<String> FQN_SEPARATOR() {
> return fqnSeparatorValueConverter;
> }
>
>
> but when I set a breakpoint in my value converter, it never gets called
> when debugging :(
>
> -Alex
>
>
Re: [Xtext 2.2] How to support multi-line qualified names? [message #779772 is a reply to message #779667] Mon, 16 January 2012 14:26 Go to previous message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Christian & Sebastian,

I'm so sorry. That was my bad for misreading Sebastian's suggestion Very Happy

As always, thank you so much for your help!

Cheers,
-Alex
Previous Topic:problems with JvmTypesBuilder, JvmModelGenerator and &quot;this&quot;
Next Topic:Critical MWE2Launcher error
Goto Forum:
  


Current Time: Fri Apr 26 03:55:25 GMT 2024

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

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

Back to the top