Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext good pracitces(I am looking for good Xtext usage practices)
Xtext good pracitces [message #1758236] Sat, 25 March 2017 12:29 Go to next message
graph researcher is currently offline graph researcherFriend
Messages: 8
Registered: March 2017
Junior Member
First, as a new user, I would like to know how different responsibilities szud be distributed between different elements of the DSL design/implementation in Xtext. For example, where the simplest constraints I can imagine should be implemented?
I have problmes while implementeing Xtext grammar for such atrivial example (the programm in the DSL I am trying to define):

<node isRooted="true">
<node isRooted="false">

Where the "true" and "false" string contraints representing booleans in my XML DSL language should be defined:
- in the Xtext grammar
- elsewhere (validation rules only or content assistant only, or both or in other place(s))

Is a good practice to define as week grammar (very limited contraints of this type) as possible and to move the implementation responsibility of them to other DSL design elements?

How the grammar should look like for such the construct?
Re: Xtext good pracitces [message #1758325 is a reply to message #1758236] Mon, 27 March 2017 16:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, your question is very vague so i cant give an answer.

generally you can encode stuff

- in the grammar
- in grammar related component (aka value converter)
- in MyDslValidator (semantic validation)

in your case you would add a boolean attribute to the grammar. that could look like

"isRooted" "=" (isRooted?="true"|"false")


The pratice i recommend is:

- if it can easily be done in the grammar, do it in the grammar,
- if not => use validation etc


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 27 March 2017 16:53]

Report message to a moderator

Re: Xtext good pracitces [message #1758562 is a reply to message #1758325] Thu, 30 March 2017 07:09 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Another indicator whether to use validation or a strict grammar is the error message the user gets.
If you're OK with something like "Unexpected token 'foo'. Expected 'true' or 'false'", doing it in the grammar is fine.
If you rather want something like "The value of 'isRooted' can only be 'true' or 'false'" got for a lose grammar and strict validation.


---
Get professional support from the Xtext committers at www.typefox.io
Re: Xtext good pracitces [message #1759767 is a reply to message #1758325] Tue, 18 April 2017 10:36 Go to previous message
graph researcher is currently offline graph researcherFriend
Messages: 8
Registered: March 2017
Junior Member
Thank you for your answers. I isolated the problem just before your answered my question and realized that its reason was related to the way I were using strings in my Xtext grammar.
So, for the following DSL expression:
rooted = "true"
the appropriate grammar rule should look like that:
'rooted' '=' (isRooted ?= '"true"' | '"false"')
// single-quote double-quote true double-quote single-quote
In place of that I was trying to concatenate double quotes surrounded by single quotes with the true and false grammar terminal symbols (surronded by single quotes). I do not know the nature of the problems involved by my former approach. In the consequence I do not know how can I introduce terminal symbols into the string (surrounded by double quotes). But this is not the problem I have, just an observation.
Sorry, for being not precise enough before.
Previous Topic:Xtext and antlr4?
Next Topic:is it possible to call @check method only once in validation?
Goto Forum:
  


Current Time: Thu Apr 25 07:01:55 GMT 2024

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

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

Back to the top