#3 Parsing of a multiline trace event.

closed
nobody
None
9
2004-07-26
2004-07-12
No

Hi Paul,
you can see the newse source of our scanning modul at:

http://cvs.sourceforge.net/viewcvs.py/etprof/etprof/Test/test_etscan.py?rev=1.8&view=auto

Now we have to work out how to define the grammar for
the trace-entry with multipe lines :

PARSING IN CURSOR #6 len=181 dep=0 uid=8564 oct=6
lid=8564 tim=1314794115 hv=1049137217 ad= '712a38b0 '
UPDATE SIEBEL.S_EVT_ACT SET
LAST_UPD_BY = :1,
MODIFICATION_NUM = :2,
APPT_START_DT = :3,
LAST_UPD = :4
WHERE
ROW_ID = :5 AND MODIFICATION_NUM = :6
END OF STMT

This entry is constructed out of a ParsingInHeader

PARSING IN CURSOR #6 len=181 dep=0 uid=8564 oct=6
lid=8564 tim=1314794115 hv=1049137217 ad= '712a38b0 '

After this the lines ( 1..n ) of the SQL

UPDATE SIEBEL.S_EVT_ACT SET
LAST_UPD_BY = :1,
MODIFICATION_NUM = :2,
APPT_START_DT = :3,
LAST_UPD = :4
WHERE
ROW_ID = :5 AND MODIFICATION_NUM = :6

After this the End-marker of the SQL and the End of
ParsingInSection

END OF STMT

The QUESTION IS HOW WE WOULD DEFINE THE GRAMMAR FOR THIS:
The header is no Problem for us.
we want to have the SQL parsed as one 'Item'
Do you have an idea?

regards Carl r.

