Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext formatting language(I can not add a blank line in my algorithms when formatting.)
Xtext formatting language [message #1755432] Fri, 03 March 2017 10:43 Go to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
In the main plugin of my Algorithmic DSL I added an om.infoly.eclipse.textxt.algo.formatting2 package using API version 2.8.
This works fine except that when I want to add a white line between my Eclipse modules display me errors by telling me:
module.prepend[newLine] => Ok but no white line
module.prepend[newLines=2] => Conflicting values for 'newLineMin': '1' and '2'.


The whole code being long I give only one example:
def dispatch void format(Module module, extension IFormattableDocument document) {
// TODO: format HiddenRegions around keywords, attributes, cross references, etc.
// module.prepend[newLines=2]
module.prepend[newLine]
switch (module) {
ModuleFunction : {
module.module.format
module.typeReturn.format;
module.last.format
}
ModuleProcedure : {
module.module.format
}
}
module.name.format;
module.parameters.format;
module.constantes.format;
module.variables.format;
interior( // Paramètres
module.regionFor.keyword("(").prepend[noSpace].append[oneSpace],
module.regionFor.keyword(")").prepend[oneSpace].append[oneSpace] ,
[oneSpace]
)
module.regionFor.keyword(":").surround[oneSpace]
interior( // Body
module.regionFor.keyword("Début").surround[newLine],
module.regionFor.keyword("Fin").surround[newLine],
[indent]
)
for (Statement statement : module.statements ) {
statement.format
}
}
Re: Xtext formatting language [message #1755437 is a reply to message #1755432] Fri, 03 March 2017 10:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11491
Registered: July 2009
Senior Member
can you share a minimal grammar and sample model as well?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Xtext formatting language [message #1755509 is a reply to message #1755437] Sat, 04 March 2017 08:26 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
You will find enclosed the complete project (but I have to remove separate packages because of the maximum size of the zip).
Thank you for telling me what you think.

Yves LEDUC
Re: Xtext formatting language [message #1755511 is a reply to message #1755509] Sat, 04 March 2017 08:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11491
Registered: July 2009
Senior Member
Hi,

the conflict can be resolved

module.prepend[newLines=2]

module.regionFor.keyword("Fin").prepend[newLine].append[newLines = 2],


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Xtext formatting language [message #1755514 is a reply to message #1755511] Sat, 04 March 2017 10:11 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Thanks it is OK
Re: Xtext formatting language [message #1755515 is a reply to message #1755511] Sat, 04 March 2017 10:18 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Displays a blank line as well as error messages in the Console view (see attached document).
  • Attachment: Console.TXT
    (Size: 66.53KB, Downloaded 26 times)
Re: Xtext formatting language [message #1755518 is a reply to message #1755515] Sat, 04 March 2017 10:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11491
Registered: July 2009
Senior Member
sure this is not yet another place of the same/similar problem? here is the model i test with



Programme x( ) : Booléen
Début
	Retourne FAUX
Fin

Programme x( ) : Booléen
Début
	Retourne FAUX
Fin




Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Xtext formatting language [message #1755864 is a reply to message #1755518] Wed, 08 March 2017 17:10 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Thank you
Now it is the formatting of the Constants that causes me a problem with the comma ',' which I want to format like this "," when it is like this for example ",". Here is the grammar element:

ConstsDecls: ('Constante:' | 'Const:') constantes=ConstDecls;
ConstDecls: consts+=ConstsDecl+; // Constantes de différents types
ConstsDecl: type=Type ':' ctes += ConstDecl (',' ctes += ConstDecl )* ';'? ; // Constantes d'un même type
ConstDecl: name=ConstName exts=ExtsName? init=DataInit ; // Constante identificateur et initialisation
ConstName: name=ValidID ;


With this code only the first comma is formatted and not the next.

def dispatch void format(ConstDecls constDecls, extension IFormattableDocument document) {
for (constsDecl : constDecls.consts ) { // Pour tous les types de Constante
var regpv = constsDecl.regionFor.keyword(";")
regpv.prepend[noSpace].append[oneSpace]
if ( constsDecl == constDecls.consts.last ) {
if (regpv != null ) // Si ';' fin dernière ligne on supprime
document.addReplacer(new InsertSemi(regpv, " "))
constsDecl.append[newLines = 2] // 2 si c'est la dernière
}
else {
if ( constsDecl.regionFor.keyword(";") == null ) // Pas de ; => Passage à la ligne
constsDecl.append[newLine] // 1 pour les autres
}
constsDecl.format
}
}


def dispatch void format(ConstsDecl constsDecl, extension IFormattableDocument document) {

var regdp = constsDecl.regionFor.keyword(":")
if ( constsDecl.regionFor.keyword(";") != null )
regdp.prepend[oneSpace].append[oneSpace]
else
regdp.prepend[space = "\t"].append[oneSpace]

var regvir = constsDecl.regionFor.keyword(",")
regvir.prepend[noSpace].append[oneSpace]

for (constDecl : constsDecl.ctes ) { // Pour toutes les constantes d'un même type
constDecl.format
}
}

def dispatch void format(ConstDecl constDecl, extension IFormattableDocument document) {
constDecl.init.format
}

def dispatch void format(DataInit dataInit, extension IFormattableDocument document) {
dataInit.regionFor.keyword("<-").surround[oneSpace]
}


Constante:Chaine:TITRE<-"Test Algorithme",INVITE1<-"Entrez trois nombres réels : ",INVITE2<-"Entrez un entier relatif : " ,RESULT1<-"Le résultat de rdt est : " ,RESULT2<-"La valeur absolue est : " Réel:PI<-3.14159; Entier: XXX<-100,YYY<-200 ;


For now it gives:

Constante:
Chaine : TITRE <- "Test Algorithme", INVITE1 <- "Entrez trois nombres réels : ",INVITE2 <- "Entrez un entier relatif : " ,RESULT1 <- "Le résultat de rdt est : " ,RESULT2 <- "La valeur absolue est : "
Réel : PI <- 3.14159; Entier : XXX <- 100, YYY <- 200


Can you tell me how to format all commas.
Re: Xtext formatting language [message #1755865 is a reply to message #1755518] Wed, 08 March 2017 17:10 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Thank you
Now it is the formatting of the Constants that causes me a problem with the comma ',' which I want to format like this "," when it is like this for example ",". Here is the grammar element:

ConstsDecls: ('Constante:' | 'Const:') constantes=ConstDecls;
ConstDecls: consts+=ConstsDecl+; // Constantes de différents types
ConstsDecl: type=Type ':' ctes += ConstDecl (',' ctes += ConstDecl )* ';'? ; // Constantes d'un même type
ConstDecl: name=ConstName exts=ExtsName? init=DataInit ; // Constante identificateur et initialisation
ConstName: name=ValidID ;


With this code only the first comma is formatted and not the next.

def dispatch void format(ConstDecls constDecls, extension IFormattableDocument document) {
for (constsDecl : constDecls.consts ) { // Pour tous les types de Constante
var regpv = constsDecl.regionFor.keyword(";")
regpv.prepend[noSpace].append[oneSpace]
if ( constsDecl == constDecls.consts.last ) {
if (regpv != null ) // Si ';' fin dernière ligne on supprime
document.addReplacer(new InsertSemi(regpv, " "))
constsDecl.append[newLines = 2] // 2 si c'est la dernière
}
else {
if ( constsDecl.regionFor.keyword(";") == null ) // Pas de ; => Passage à la ligne
constsDecl.append[newLine] // 1 pour les autres
}
constsDecl.format
}
}


def dispatch void format(ConstsDecl constsDecl, extension IFormattableDocument document) {

var regdp = constsDecl.regionFor.keyword(":")
if ( constsDecl.regionFor.keyword(";") != null )
regdp.prepend[oneSpace].append[oneSpace]
else
regdp.prepend[space = "\t"].append[oneSpace]

var regvir = constsDecl.regionFor.keyword(",")
regvir.prepend[noSpace].append[oneSpace]

for (constDecl : constsDecl.ctes ) { // Pour toutes les constantes d'un même type
constDecl.format
}
}

def dispatch void format(ConstDecl constDecl, extension IFormattableDocument document) {
constDecl.init.format
}

def dispatch void format(DataInit dataInit, extension IFormattableDocument document) {
dataInit.regionFor.keyword("<-").surround[oneSpace]
}


Constante:Chaine:TITRE<-"Test Algorithme",INVITE1<-"Entrez trois nombres réels : ",INVITE2<-"Entrez un entier relatif : " ,RESULT1<-"Le résultat de rdt est : " ,RESULT2<-"La valeur absolue est : " Réel:PI<-3.14159; Entier: XXX<-100,YYY<-200 ;


For now it gives:

Constante:
Chaine : TITRE <- "Test Algorithme", INVITE1 <- "Entrez trois nombres réels : ",INVITE2 <- "Entrez un entier relatif : " ,RESULT1 <- "Le résultat de rdt est : " ,RESULT2 <- "La valeur absolue est : "
Réel : PI <- 3.14159; Entier : XXX <- 100, YYY <- 200


Can you tell me how to format all commas.
Re: Xtext formatting language [message #1755872 is a reply to message #1755865] Wed, 08 March 2017 18:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11491
Registered: July 2009
Senior Member
am not sure if i get your problem / question since it seems trivial

		obj.regionFor.keywords(",").forEach[
			prepend[noSpace].append[oneSpace]
		]


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Xtext formatting language [message #1755901 is a reply to message #1755872] Thu, 09 March 2017 08:12 Go to previous message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 54
Registered: May 2015
Member
Sorry the answer clogged my eyes.

def dispatch void format(ConstsDecl constsDecl, extension IFormattableDocument document) {
var regdp = constsDecl.regionFor.keyword(":")
if ( constsDecl.regionFor.keyword(";") != null )
regdp.prepend[oneSpace].append[oneSpace]
else
regdp.prepend[space = "\t"].append[oneSpace]

constsDecl.regionFor.keywords(",").forEach[
constDecl | constDecl.prepend[noSpace].append[oneSpace] constDecl.format
]
}

def dispatch void format(ConstDecl constDecl, extension IFormattableDocument document) {
constDecl.init.format
}

def dispatch void format(DataInit dataInit, extension IFormattableDocument document) {
dataInit.regionFor.keyword("<-").surround[oneSpace]
}


it is OK :

Constante:
Chaine : TITRE<-"Test Algorithme", INVITE1<-"Entrez trois nombres réels : ", INVITE2<-"Entrez un entier relatif : ", RESULT1<-"Le résultat de rdt est : ", RESULT2<-"La valeur absolue est : "
Réel : PI<-3.14159
Entier : XXX<-100, YYY<-200


Sometimes it is easy to find the answer to a complex question and the answer to a simple question does not come right away.
Thanks for this trivial response

Yves LEDUC
Previous Topic:Two DSL, single project, Activator&injector issues
Next Topic:Generate a final product for my DSL
Goto Forum:
  


Current Time: Tue Dec 12 06:36:17 GMT 2017

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

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