Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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
Jochen Schmich is currently offline Jochen Schmich
Messages: 21
Registered: July 2009
Junior Member
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]

Report message to a 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
Alexander Nittka is currently offline Alexander Nittka
Messages: 1149
Registered: July 2009
Senior Member
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


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
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
Jochen Schmich is currently offline Jochen Schmich
Messages: 21
Registered: July 2009
Junior Member
[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]

Report message to a 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
Jochen Schmich is currently offline Jochen Schmich
Messages: 21
Registered: July 2009
Junior Member
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]

Report message to a moderator

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


Current Time: Sat Apr 19 00:33:47 EDT 2014

Powered by FUDForum. Page generated in 0.01617 seconds