Discussion

    • summary: Parsing of a mulitline trace event. --> Parsing of a multiline trace event.
     
    • priority: 5 --> 9
    • status: open --> pending
     
    • status: pending --> open
     
  • Paul McGuire
    Paul McGuire
    2004-07-13

    Logged In: YES
    user_id=893320

    Carl -

    Have you tried something like:

    ZeroOrMore( ~Literal("END OF STATEMENT") + restOfLine )
    + "END OF STATEMENT"

    Can you post examples of a single line and multiline SQL
    statement, including the surrounding text? I want to see
    how a single line SQL statement is delimited.

    -- Paul

     
  • Logged In: YES
    user_id=385682

    Thanks paul for your respionse, here the whole picture,a
    complete extended trace file (see upload)

    Carl

     
  • Paul McGuire
    Paul McGuire
    2004-07-15

    Logged In: YES
    user_id=893320

    I made the following changes to your code to match multiline
    SQL (I hacked variable names, you'll want to clean them up
    in your program):

    traceLineEvt = (
    _EVENT_NAME_.setResultsName ("TraceEvent")+
    _CUR_HANDLE_.setResultsName
    ("CursorHandle") +
    OneOrMore
    (_PARAM_GROUP_).setResultsName ("Params") )

    traceHdr = "PARSING IN CURSOR" + restOfLine; # <-
    define better grammar for this
    traceLine = ( Suppress
    ("=====================") +
    traceHdr.setResultsName("ParsingStats") +
    ( OneOrMore( LineStart() + ~Literal("END
    OF STMT") + restOfLine )).setResultsName("SQLstmt") +
    Suppress("END OF STMT") +
    OneOrMore( Group
    (traceLineEvt) ).setResultsName("Events") )

    Let me know if you want more explanation or comments.
    This is (another!) area that could use more documentation
    and/or examples.

    -- Paul

     
  • Logged In: YES
    user_id=385682

    Thanks paul,
    this is more then i expected!
    i will implement this or next week
    and tell you about the results

    with kind regards
    carl

     
  • Paul McGuire
    Paul McGuire
    2004-07-15

    • status: open --> closed
     
  • Paul McGuire
    Paul McGuire
    2004-07-15

    Logged In: YES
    user_id=893320

    Carl -

    I'm glad that worked for you. I'll close out this request.

    -- Paul

     
  • Logged In: YES
    user_id=385682

    Hi Paul every works fine with multiline event Parsing in cursor!
    Here the grammar :

    traceLinePIC = ( _PIC_DLINE_ =
    Literal('=====================').suppress()
    _PIC_BEGIN_ = Literal('PARSING IN CURSOR')
    _PIC_END_ = Literal('END OF STMT').suppress()

    _PIC_LENGTH_ = Literal("len").suppress() +
    _ASSIGN_ + _INTEGER_
    _PIC_DEPTH_ = Literal("dep").suppress() +
    _ASSIGN_ + _INTEGER_
    _PIC_UID_ = Literal("uid").suppress() +
    _ASSIGN_ + _INTEGER_
    _PIC_OCT_ = Literal("oct").suppress() +
    _ASSIGN_ + _INTEGER_
    _PIC_LID_ = Literal("lid").suppress() +
    _ASSIGN_ + _INTEGER_
    _PIC_TIME_ = Literal("tim").suppress() +
    _ASSIGN_ + _INTEGER_
    _PIC_HV_ = Literal("hv").suppress() +
    _ASSIGN_ + _INTEGER_
    _PIC_AD_ = Literal("ad").suppress() +
    _ASSIGN_ + quotedString

    _PIC_SQL_ = OneOrMore( LineStart() +
    ~_PIC_END_ + restOfLine )

    traceLinePIC = ( _PIC_DLINE_ + LineStart()
    +
    _PIC_BEGIN_.setResultsName
    ("TraceEvent") +
    _CURSOR_HANDLE_.setResultsName
    ("CursorHandle") +
    _PIC_LENGTH_.setResultsName
    ("PicLength") +
    _PIC_DEPTH_.setResultsName
    ("PicDepth") +
    _PIC_UID_.setResultsName
    ("PicUid") +
    _PIC_OCT_.setResultsName
    ("PicInOct") +
    _PIC_LID_.setResultsName
    ("PicInLid") +
    _PIC_TIME_.setResultsName
    ("PicTime") +
    _PIC_HV_.setResultsName
    ("PicHv") +
    _PIC_AD_.setResultsName
    ("PicAd").setParseAction(stripQuotes) +
    _PIC_SQL_.setResultsName
    ("PicSql") +
    _PIC_END_ )

    and here the ouptut from the test-program :

    =====================
    PARSING IN CURSOR #1 len=71 dep=0 uid=260 oct=42 lid=260
    tim=1087828747368534 hv=3555457345 ad='8fa86f70'
    ALTER SESSION SET EVENTS '10046 trace name context forever,
    level 12'
    END OF STMT

    ['PARSING IN CURSOR', '1', '71', '0', '260', '42', '260',
    '1087828747368534', '3555457345', '8fa86f70', "ALTER SESSION
    SET EVENTS '10046 trace name context forever, level 12'"]

    The only thing is would like to improve is if a parsing
    Error occurs to output something like a parsing stack, to
    know better where the grammar failed.

    thanks for your help
    Great!

    Carl

     
    • status: closed --> open
     
  • Logged In: YES
    user_id=385682

    Hi, some copy error
    the beinning of graamar must be
    _PIC_DLINE_ =

    and not

    traceLinePIC = ( _PIC_DLINE_ =

     
  • Paul McGuire
    Paul McGuire
    2004-07-25

    Logged In: YES
    user_id=893320

    Carl -

    Hm, there is no parsing exception stack, but the
    ParseException does contain a location, a reference to the
    input string, and an error message, as well as some
    computed attributes for the text line, column and line
    number. Unfortunately, I have had not very good luck with
    exceptions pointing me to the exact error location, but more
    often pointing to the end of the last successful token match.
    If you do some experiments with erroneous data input, and
    catch the exceptions in a catch ParseException structure, you
    will start to get an idea of how these exception reports work.

    One suggestion is to use setName() to give readable names
    to some of your structures, especially those defined using
    Word (the default string for Word's are fairly cryptic). Don't
    bother giving names to Literal's, they will output their literal
    string match as the expected text.

    Here is an example try-catch block from one of my example
    programs (the IDL parser):

    try:
    tokens = idlBNF.parseString( strng )
    except ParseException, err:
    print err.line
    print " "*(err.column-1) + "^"
    print err
    print

    I'm afraid that's the best I can do for now.

    -- Paul

     
  • Logged In: YES
    user_id=385682

    Hello Paul, this is absolute ok with me!

    Carl

     
  • Paul McGuire
    Paul McGuire
    2004-07-26

    • status: open --> closed