Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Validator for my language(I can not write validation methods for my language)
Validator for my language [message #1750817] Thu, 29 December 2016 11:36 Go to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 56
Registered: May 2015
Member
I wrote the grammar of a DSL
I follow the validation of the identifiers.
For type declarations I have the following grammar rules:

TypesDecl: {TypesDecl} 'Type:' types+=TypeDecl*;
TypeDecl: type=Type ':' name=TypeName exts=ExtsName?;

TypeName: name=ValidID;

And the validation method

@Check
def checkTypeNameStartsWithUpperCaseEndsWith_t(TypeName typeName) {
if (!Character.isUpperCase(typeName.name.charAt(0)) || !typeName.name.endsWith("_t"))
warning( TYPE_MSG, AlgorithmicPackage.Literals.TYPE_NAME__NAME)
}

In use I have:

Type:
String: Texte_t

If I delete the T in the header or the final _t in the editor, a warning is displayed. It's OK.

But now doing something similar for the modules:

Module:
'Module' name=ModuleName parameters=Parameters
'Début'
statements+=Statement*
'Fin';

ModuleName: name=ValidID;

Then:

@Check
def checkModuleNameStartsWithLowerCase(ModuleName moduleName) {
if (!Character.isLowerCase(moduleName.name.charAt(0)))
X warning( MODULE_MSG, AlgorithmicPackage.Literals.MODULE_NAME__NAME)
}

The warning shows me an error for MODULE_NAME__NAME and the wizard offers me only:
MODULE__NAME: EReference - Literals
MODULE_NAME: EClass - Literals

Which do not work (any more than other proposals that have nothing to do).
I can not figure out what's going on.
Why does it work for one and not for the other?

Thanks in advance.
Re: Validator for my language [message #1750818 is a reply to message #1750817] Thu, 29 December 2016 11:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
can you please share a complete reproducible grammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validator for my language [message #1750820 is a reply to message #1750817] Thu, 29 December 2016 14:21 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 56
Registered: May 2015
Member
Thank you for reading my post.
Attached is the complete test project of the Algorithmic language


I tried to send the full project but this caused a mistake!

Thanks
Re: Validator for my language [message #1750826 is a reply to message #1750820] Thu, 29 December 2016 16:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
public interface ModuleName extends StatementName, ExpressionName


getName is in ExpressionName (Xtext moves common features up to the supertype

=> MyDslPackage.Literals.EXPRESSION_NAME__NAME


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Validator for my language [message #1750827 is a reply to message #1750826] Thu, 29 December 2016 16:33 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 56
Registered: May 2015
Member
Ok this is what I used for the type
warning (TYPE_MSG, AlgorithmicPackage.Literals.TYPE_NAME__NAME)
But :
error(CONST_MSG, AlgorithmicPackage.Literals.CONST_NAME__NAME )

Causes an error:
The method or field CONST_NAME__NAME is undefined for the type Class<Literals>
This is my problem, what works with types I can not seem to adapt to Constants and Variables.
(Thank you for your publication on the Internet that I read with great interest)
Re: Validator for my language [message #1750828 is a reply to message #1750827] Thu, 29 December 2016 16:45 Go to previous message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 56
Registered: May 2015
Member
Ok it works, I did not really understand why but it works.

Thank you very much for your help.
It's the magic of the Internet we always find someone who has the solution!

Yves
Previous Topic:how to run junit test from maven
Next Topic:in-editor error message on the wrong cross-reference
Goto Forum:
  


Current Time: Fri Apr 19 05:32:28 GMT 2024

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

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

Back to the top