Repository navigation
PMD-3546925 PLSQL Language for PMD - #1
Conversation
|
This integration basically dumps a fully independent JavaCC lexer into the PMD packages, but fails to (a) integrate is as a PMD Language with a LanguageVersionHandler, or (b) use the PMD common JavaCC classes. I was going to see if I could clean up this up quickly, but I can't. The grammar is not included in the commit. This is required to maintain the code and do (b) above. It should be in the /etc/grammar directory, along with corresponding modifications to /src/main/ant/alljavacc.xml. Look very closely at how the C++ language is integrated. The PLSQL would be essentially the same. Feel free to take a stab at this, otherwise include the grammar and I'll see when I can get to it next. |
|
Nothing about the PL/SQL parser is quick :-( - (most of the keywords in PL/SQL are not reserved words and infrequent or edges cases have increased the parser generation time from about 3 minutes to 90 minutes. As an example FUNCTION can be a keyword or a variable, parameter, or database table or column name. The PL/SQL parser also combines the wonders of mixed Pl/SQL, SQL*Plus, SQL DML (SELECT,INSERT,UPDATE,DELETE.MERGE) and DDL (CREATE and DROP, etc.). The committed code is the simplest translation of the JavaCC compiler to a JJTree equivalent, and is of immediate use for CPD. The grammar has been committed under /etc/grammar (sturton/pmd on github). 2 versions have been committed: the first version equates to the non-Visitor version used to generate the CPD tokenizer and the second version is modified to allow the Visitor pattern and return a terminal object. Playing with the resultant java classes, it seemed as if some of the PMD applications were Java language specific: as an example the ViewerModel class (used in bgastviewer) references the Java terminal object (ASTCompilationUnit) explicitly. [ " < import net.sourceforge.pmd.lang.java.ast.ParseException;
" On 25 Aug 2012, at 09:44, ryan-gustafson [email protected] wrote:
|
|
Unless you want to write PMD Rules and thus need the AST, or the tree/lexer portions of the grammar are horribly intertwined, my guess is you could remove all tree portions from the grammar, and convert this to a .jj instead of a .jjt. That's what is done for C++, it's just a lexer, no tree building (look in the lang.cpp.ast package). As is, the AST produced is utterly useless for visiting, all nodes are of the same type. It needs to go solidly one way or the other (lexer or lexer+tree), the SimpleNode partial approach isn't acceptable. I think the Viewer is dead code (just not yet removed), the Designer is what you should be using, and it's fully dynamic to support any AST producing Language. Which if you drop AST support becomes a non-issue. The manual mods to generated code are unnecessary, this should all be automated via Ant scripts, per my prior comment. I can get his working if we make a decision on whether we are lexing or building trees. I thought I recall Romain commenting on licensing before (LGPL). Has that been resolved? |
|
On 26 Aug 2012, at 10:43, ryan-gustafson [email protected] wrote:
[ when others then null - The Tom Kyte Blog - Yes ] The other benefit that I want to get out of this integration is the tree generator/Visitor combination itself, for use by anyone who thinks of a use for a functional PLSQL AST. Without full PMD integration there is little benefit of extending beyond the PLDoc/CPD hybrids that I cobbled together:- http://pldoc.sourceforge.net/maven-site/pldoc-cpd/ and http://pldoc.sourceforge.net/maven-site/maven-cpd-plugin/index.html. Of the 2 committed versions of PldocAST.jjt, the committed classes relate to the original (CPD only version): the separate classes have been generated but were not committed into my PMD sourcetree because I wanted to keep the Visitor implementation uncommitted until I had a working Designer (or at least a working Viewer) implementation. I will commit the (separate) classes generated by the Visitor version.
I don't know whether Albert has managed to get around to responding.
|
|
The AST* classes are committed to sturton/pmd, replacing the old CPD only classes. I'm in the middle of cribbing the classes required from the Java language to get the PLSQL Scope classes. The main problems are that the important productions are missing from the PLDoc .jjt file. ASTMethodDeclarator On 25 Aug 2012, at 09:44, ryan-gustafson [email protected] wrote:
|
|
Status report (sturton/pmd committed at github) productions amended to copy Java productions as much possible Designer class copied as PLSQLDesigner (because the Designer class imports Java specific classes); and these seem to be functioning Not yet attempted: On 26 Aug 2012, at 10:43, ryan-gustafson [email protected] wrote:
|
|
Test Rule " IS BEGIN UPDATE employee_on_activity ea SET ea.ea_planned_hours = p_hours WHERE ea.ea_emp_id = p_emp_id AND ea.ea_proj_id = p_project_id; EXCEPTION END set_new_planned; FUNCTION existing_planned (p_emp_id IN NUMBER, p_project_id IN NUMBER) RETURN NUMBER IS existing_hours NUMBER(4); BEGIN RETURN (existing_hours); EXCEPTION END existing_planned; END update_planned_hrs; "
|
|
PMD » pmd #3 FAILURE |
|
PMD » pmd #4 FAILURE |
|
PMD » pmd #5 FAILURE |
|
PMD » pmd #7 FAILURE |
|
PMD » pmd #8 FAILURE |
|
PMD » pmd #9 FAILURE |
|
PMD » pmd #12 FAILURE |
|
PMD » pmd #14 FAILURE |
|
PMD » pmd #15 FAILURE |
|
PMD » pmd #16 FAILURE |
|
PMD » pmd #17 FAILURE |
|
PMD » pmd #18 FAILURE |
|
PMD » pmd #22 FAILURE |
|
PMD » pmd #23 FAILURE |
|
PMD » pmd #24 FAILURE |
|
PMD » pmd #5 FAILURE |
|
PMD » pmd #6 FAILURE |
|
PMD » pmd #7 FAILURE |
|
PMD » pmd #8 FAILURE |
|
PMD » pmd #9 FAILURE |
|
PMD » pmd #10 FAILURE |
|
PMD » pmd #11 FAILURE |
|
PMD » pmd #12 FAILURE |
|
PMD » pmd #121 FAILURE |
|
PMD » pmd #125 SUCCESS |
|
PMD » pmd #126 SUCCESS |
|
PMD » pmd #151 FAILURE |
…, 12c ACCESSIBLE BY clause )
Remove unused imports and variables
Conflicts: pmd/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java
|
Many thanks again for the effort you have put into this - and sorry again, that it took so long. It's now finally merged into the core PMD codebase. |
|
I'm just glad to contribute: I had experience with PLDoc's PLSQL parser and owned Tom Copeland's book, and it seemed easier/more efficient to add PLSQL into PMD, rather than to extend PLDoc with code metrics. I know that the PLDoc project owner (Albert Tumanov) was also happy that work on PLDoc was useful outside the project. Hopefully the work that you put into making PMD more language agnostic, will prompt more people to add languages. |
Add support lexical parameters in SQL*Plus scripts, allow excluding lines which the parser does not understand.
New version of XML to HTML transformer
Patch to:-
add Oracle PL/SQL language to PMD languages
add PL/SQL as an option to CPD
AST is derived from PLDoc parser (pldoc.sourceforge.net) 1.3.2.
The AST also covers a subset of SQL*Plus.