#784 [SQL] Add control for PL/SQL structure

open
Scintilla (358)
5
2011-02-14
2011-02-14
No

Hello Neil,
I propose you this patch that add control for PL/SQL structure.
This patch detects errors into the PL/SQL structure (ex: IF without THEN or END IF, CASE without END CASE and so on) via the "CheckThisStatement" method (i.e. whether PL/SQL is well formed or not)
For now, I use two vectors to store all structs, but I plan to switch onto your new SparseState class. That's my next job ;)
I add also a patch for sql keyword.

The overview of this patch :
- for each new lines, lexer resets several flag, set counters and delete old data into 2 vectors (all data that concern the next lines, that going to be parse by the lexer) via pmethod "prepareSQLStatesForLine".
- lexer detects usefull sql keywords.
- lexer adds it into SQLStates obecjt via "AddStatements" method, the return of this method gives (overwrite) the actual type of plsql statement (ex: one "IF" can be for "IF ... THEN" or "IF ... EXISTS", idem for "PROCEDURE" can be PROCEDURE SPEC or PROCEDURE BODY).
- If the structure of PL/SQL is not well formed, then the return of "AddStatements" method is PLSQL_NOT_WELL_FORMED. The lexer could change the color line in this case (not yet implemented).

List of new features :
- better folding for "case when", anymore limitation with folding into exception block.
- better folding for "case" with first "when", there is anymore SC_MARKNUM_FOLDERMIDTAIL on the first "when then".
- detect PL/SQL not well formed.
- remove "statementFound" flag that be removed by classic mecanism (ex : "if (levelCurrent > levelNext) levelCurrent = levelNext;" like bracket folding).

TODO :
- replace 2 vectors (statementsStack and linesPosition) by your new SparseState class.
- add error managment. By the way, how can I change the style of line into "void SCI_METHOD Fold(...)" method ? I try LexAccessor::SetLineState (int,int) without success...
Jérôme

Discussion

