grammar to permit zipfiles in a string [message #1835654] |
Wed, 09 December 2020 15:10  |
Eclipse User |
|
|
|
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 #1835660 is a reply to message #1835659] |
Wed, 09 December 2020 15:46   |
Eclipse User |
|
|
|
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
|
|
|
Re: grammar to permit zipfiles in a string [message #1835662 is a reply to message #1835660] |
Wed, 09 December 2020 16:14   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03413 seconds