Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » grammar to permit zipfiles in a string
grammar to permit zipfiles in a string [message #1835654] Wed, 09 December 2020 15:10 Go to next message
Nils K. is currently offline Nils K.Friend
Messages: 13
Registered: November 2020
Junior Member
Hello,

I'm looking into a grammar template to allow zip files like e.g.

"test.zip"
"AA333.zip"
"23test.zip"

My current idea is the following terminal line to do so, but it seems not correct yet. What's wrong? I understand the following line in that way that all figures 0 to 9 or all letter a to z or A to Z are permitted (like the examples above), besides the required ending of ".zip".

terminal zipfile returns ecore::EString:
('a' .. 'z'+ | '0' .. '9'+ | 'A' .. 'Z'+ '.zip')
;

P.S.
Is there any tool around to make this grammar creation easier?
Re: grammar to permit zipfiles in a string [message #1835657 is a reply to message #1835654] Wed, 09 December 2020 15:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
hi, is there any reason to do this in grammar and not via semantic validation?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar to permit zipfiles in a string [message #1835659 is a reply to message #1835657] Wed, 09 December 2020 15:34 Go to previous messageGo to next message
Nils K. is currently offline Nils K.Friend
Messages: 13
Registered: November 2020
Junior Member
What do you mean by semantic validation? (Sorry I'm new to xtend/xtext)

Where are semantic validations usually performed in a xtend/xtext project? Can I look for some keywords maybe?
Re: grammar to permit zipfiles in a string [message #1835660 is a reply to message #1835659] Wed, 09 December 2020 15:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
have a look at the example xtext generates in the wizard

public class MyDslValidator extends AbstractMyDslValidator {
	
	public static final String INVALID_NAME = "invalidName";

	@Check
	public void checkGreetingStartsWithCapital(Greeting greeting) {
		if (!Character.isUpperCase(greeting.getName().charAt(0))) {
			warning("Name should start with a capital",
					MyDslPackage.Literals.GREETING__NAME,
					INVALID_NAME);
		}
	}
	
}


imagine instead of checking for first char is upper you check for the string to end with zip



Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar to permit zipfiles in a string [message #1835662 is a reply to message #1835660] Wed, 09 December 2020 16:14 Go to previous messageGo to next message
Nils K. is currently offline Nils K.Friend
Messages: 13
Registered: November 2020
Junior Member
Well, I found the designated files for that purposes and it includes some checks, but none of them include the current checks that may be defined by the grammar file.

My current issue is that the grammar definition is defined by some sort of image definition (ecore file) that needs to be extended to permit zip files.

How can I achieve that via grammar definition?
I thought about this way (adding | '<' zipfile '>' )

Image:
'<' ...existing type.. '>' | '<' zipfile '>'
;

terminal zipfile returns ecore::EString:
('a' .. 'z'+ | '0' .. '9'+ | 'A' .. 'Z'+ '.zip')
;

Does my zipfile definition allow all sorts of names in front of a .zip ending?
Re: grammar to permit zipfiles in a string [message #1835663 is a reply to message #1835662] Wed, 09 December 2020 16:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13724
Registered: July 2009
Senior Member
the problem is. lexers in antlr are not quite powerful and they are not context sensitive

thus again: why in grammar.
why not use normal STRING in grammar to parse "test.zip"
and validate it.

or dont you have " at all.
can you then give examples
for the

< > stuff.


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: grammar to permit zipfiles in a string [message #1836066 is a reply to message #1835663] Sat, 19 December 2020 15:24 Go to previous message
Nils K. is currently offline Nils K.Friend
Messages: 13
Registered: November 2020
Junior Member
Thanks for your help. I resolved it and it appears to be an issue with the validation code of the first grammar option. Maybe, that's of help to others anyway and besides the grammar, there might be code elsewhere that leads to errors even it looks like the grammar is the issue on first sight.

[Updated on: Sat, 19 December 2020 15:25]

Report message to a moderator

Previous Topic:Calling doGenerate in other doGenerate
Next Topic:What'S EStructucalFeature and how to convert enum grammar defintions to it?
Goto Forum:
  


Current Time: Mon Jan 25 15:01:48 GMT 2021

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

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

Back to the top