Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xtext 2.0] Reserved word 'is'?
[Xtext 2.0] Reserved word 'is'? [message #713327] Mon, 08 August 2011 06:58 Go to next message
Eclipse UserFriend
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 07:31 Go to previous messageGo to next message
Eclipse UserFriend
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 08:19 Go to previous messageGo to next message
Eclipse UserFriend
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 09:19 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [Xtext 2.0] Reserved word 'is'? [message #713453 is a reply to message #713434] Mon, 08 August 2011 09:45 Go to previous message
Eclipse UserFriend
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 09:53] by Moderator

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


Current Time: Mon Jul 14 08:55:49 EDT 2025

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

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

Back to the top