1 2 > >> (Page 1 of 2)
  • Neil Hodgson

    Neil Hodgson - 2011-02-14
    • assigned_to: nobody --> nyamatongwe
     
  • Neil Hodgson

    Neil Hodgson - 2011-02-14

    For the accented characters in your name to show correctly the file needs a UTF-8 coding cookie in the first two lines like:
    // -*- coding: utf-8 -*-

    The split into lex and fold phases is trying to make things simpler by having folding work on completed lexical information. Changing the styles in the fold phase, while possible, goes against this and will cause problems for you and make it harder for others to maintain.

    An approach that may be more compatible with the standard flow would be to use the IDocument::Decoration* methods to place decorations over the errors. There have not been any use of these up to now as they were included to match a similar feature in LexPython used to indicate bad whitespace but LexPython hasn't been converted to a lexer object yet. You'll be a pioneer here so read up on decorations in the Scintilla documentation.

     
  • Jérôme LAFORGE

    >IDocument::Decoration*
    I've just tested, that' exactly what I was lookin for!!!
    Many Thx.
    Jérôme

     
  • Jérôme LAFORGE

    You can find the new patch with the cookie and the Decoration, that works :)
    But another question, is it possible to change the color of decoration?

     
  • Jérôme LAFORGE

    The new patch where decoration can be modified by the application.
    Jérôme

     
  • Jérôme LAFORGE

    Please find this new patch with more description for lexer.sql.error.structure.indicator property.
    Jérôme

     
  • Jérôme LAFORGE

    patch #3 with more description for lexer.sql.error.structure.indicator property.

     
  • Jérôme LAFORGE

    i propose also this patch #4 (if misunderstand) where the lexer can't set decoration

     
  • Neil Hodgson

    Neil Hodgson - 2011-02-17

    I'm a little concerned about existing applications producing unexpected decorations when upgrading to this version with no way to turn them off. Perhaps there should be an option to control whether this is done.

     
  • Jérôme LAFORGE

    plz find the new patch #5 with lexer.sql.not.well.formed.decoration for turning off decorations.
    Jérôme

     
  • Jérôme LAFORGE

    patch #5 with way to turn off decorations.

     
  • Jérôme LAFORGE

    > GetNameForThisStatement is not used
    Is it possible to keep it anyway or surround it with preprocessor directives like #ifdef DEBUG ... #endif.
    Because, this method is very useful during debugging.
    During the tests, I used printf for logging all informations (like Statement name with this method).
    I remove it for the patch but it would be useful to keep this kind of mechanism with preprocessor directives for future debugging.
    Maybe you already defined into scintilla a better way to trace useful information.

    > "valid" is a word but "valide" is not: isValideParent->isValidParent
    oops, it's mess with my native language...
    I'm going to fix it with next patch.

    > A space has been removed from the text for lexer.sql.allow.dotted.word
    Maybe I miss something, because into DefineProperty if the 2 description strings then "./LexGen.py" put one space between 2 description strings.
    I have this on my SciteDoc.html "Set to 1 to colourise recognized words with dots (recommended for Oracle PL/SQL objects)."
    Whatever, I'm also going to add this space.

    I waiting for your response about cleaner debug method, and after I'll propose a new patch with your recommendations.

     
  • Neil Hodgson

    Neil Hodgson - 2011-02-19

    Different people debug differently and debug code is often crafted for a particular problem. Its almost never useful to others so I would really prefer that no debugging code be included in releases. Even when only active in debug builds, traces from a lexer will get in the way of debugging other features. You could have a private header with debugging functions that you add when debugging and remove for releases.

    There is Platform::DebugPrintf but that also requires uncommenting the #define TRACE in PlatWin.cxx and rebuilding.

    From the point of view of the C++ compiler, there is only one description string for lexer.sql.allow.dotted.word: two adjacent string literals are joined together. Changed LexGen.py to produce same result as compiler.

    stmtsIndex appears unused.

     
  • Jérôme LAFORGE

    With this patch, I found a problem with case ... when ... then ... end into SQL request.
    The synthax of case into SQL request is :
    CASE ... WHEN ... THEN ... ELSE ... END (without END CASE)
    With this example, you can see the problem :
    SELECT CASE 'DUMMY' WHEN 'DUMMY' THEN 1 ELSE 2 END FROM DUAL GROUP BY CASE 'DUMMY' WHEN 'DUMMY' THEN 1 ELSE 2 END;
    the CASE statement into "GROUP BY" is catched like the end of END of first CASE. So WHEN, THEN and ELSE into "GROUP BY" are managed like PLSQL_NOT_WELL_FORMED by the lexer.

    For fixing, I'll disable the PL/SQL control structures into SQL request (like SELECT, INSERT and so on) but keep the folding enabled
    I'll also remove SQL_EXISTS because that's only within SQL request.

    I propose this patch #6 but for now without the fix for CASE into SQL request.

     
  • Neil Hodgson

    Neil Hodgson - 2011-02-23

    The decoration code is a bit verbose with this pattern repeated many times:

                if \(options.sqlDecorationSqlNotWellFormed\) \{
                    if \(stmt == PLSQL\_NOT\_WELL\_FORMED\)
                        //todo: error managment
                        pAccess->DecorationFillRange\(i, 1, j\);
                    else
                        pAccess->DecorationFillRange\(i, 0, j\);
                \}
    

    This can probably be moved to the end as a common block.

    At more than 500 lines, its likely CheckThisStatement could also be shortened and simplified.

     
  • Nobody/Anonymous

    hof9YG <a href="http://pvohqlusfpxy.com/">pvohqlusfpxy</a>, [url=http://vdtbribjvxxf.com/]vdtbribjvxxf[/url], [link=http://rmyohykshvkp.com/]rmyohykshvkp[/link], http://bcmpgtcoocph.com/

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks