Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Parser seems to confuse assignments / Grammar problem
Parser seems to confuse assignments / Grammar problem [message #1073631] Thu, 25 July 2013 03:55 Go to next message
Eclipse UserFriend
Hi all,

I've got a problem with my Xtext grammar - more specifically with the following parser rule:

Property:
	'property' type=JvmTypeReference (collection?='*')? name=ValidID ('default' default=PropertyDefaultValue | 'opposite' opposite=[Property])? ';'
;


Now consider the following example code:

property Boolean
property String secondProperty;


(Please note, that the second 'property'-keyword and the ValidID 'secondProperty' have error markers in the editor: 1. Marker says "no viable alternative at input 'property'", 2. marker says "extraneous input 'secondProperty' expecting ';'").

If I hit Ctrl-Space after "Boolean" (while debugging), I noticed, that the instance of Property being passed to my ContentProposalProvider has the value 'String' as its 'name'.

This seems to happen, because the semicolon is missing (which is usually the case, when defining a new Property) - the parser just ignores the following 'property'-keyword and confuses the 'type'-Assignment with the 'name'-Assignment. If I remove the semicolon from the grammar, everything works correctly.

Besides removing the need for mandatory semicolons after each statement, are there other ways to get around this problem?

Thanks in advance,
Jochen

[Updated on: Thu, 25 July 2013 03:56] by Moderator

Re: Parser seems to confuse assignments / Grammar problem [message #1073636 is a reply to message #1073631] Thu, 25 July 2013 04:05 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

I don't quite understand the problem. Is the example code supposed to be correct? Because according to your grammar it is not. The boolean property is missing a name (and the mandatory semicolon).

Alex
Re: Parser seems to confuse assignments / Grammar problem [message #1073640 is a reply to message #1073631] Thu, 25 July 2013 04:14 Go to previous messageGo to next message
Eclipse UserFriend
[This post stated that I managed to solve the problem by myself - which is not true - it still persists - sorry for the confusion].

Here is a more complete example of the grammar:

Class:
(abstract?='abstract')? 'class' name=ValidID
		('extends' extendedType=JvmTypeReference)?
		('implements' extendedInterfaces+=JvmTypeReference (',' extendedInterfaces+=JvmTypeReference)*)?
	'{'
		facets+=Facet*
	'}'

Facet:
	Property | Method
;

Method:
(visibility=Visibility)? (abstract?='abstract' | (final?='final' static?='static'))?
	'method'
	returnType=JvmTypeReference	name=ValidID '('(parameters+=MethodParameter (',' parameters+=MethodParameter)*)?')' ';'
;

Property:
	'property' type=JvmTypeReference (collection?='*')? name=ValidID ('default' default=PropertyDefaultValue | 'opposite' opposite=[Property])? ';'
;


Cheers,
Jochen

[Updated on: Thu, 25 July 2013 05:22] by Moderator

Re: Parser seems to confuse assignments / Grammar problem [message #1073643 is a reply to message #1073636] Thu, 25 July 2013 04:18 Go to previous message
Eclipse UserFriend
Hi Alexander - thanks for the quick response:

Well, more or less. The example represents the state of the file, when a user wants creates a 'Property': He inserts the keyword, a type is chosen... - now he hits Ctrl-Space (we want to propose some possible names).

[Updated on: Thu, 25 July 2013 04:19] by Moderator

Previous Topic:org.eclipse.xtext.ecore
Next Topic:"scope" problem
Goto Forum:
  


Current Time: Wed Jul 23 08:16:46 EDT 2025

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

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

Back to the top