Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.0] Reserved word 'is'?
[Xtext 2.0] Reserved word 'is'? [message #713327] Mon, 08 August 2011 10:58 Go to next message
Sebastian Herold is currently offline Sebastian HeroldFriend
Messages: 5
Registered: July 2011
Junior Member
I still have problems testing the simple assertion language:
// 'Element' and 'QualifiedName' definition is left

Assertion:
	'assert that ' element=[Element|QualifiedName] condition=Condition
;

Condition:
	EqualsCondition | IsCondition
;

EqualsCondition:
	'equals' value=STRING
;

IsCondition:
	'is' state=StateType
;

enum StateType:
	PRESENT='present' | VISIBLE='visible'
;

The sentence:
assert that Login.login is present
can't be parsed because of the error mismatched character 's' expecting 'n' at 'is'. When 'is' is substituted by 'was' in 'IsCondition':
IsCondition:
	'was' state=StateType
;
and you type:
assert that Login.login was present
everything is ok. Is 'is' a reserved word?

Best regards,
Sebastian
Re: [Xtext 2.0] Reserved word 'is'? [message #713346 is a reply to message #713327] Mon, 08 August 2011 11:31 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

don't use white spaces in keywords ('assert' 'that' instead of 'assert that '). Please post the full grammar.

Alex
Re: [Xtext 2.0] Reserved word 'is'? [message #713378 is a reply to message #713346] Mon, 08 August 2011 12:19 Go to previous messageGo to next message
Sebastian Herold is currently offline Sebastian HeroldFriend
Messages: 5
Registered: July 2011
Junior Member
The white spaces at the end of keywords are very handy to avoid additional keypresses. But this isn't the problem. Here my complete grammar:
grammar de.is24.test.Dsl with org.eclipse.xtext.common.Terminals

generate dsl "htttp://www.is24.de/test/Dsl"

Model:
	(pageObjects+=PageObject)+
	(givens+=GivenNotation)*
	(tests+=TestNotation)*
	// (conditions+=Assertion)*
;

TestNotation: 
	'test ' name=ID '{'
		'given ' given=GivenTestAction
		'when user ' when=Action
		'then ' assertion=Assertion
	'}'
;

Assertion:
	'assert that ' element=[Element|QualifiedName] condition=Condition
;

Condition:
	EqualsCondition | IsCondition
;

EqualsCondition:
	'equals' value=STRING
;

IsCondition:
	'was' state=StateType
;

enum StateType:
	PRESENT='present' | VISIBLE='visible'
;


GivenTestAction: 
	(action=Action | given=[GivenNotation])
;
	
PageObject:
	'object ' name=ID ('extends ' extends=[PageObject])? '{'
		(elements+=Element)+
	'}';

Location: 
	'xpath ' xpath=STRING | 'id ' elementId=ID | 'name ' elementName=ID
;

GivenNotation:
	'given ' name=ID '{'
		('given ' given=[GivenNotation|ID] )?
		(actions+=Action)+
	'}'	
;

Element:	
	SimpleElement | LinkElement | InputElement | ButtonElement | ImageElement
;

Action :
	GotoAction | ClickAction | TypeAction
;

GotoAction:
	'goto ' url=STRING
;

ClickAction: 
	'click ' element=[Element|QualifiedName] 
;

TypeAction:
	'type ' text=STRING ' into ' element=[Element|QualifiedName]
;

SimpleElement: 
	'elem ' name=ID location=Location
;

LinkElement: 
	'link' name=ID location=Location
;

InputElement: 
	'input' name=ID location=Location
;

ButtonElement: 
	'button' name=ID location=Location
;

ImageElement: 
	'image' name=ID location=Location
;

QualifiedName:
	ID ('.' ID)*
;
Re: [Xtext 2.0] Reserved word 'is'? [message #713434 is a reply to message #713378] Mon, 08 August 2011 13:19 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

white spaces within keywords *are* problematic. If you worry about content assist, write templates or adapt the completion function for keywords. I haven't tested it but I am prepared to bet that the problem is caused by the ' into ' keyword. The lexer works without context. It simply chops up the document into tokens it tries to make as long as possible. Now, after Login.login there is a space then an 'i' and - hey - there is a token that starts with a space followed by an i, so that must be it. But when the 's' is read instead of the expected 'n', you get the error.

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: [Xtext 2.0] Reserved word 'is'? [message #713453 is a reply to message #713434] Mon, 08 August 2011 13:45 Go to previous message
Sebastian Herold is currently offline Sebastian HeroldFriend
Messages: 5
Registered: July 2011
Junior Member
Thanks, such an easy solution: I just removed all white spaces in keywords.

I thought the context would had more priority than a keyword.

Regards,
Sebastian

[Updated on: Mon, 08 August 2011 13:53]

Report message to a moderator

Previous Topic:Content Assist error
Next Topic:Xtext 2.0 Syntax Coloring
Goto Forum:
  


Current Time: Fri Apr 19 22:46:24 GMT 2024

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

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

Back to the top