Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Check if a language/grammar file is defined twice in Workspace (Validation for language files defined twice)
Check if a language/grammar file is defined twice in Workspace [message #1816430] Tue, 29 October 2019 08:36 Go to next message
Eclipse UserFriend
Hi,

We have a Visual Studio Code language extension written in Xtext. We need to make sure that certain grammar files (with certain extensions) are defined only once inside the workspace, and if not show a validation error.

Is there perhaps an easy way to do this with XText?

Thanks a lot

[Updated on: Tue, 29 October 2019 08:37] by Moderator

Re: Check if a language/grammar file is defined twice in Workspace [message #1816627 is a reply to message #1816430] Fri, 01 November 2019 13:58 Go to previous messageGo to next message
Eclipse UserFriend
hi, i am not sure if i get your problem
what makes a file "defined twice"
you do you mean something like:

there should be only one

"Hello World!" in all mydsl files in the project?
Re: Check if a language/grammar file is defined twice in Workspace [message #1816637 is a reply to message #1816627] Sat, 02 November 2019 03:33 Go to previous message
Eclipse UserFriend
This is a job for the validator.

Lorenzo Bettini found a very simple to understand implementation

Source: https://github.com/LorenzoBettini/packtpub-xtext-book-examples/blob/master/org.example.smalljava/src/org/example/smalljava/validation/SmallJavaValidator.xtend

@Check
def void checkNoDuplicateMember(SJMember member) {
val duplicate = member.containingClass.members.findFirst[
it != member && it.eClass == member.eClass &&
it.name == member.name
]
if (duplicate != null)
error("Duplicate member '" + member.name + "'",
SmallJavaPackage::eINSTANCE.SJMember_Name,
DUPLICATE_ELEMENT
)
}

HIH, Uli
Previous Topic:Operator overloading in Xbase Expression
Next Topic:Xtend Grey Space: It works great until it doesn't
Goto Forum:
  


Current Time: Mon Jul 14 23:28:36 EDT 2025

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

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

Back to the top