Use Generator CodeGen in Tatsu - parsing

I have generated Model code and parser from my Grammar but I can't modify model to generated code in python.
My EBNF grammar is a script code like "C" syntax for translate file in XML or ANSI X12.
It's a language specific and I would like to generate Python code from this script with Tatsu.
I parse script but I can't success to use Parser or Model to generated Python source code.... Where i must to save Model or modify parser to generated python code ... I see tools.py ... can I copy the code to build a new code model...
Can you help me ... I start learn python and i must to implement this solution on web site with upload script and download python code.

TatSu is a parser generator. I doesn't have any provisions for generating running code from text parsed by an arbitrary grammar.
You have to write your own code generator (walk thes AST after a parse, and generate the corresponding code).

Related

Why ANTLR generated parser has not parse/start/begin functions?

I am trying to generate parser with ANTLR for the minimalistic grammar of First Order Logic, that can be found at the ANTLR source code: https://github.com/antlr/grammars-v4/blob/master/fol/fol.g4
The strange thing is, that the generated Parser has no parse, begin, start methods that can be seen in every tutorial. Listener is generated as well, but I am interested to get the parse tree (for later manipulation) and, besides, many tutorials that mention listeners, use one of mentioned 3 functions anyway. What has gone wrong? Are there parser generation options?
The mentioned methods are not included in the generated code, yes, they may be in the base class, but Eclipse consider their us as error (undefined methods).
I am using antlr 4.8.
The generated parser class will have methods with the same names as the rules you define in your grammar. So if your grammar has a rule named foobar and you want to parse your input according to that rule, you'd call parser.foobar() to do so.
If the code in your tutorial calls a method named parse, begin or start, then the grammar in that tutorial almost certainly defines a rule with that name.
In the grammar you linked, the main rule is called condition, so that's the method that you should be calling.

No completion for Xbase expressions when embedded in another Xtext DSL

I am building a Xtext DSL and I want to embed Xbase expressions in some specific places to interpret part of my models using the Xbase interpreter, but I am not able to have method completion in the generated editor.
I reused the examples provided here: https://www.eclipse.org/Xtext/documentation/201_sevenlang_introduction.html, and manage to integrate Xbase as part of my grammar. Keyword completion proposal is working fine (i.e. do, for, while ...), but I can't find a way to have completion for Java/Xbase methods (e.g. newArrayList, or myArray.add(X)).
Clarification from comments below: if I write var x = newArrayList in the editor the method is not styled in italic but I don't have any error either.
This is a sample version of the grammar I am using:
grammar org.xtext.example.common2.Common2 with org.eclipse.xtext.xbase.Xbase
generate common2 "http://www.xtext.org/example/common2/Common2"
import "http://www.eclipse.org/xtext/xbase/Xbase"
Test returns Test:
{Test}
'test'
expressions+=Script
;
Script returns XBlockExpression:
{Script}
'{'
(expressions+=XExpressionOrVarDeclaration ';'?)*
'}'
;
I found out that if I change my grammar to the following one I can have the completion as expected:
grammar org.xtext.example.common2.Common2 with org.eclipse.xtext.xbase.Xbase
generate common2 "http://www.xtext.org/example/common2/Common2"
import "http://www.eclipse.org/xtext/xbase/Xbase"
Test returns XBlockExpression:
{Test}
'test'
expressions+=Script
;
Script returns XBlockExpression:
{Script}
'{'
(expressions+=XExpressionOrVarDeclaration ';'?)*
'}'
;
My guess is that all the tree must be composed of instances of XExpression to enable the completion, but I don't understand why? To me Test should not be a subclass of XBlockExpression (in my real-world use case Test has additional attributes/references), but it should contain an XBlockExpression.
Is there a way to achieve this? Any help/resource to look at would be much appreciated
Note
I already checked this SO question How to embed XBase expressions in an Xtext DSL, I already have xbase.lib in my build path.

JavaParser: Where is the Java grammar definition?

Where can I get the BNF-style Java 1.8 grammar that JavaParser is actually using to parse Java code?
There's a java_1_8.jj file in JavaParser's codebase automatically generated by javacc, but no sight of the grammar file used to generate this .jj file.
There's a java_1_8.jj file in JavaParser's codebase automatically generated by javacc, but no sight of the grammar file used to generate this .jj file.
java_1_8.jjis the grammar file, while it is not in the BNF style you expected. It is not generated, but it is used to generate the parser java files.

Do anybody know how to generate the rsc file of jdt's parser

Do anybody know how to generate the rsc file of jdt's parser .I mean how to serialization the rule of parser .and where can i find the detail about the rule.
I have import jdt to my code ,and try to learn the rule of the parsr.
But the serialization rule confuse .Then i can easier to learn the rule if i find the code which is used to serialization the rule to rsc file.
http://www.eclipse.org/jdt/core/howto/generate%20parser/generateParser.html
i think i hava found the answer.

DOM like parser for lua similar to perls PPI

Im looking for a DOM parser for the lua language that works similar to the great PPI parser for perl.
Basically i have a lot of lua scripts bound to specific entities - i want to evaluate some specific function calls within these scripts to show some generic information about a script (generate a report for example).
E.g.
function func1()
....
if(check(1,4))
end
end
In this case, i want the dom parser to find the function call check with a number of arguments.
I dont want to use regexp or similar tools, a DOM parser would be the best.
LuaInspect is what you want.
LuaInspect builds an AST (what you are calling a DOM) from Lua code, and can perform static analysis on it. It can generate an HTML report, and is also used to for code completion in some editors.
command.lua is LuaInspect's main file, which uses ast.lua to build the AST, etc.

Resources