public static void main(String[] args) {
BausteineStandaloneSetup setup = new BausteineStandaloneSetup();
setup.doSetup();
Injector injector = setup.createInjector();
Main main = injector.getInstance(Main.class);
main.write();
}
I currently use this to preparse arbitrary files which are not in my DSL and transform them. I do not want to rewrite particular checks for Rules, e.g. to verify if an ID is in the correct format, hence I just get the Parser injected and invoke the rule checking with a StringInputStream.
This looks roughly like this:
@Inject
private IAntlrParser parser;
@Inject
private BausteineGrammarAccess access;
...
InputStream inputStream = new StringInputStream("baustein " + name);
IParseResult result = parser.parse(access.getBausteinDefRule().getName(),inputStream);
There might be a more efficient way to do this, but currently I am quite happy with the solution. I guess I could try to use the lexer instead of the parser if I only want to check for terminals, but I need to extend the checks anyway.
0 comments:
Post a Comment