Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validator - Error/Warning Message Syntax
Validator - Error/Warning Message Syntax [message #983055] Tue, 13 November 2012 16:35 Go to next message
Katja N is currently offline Katja NFriend
Messages: 3
Registered: November 2012
Junior Member
Hello everyone,

I am a master student working on a DSL for the creation of dynamic web-based surveys in the context of my master thesis. While I haven't had a lot of trouble implementing the actual DSL and an accompanying HTML generator, I am now struggling a little bit with the JavaValidator. I am new to this and one of my major problems is that I have difficulties getting the error/warning messages to display where I would like them to in the editor.

A very simplified example. In my DSL, I have defined (survey) items:
Item:
	"item" name=ID (requests+=Text)+ 
	"{"
		(instructions=Instructions)?
		answers=AnswerCategories
	"}"
;


Text:
	PlainText | PipedText
;

PlainText:
	text=STRING
;

PipedText:
	"insertAnswer" answerFrom=[Item]
;


Basically, an item consists of a question, further instructions, and answer categories. The question (or "requests" as I called them in my DSL) consist of plain text strings and references to other items (this is used to pipe the selected answer from the referenced item into the question text of the new item).

I was now trying to make sure that plain text strings are not empty (as a first step), using the following code in the JavaValidator:
	@Check
	public void checkRequestTextNotEmpty(Item item){		
		for(Text t : item.getRequests()){
			if ((t instanceof PlainText) && ((PlainText) t).getText().isEmpty()){
				warning("[WARNING] Request empty", SurveMePackage.Literals.ITEM__REQUESTS);
			}
		}
	}


When I type into the editor something like "item MyFirstItem 'How old are you...' '' '...and when were you born?'", the error message is triggered, however, the first plain text string is underlined as the error source, rather than the whole list of requests, let alone the part that is actually causing the error. This may not be a huge problem, however, I would generally like to gain a better understanding of the error() and warning() methods, i.e. their syntax.

Could someone please explain to me if it is possible to mark the actual part of the list that is causing the issue and if so, how? And could you maybe give me a general explanation of how to use the error() and warning() messages reasonably, i.e. give an example of how to use it with different parameters etc.? I had a look in the API, but the methods were not explained in more detail in there, and I find it hard to fully comprehend how to make the best use of them.

Thank you very much in advance!
Re: Validator - Error/Warning Message Syntax [message #983097 is a reply to message #983055] Tue, 13 November 2012 17:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it should be right staight forward


error(<message>, <object to mark>, <feature to mark>, <index to mark or -1 if you dont care>, <error-code>,<data1>, ...<datan>);


=> in your case

error("[WARNING] Request empty",item, SurveMePackage.Literals.ITEM__REQUESTS,item.getRequests().indexof(t), "CODE");


but you may actually want to check Texts or mark them so

error("[WARNING] Request empty",t, SurveMePackage.Literals.PLAIN_TEXT__TEXT,-1"CODE");



~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validator - Error/Warning Message Syntax [message #983963 is a reply to message #983097] Wed, 14 November 2012 09:37 Go to previous messageGo to next message
Katja N is currently offline Katja NFriend
Messages: 3
Registered: November 2012
Junior Member
Awesome, thank you so much for the quick reply and explanation, works like a charm Smile

I guess I was a little confused by the differentiation between objects and features in that context. In my example...

Item:
	"item" name=ID (requests+=Text)+ 
	"{"
		(instructions=Instructions)?
		answers=AnswerCategories
	"}"
;


... I would treat Item as an object, and name, requests, instructions and answers as features of that object, right?
Re: Validator - Error/Warning Message Syntax [message #983985 is a reply to message #983963] Wed, 14 November 2012 09:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Yes. Correct

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validator - Error/Warning Message Syntax [message #983998 is a reply to message #983985] Wed, 14 November 2012 10:18 Go to previous message
Katja N is currently offline Katja NFriend
Messages: 3
Registered: November 2012
Junior Member
Okay, thanks again for your help!
Previous Topic:Terminal rule named INT not awaiting an Integer
Next Topic:whitespace Indentation based grammar ?
Goto Forum:
  


Current Time: Thu Apr 25 11:25:26 GMT 2024

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

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

Back to the top