as part of our application i need to build component that will output code in php and asp
that have the same functionality ( and maybe latter jsp ) .
how can i design this kind of component to be generic as possible ?
You need to be able to create a parse tree out of all input languages.
For each output language, you will need to create a set of tree transforming grammar.
You may also require a runtime library to help translate routines that are not available in your output language.
I would personally go with the Strategy Pattern. You could have a master code maker class and instantiate it with a strategy.
PHPCodeStrategy
ASPCodeStrategy
Then each would have a method called execute maybe. Bu then you could add further strategies down the line and extend your application.
Andrew
Related
I have been playing with ANTLR Lab (really nice by the way) and was wondering how it is able to label the matching parser rule and alternative number. For example, below content:1, x_tag:2 and x_tag:3 are all rule names and the number after the colon is the alternative within that rule.
I have built a recognizer from my grammar but cannot see from looking at the runtime API how to access them from within a custom listener.
AFAIK, ANTLR Lab and the ANTLR IntelliJ plugin both use the RuleContextWithAltNum to set and get the alternative.
Note that it is only implemented in Java. From the documentation:
A handy class for use with options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} that provides a backing field / impl for the outer alternative number matched for an internal parse tree node. I'm only putting into Java runtime as I'm certain I'm the only one that will really every use this.
Also see the related stackoverflow Q&A: Is there a way to know which alternative rule ANTLR parser is currently in?
in my project we use a Xtext template language to create some documents.
Similar to whats written here:
https://www.eclipse.org/Xtext/documentation/207_template.html
So basically a template starts with a « and ends with a »
In between we call xtend functions which define what will be visible in the output html document.
We would like to add a graphical editor to the already existing textual one.
I saw that Sirius can interact with Xtext and found the examples quite interesting.
What I could not figure out was how to tell Sirius to use my already existing xtend functions.
My question is: Is there a way to create a graphical interface for a xtedt template language with sirius or am i running in a dead end?
Thanks in advance
This seems doable, however it is not clear what you mean by "how to tell Sirius to use my already existing xtend functions". Maybe you could start by providing an example of what your templates look like, and the kind of representation you expect to have.
If I refer to the Xtext example you link, an Xtend function call in your template is an XBlockExpression. You would thus need to specify in Sirius an adequate representation for this metaclass.
Links that may help can be found here: https://www.eclipse.org/forums/index.php/t/1090448/
Is there a way to build a ruleset in codeeffects from a string? The default way over the ASP/MVC RuleEditor is currently not an option.
You need to use RuleXML if you want to build your rules dynamically outside of our editor. It's a common way of creating rules in Code Effects. String representation is too generic to be useful in rule generation. Details on RuleXML can be found here.
Also, please take a look at SourceXML; it allows you to generate your source objects dynamically, too. This is a MUCH more flexible approach for source handling that plain .NET objects. Details can be found here.
I'm new to web development with Symphony2 (though definitely not new to web development), and I'm just about to begin a medium sized project, which will be sliced in bundles, as each installation of the app may have a different setup of available functionality.
I would like to generate my navigation dynamically from the available bundles, e.g. if the bundle "foo" is active, a menu entry with a route to the foo main controller action should appear.
Normally, my take on this would be to create a singleton somewhere, which I then would fill during the load() function of a bundle, and during rendering, I would output the singleton.
But symfony2 offers a lot flexibility at this part, so I'm currently evaluating if there may be a better way.
Could services be a way to go here? Or events? Or something with dependency injection, so the bundles get an instance of a NavigationConfigurationElement at construction time?
Any input or thoughts on this, or maybe some links to examples how to do this, would be greatly appreciated.
Best regards,
Jens
i thing the best way to do it, is to use dependency injections tags. you will have to create a dependency injection extension and offer a "tag" that can be used by the various bundles to register their menu entries.
i will not describe you the whole process here because there is plenty of resources about that in the internet.
but to give you a quick outline of what to do
implement a service holding the menu entries (the singleton you where talking about)
process the tag by implementing a compiler pass, this compiler pass will look for all services tagged with the navigation class and register them with the menu service
create a twig function that will use the service to retrieve the menu and render it
write bundles that use the tag and provide menu items
here are some resources that might help you:
http://symfony.com/doc/current/components/dependency_injection/tags.html
http://miguel.ibero.me/es/post/2012-04-28/adding-tags-to-symfony.html
i'm currently implementing a solr bundle for symfony that uses DI tags as well. i have a class called IndexManager that manages various solr indexes from different bundles. i use the DI tag so other bundles can register content/entities they want to be indexed in solr. the principle is the same as with the menu items.
see here: https://github.com/roomthirteen/Room13SolrBundle
the important files are:
adding the compiler pass: https://github.com/roomthirteen/Room13SolrBundle/blob/master/Room13SolrBundle.php
the compiler pass itself: https://github.com/roomthirteen/Room13SolrBundle/blob/master/DependencyInjection/Compiler/SolrCompilerPass.php
hope that helps. any more questins? don't hesitate to ask.
I would like to find the best way to parse an UML Diagram that detail the security tomcat configuration for a web application, then generate the concerned file (web.xml).
For the beginning, I have a Metamodel and his instance created with Magic Draw, I have to export them and use them in a kind of java application (plugin? API?) then parse and validate them against some constraint (OCL?) finally I have to generate the Web.xml file.
So, I made some research and I found that I can use EMF to catch my models, but its not so clear and handily to create a peace of java code that can handle my model remotely from an URI then validate em.
Do you have any suggestions/advises to made this please? Do I must use EMF? or there is another framework?
Thanks
web.xml from UML? Sorry, I don't think it's a useful idea. It doesn't take long to hand edit such a thing. The effort it would take to automate such a thing wouldn't be worth it. I'd open up a text editor, create the web.xml, and spend the time you save doing more useful things.
But, if you must, I'd find a way to export your object model into an XML document. I'd parse that into a DOM tree, walk the tree, and emit the elements I needed into a web.xml.
I know that Magic Draw has the capability to export UML as XML. See if that helps you.
But there's no way to do it directly from the Magic Draw tool that I know of. You'll have to write this Java post-process and run it on the command line using the exported model XML as input.