Working With a User Generated Script [message #1016577] |
Wed, 06 March 2013 19:34  |
Eclipse User |
|
|
|
Bear with me, I'm just getting started.
A few days ago, I learned antlr - just enough to declare a simple scripting language.
The idea popped into my head that it would be great if I could have syntax highlighting, which led me to XText.
I've gone through the tutorials, but... they seem pretty advanced for my needs.
I've created a grammar and the editor works just dandy. As far as that goes, XText is pretty darn awesome - the learning curve was pretty slim.
I'm now at the point where it's time to parse the script.
My goal is the scriptable automation of an existing java application. Say, for instance, I have a java class with two methods
public class talktome{
public void sayHello(String Name){
system.out.println("Hello " + Name);
}
public void sayGoodbye(String Name){
system.out.println("Goodbye " + Name);
}
}
I want to have a script that looks like this:
automater Talk1{
SaySomethingTo("Fred")
SaySomethingTo("Wilma")
SaySomethingTo("Betty")
}
automater Talk2{
JustSayGoodbye("Daphne")
JustSayGoodbye("Scooby")
}
The end result that I want is something along the lines of:
import com.example.TalkToMe.*;
import somethingFromXtext;
public class Main {
public static void void main(String[] args){
XtextMagicalThing script = loadMyDSLScript("fromearlierinthepost");
for (automater : script.getAutomaters()){
for(command : automater.getCommands()){
if(command.name == "SaySomethingTo"){
SayHello(command.param);
SayGoodBye(command.param);
} else if (command.name == "JustSayGoodbye"){
SayGoodBye(command.param);
}
}
}
}
}
It seems to me from my basic understanding of XText that the parser is being automatically generated, I just don't know how to get it.
I did find this link which talks about loading a model, but I think I might have a little bit of a terminology disconnect. That uses EMF, and my understanding was that using EMF in a standalone application was not encouraged.
In antlr, I'd build a tree walker that parsed tokens from a lexer. Then I'd walk the tree and from there validate and interpret the results.
I see in my src-gen tree that there is an "InternalDSLLexer.java" and an "InternalDSLParser.java" that I could potentially use, but I thought it would be a good idea to ask what the recommended path is.
I hope I made at least a little bit of sense here.
|
|
|
|
|
|
|
|
|
|
Re: Working With a User Generated Script [message #1017156 is a reply to message #1017151] |
Sat, 09 March 2013 22:54  |
Eclipse User |
|
|
|
Just a quick follow up.
My memory usage issue really spawns from the fact that I started long ago when memory was expensive and everything needed to be optimized.
I can see that it's possible to generate a more efficient parser, but the default output does the job for quick and easy.
Playing around with it for a bit, I did get the jar size reduced to < 3000 files and < 4mb.
Memory usage was a bit complicated.
Looking in Task Manager shows between 120 and 160mb of usage. Profiling showed that the bulk of that was unused space and the actual used space was around 75mb.
Command line options can reduce the usage down to ~40mb, but that's not just limiting the leveraged libraries, that's also limiting the application referencing them.
I definitely see the utility in xtext and EMF - it provides a heck of a lot more than just validation of a script, but... if someone wants to efficiently run a script in an external application... it looks like you have to do one of two things:
- Write the code to generate your interpreter, or
- Write your interpreter externally
I did look through the generated antlr .g file and the resulting InternalXXLexer and InternalXXParser, but it wasn't obvious if those could be leveraged independently. Nothing to do at this point but give it a shot.
I do want to thank you very much Christian. The direction you provided was very helpful to me.
|
|
|
Powered by
FUDForum. Page generated in 0.06147 seconds