Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » need hint regarding 'parsability'
need hint regarding 'parsability' [message #610480] Tue, 21 September 2010 20:54 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi,
I have an issue in b3 regarding value conversion. When versions are
entered, they can be entered without escapes or quotes and they are
transformed into instances of Version and VersionRange (as used by p2).

Example: 1.0.0.v201008123456790

If the version contains 'odd characters' or 'keywords' the version is
entered as a String. Example "1.0.0.ouch_if".

When converting a Version value back, I would like to know if it will
require quoting or not. Is there a way to check if the grammar would
accept the unquoted string?

Regards
- henrik
Re: need hint regarding 'parsability' [message #619624 is a reply to message #610480] Tue, 21 September 2010 23:52 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

I'm afraid you have to implement this on your own. Have a look at the
default ID converter which queries the grammar for all keywords to
decide whether an id has to be quoted (prefixed with ^) or not. The same
should be possible for your versions as well.
Another alternative would be to inject the parser into the value
converter and invoke the respective entry rule for your data types.

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

Am 21.09.10 22:54, schrieb Henrik Lindberg:
> Hi,
> I have an issue in b3 regarding value conversion. When versions are
> entered, they can be entered without escapes or quotes and they are
> transformed into instances of Version and VersionRange (as used by p2).
>
> Example: 1.0.0.v201008123456790
>
> If the version contains 'odd characters' or 'keywords' the version is
> entered as a String. Example "1.0.0.ouch_if".
>
> When converting a Version value back, I would like to know if it will
> require quoting or not. Is there a way to check if the grammar would
> accept the unquoted string?
>
> Regards
> - henrik
Re: need hint regarding 'parsability' [message #625379 is a reply to message #619624] Wed, 22 September 2010 08:30 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 9/22/10 1:52 AM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> I'm afraid you have to implement this on your own. Have a look at the
> default ID converter which queries the grammar for all keywords to
> decide whether an id has to be quoted (prefixed with ^) or not. The same
> should be possible for your versions as well.
ok, I have seen that.
> Another alternative would be to inject the parser into the value
> converter and invoke the respective entry rule for your data types.
>
Can you elaborate a bit on what "invoke the respective entry rule for
your data types" mean?
(This approach is what I think I want).

Regards
- henrik
Re: need hint regarding 'parsability' [message #625454 is a reply to message #625379] Wed, 22 September 2010 08:43 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

you could try something like this:

@Inject
IParser parser;

IParseResult result = parser.parse(grammarAccess.getVersion().getName(),
new StringReader("1.0.0.foo_if"));

The result should contain information about the syntax errors.

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

Am 22.09.10 10:30, schrieb Henrik Lindberg:
> On 9/22/10 1:52 AM, Sebastian Zarnekow wrote:
>> Hi Henrik,
>>
>> I'm afraid you have to implement this on your own. Have a look at the
>> default ID converter which queries the grammar for all keywords to
>> decide whether an id has to be quoted (prefixed with ^) or not. The same
>> should be possible for your versions as well.
> ok, I have seen that.
>> Another alternative would be to inject the parser into the value
>> converter and invoke the respective entry rule for your data types.
>>
> Can you elaborate a bit on what "invoke the respective entry rule for
> your data types" mean?
> (This approach is what I think I want).
>
> Regards
> - henrik
Re: need hint regarding 'parsability' [message #625672 is a reply to message #625454] Wed, 22 September 2010 09:44 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The method mentioned is protected in the generated parser, so I guess I
have to derive a new class that exposes this functionality - i.e.

protected IParseResult parse(String ruleName, CharStream in)

Regards
- henrik

On 9/22/10 10:43 AM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> you could try something like this:
>
> @Inject
> IParser parser;
>
> IParseResult result = parser.parse(grammarAccess.getVersion().getName(),
> new StringReader("1.0.0.foo_if"));
>
> The result should contain information about the syntax errors.
>
> Regards,
> Sebastian
Re: need hint regarding 'parsability' [message #625820 is a reply to message #625672] Wed, 22 September 2010 10:27 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Sorry about the noise - the method *is* public in the parser generated
for the grammar - only a cast was required.

Duh...
- henrik

On 9/22/10 11:44 AM, Henrik Lindberg wrote:
> The method mentioned is protected in the generated parser, so I guess I
> have to derive a new class that exposes this functionality - i.e.
>
> protected IParseResult parse(String ruleName, CharStream in)
>
> Regards
> - henrik
>
> On 9/22/10 10:43 AM, Sebastian Zarnekow wrote:
>> Hi Henrik,
>>
>> you could try something like this:
>>
>> @Inject
>> IParser parser;
>>
>> IParseResult result = parser.parse(grammarAccess.getVersion().getName(),
>> new StringReader("1.0.0.foo_if"));
>>
>> The result should contain information about the syntax errors.
>>
>> Regards,
>> Sebastian
>
Re: need hint regarding 'parsability' [message #626239 is a reply to message #625820] Wed, 22 September 2010 13:05 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
And - it works like a charm!!
Exactly what I wanted. Thanks for the hint Sebastian.

Regards
- henrik

On 9/22/10 12:27 PM, Henrik Lindberg wrote:
> Sorry about the noise - the method *is* public in the parser generated
> for the grammar - only a cast was required.
>
> Duh...
> - henrik
>
> On 9/22/10 11:44 AM, Henrik Lindberg wrote:
>> The method mentioned is protected in the generated parser, so I guess I
>> have to derive a new class that exposes this functionality - i.e.
>>
>> protected IParseResult parse(String ruleName, CharStream in)
>>
>> Regards
>> - henrik
>>
>> On 9/22/10 10:43 AM, Sebastian Zarnekow wrote:
>>> Hi Henrik,
>>>
>>> you could try something like this:
>>>
>>> @Inject
>>> IParser parser;
>>>
>>> IParseResult result = parser.parse(grammarAccess.getVersion().getName(),
>>> new StringReader("1.0.0.foo_if"));
>>>
>>> The result should contain information about the syntax errors.
>>>
>>> Regards,
>>> Sebastian
>>
>
Previous Topic:is there a batch validation hook in Xtext?
Next Topic:best practice - applying formatting?
Goto Forum:
  


Current Time: Sat Apr 27 04:19:20 GMT 2024

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

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

Back to the top