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 05:43  |
Eclipse User |
|
|
|
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 #1755864 is a reply to message #1755518] |
Wed, 08 March 2017 12:10   |
Eclipse User |
|
|
|
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 12:10   |
Eclipse User |
|
|
|
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 #1755901 is a reply to message #1755872] |
Thu, 09 March 2017 03:12  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Sun Apr 27 03:48:23 EDT 2025
Powered by FUDForum. Page generated in 9.08327 seconds
|