Recent Changes

Today

  1. msg Odd .copy() behaviour message posted Odd .copy() behaviour I've finally made the jump from 1.5.2 or so to 2.1.10, and what kept me from upgrading back then b…
    Odd .copy() behaviour
    I've finally made the jump from 1.5.2 or so to 2.1.10, and what kept me
    from upgrading back then bites me again: .copy() changes the behaviour
    of ParserElements since 1.5.2:

    Here's an example:

    import pprint
    from pyparsing import Word, ZeroOrMore, alphas
     
    def get_grammar():
        vanishing = Word(alphas)
        item = "foo" | vanishing
        item_seq = item + ZeroOrMore( item )
        return locals()
     
    def enable_tree(syms):
        for name, ob in syms.iteritems():
            ob.setParseAction(lambda s, p, t, name=name: (name,)+tuple(t))
     
    if __name__=="__main__":
        g = get_grammar()
        enable_tree(g)
        pprint.pprint(g["item_seq"].parseString("foo bar")[0])

    If you ignore the plumbing, it's a trivial sequence grammar. The stuff
    is arranged to spit out a representation of the parse tree, and if you
    try it, you'll see it's printing the expected

    ('item_seq', ('item', 'foo'), ('item', ('vanishing', 'bar')))

    However, if you now change the grammar to:

    def get_grammar():
        vanishing = Word(alphas)
        item = "foo" | vanishing
        item = item.copy()       # <--- inserting a call to copy
        item_seq = item + ZeroOrMore( item )
        return locals()

    pyparsing doesn't "see" the "vanishing" nonterminal any more, and the
    output is:

    ('item_seq', ('item', 'foo'), ('item', 'bar'))

    In more complex grammars, you'll see that only the level below the
    copied (or, more dramatically, setResultsName-d) element is swallowed --
    rules deeper down are again correctly represented.

    Is this expected behaviour? I'm asking because apparently no one got
    hit by this in the past eight years apart from me, so somehow I suspect
    I'm being stupid. Am I?
    8:12 am

Monday, August 14

  1. msg schemaSQL.parseFile(f) fails if parseAll=True attemted message posted schemaSQL.parseFile(f) fails if parseAll=True attemted Sorry for the n00b question, but how can I rectify this? C:\Python27\Lib\site-packages\pyparsing…
    schemaSQL.parseFile(f) fails if parseAll=True attemted
    Sorry for the n00b question, but how can I rectify this?

    C:\Python27\Lib\site-packages\pyparsing.py has
    def parseFile( self, file_or_filename, parseAll=False ):

    And the C:\Python27\Lib\site-packages\pyparsing-2.2.0-py2.7.egg-info folder has some text files, but didn't find traces of the earlier version.
    Any "tools of the trade" advice?
    Would uninstalling the whole python and installing -say- activepython distro would help?
    7:46 am

Sunday, August 13

  1. msg schemaSQL.parseFile(f) fails if parseAll=True attemted message posted schemaSQL.parseFile(f) fails if parseAll=True attemted 1.4.11 Thank you, you are right as always :)
    schemaSQL.parseFile(f) fails if parseAll=True attemted
    1.4.11
    Thank you, you are right as always :)
    8:14 pm
  2. msg schemaSQL.parseFile(f) fails if parseAll=True attemted message posted schemaSQL.parseFile(f) fails if parseAll=True attemted Hm, matplotlib used to bundle pyparsing as part of its mathtext module, so you may be having confli…
    schemaSQL.parseFile(f) fails if parseAll=True attemted
    Hm, matplotlib used to bundle pyparsing as part of its mathtext module, so you may be having conflicts there. In your code, add:
    import pyparsing; print pyparsing.__version__

    If it turns out that you are having conflicts with matplotlib's pyparsing, then be sure to import pyparsing in your module before importing matplotlib. In this way, the latest pyparsing will get imported first, and the import in matplotlib will be a no-op. I *think* matplotlib will work okay with an updated pyparsing, but if you don't use mathtext, then it won't really matter.
    7:52 pm
  3. msg schemaSQL.parseFile(f) fails if parseAll=True attemted message posted schemaSQL.parseFile(f) fails if parseAll=True attemted >python -m pip list says: ... pyparsing (2.2.0) ... C:\Users\flazar>python -V Python…
    schemaSQL.parseFile(f) fails if parseAll=True attemted
    >python -m pip list says:
    ...
    pyparsing (2.2.0)
    ...

    C:\Users\flazar>python -V
    Python 2.7
    I was trying to get some plots with numpy and mathplotlib, and I have some unsolved mysteries with the windows 64bit python and some win32 libraries, so I'm not 100% sure the plumbing is flawless.
    7:41 pm
  4. msg schemaSQL.parseFile(f) fails if parseAll=True attemted message posted schemaSQL.parseFile(f) fails if parseAll=True attemted According to the CHANGES file, it looks like that named arg was added to parseFile in version 1.5.1…
    schemaSQL.parseFile(f) fails if parseAll=True attemted
    According to the CHANGES file, it looks like that named arg was added to parseFile in version 1.5.1, back in '08. Are you on an old version of pyparsing?
    4:59 pm
  5. msg schemaSQL.parseFile(f) fails if parseAll=True attemted message posted schemaSQL.parseFile(f) fails if parseAll=True attemted result = schemaSQL.parseFile(f,parseAll=True) fails with TypeError: parseFile() got a…
    schemaSQL.parseFile(f) fails if parseAll=True attemted
        result = schemaSQL.parseFile(f,parseAll=True)
    fails with TypeError: parseFile() got an unexpected keyword argument 'parseAll',
    while doc says: def parseFile( self, file_or_filename, parseAll=False ):

    Any pointers?
    4:19 pm

Thursday, August 3

  1. msg Group result question message posted Group result question Thanks, result[2].asList()] worked perfectly. The result indices feels better with the plain…
    Group result question
    Thanks,
    result[2].asList()] worked perfectly.
    The result indices feels better with the plain list:
    ....
    ['file_inst_parent_idx', 'file_instance', 1, ['parent_id']]
    ['file_inst_src_data_file_idx', 'file_instance', 2, ['source_data_id', 'file_id']]
    ['file_inst_strm_file_idx', 'file_instance', 1, ['stream_file_id']]
    ...
    6:12 pm
  2. msg Group result question message posted Group result question There is no array ("list" actually) and there is no dict. What you are seeing is the repr…
    Group result question
    There is no array ("list" actually) and there is no dict. What you are seeing is the repr representation of pyparsing's parse output object, ParseResults. Since ParseResults objects can be accessed in both list and dict forms, the repr output shows the list elements as a list and any named elements as a dict. You can iterate over the ParseResults, index into them, invoke len() on them, just like any list, or invoke keys(), items(), values(), etc. just like a dict. See more info about ParseResults capabilities at https://pythonhosted.org/pyparsing/pyparsing.ParseResults-class.html . If you *must* have a list or dict, this class also supports asList() and asDict() methods, but you may be able to do without them. Please give it a shot and just use this as if it were a list, for instance, try printing "','.join(result[2])".
    12:45 pm
  3. msg Group result question message posted Group result question I'm parsing CREATE INDEX sql statements as : create index dft_inst_strm_dft_snpsht_el_idx on defe…
    Group result question
    I'm parsing CREATE INDEX sql statements as :
    create index dft_inst_strm_dft_snpsht_el_idx on defect_instance (stream_defect_id, snapshot_element_id);
    I'm parsing the "on defect_instance (stream_defect_id, snapshot_element_id)" part with the grammar:

    ON = Keyword("on", caseless=True).addParseAction(upcaseTokens)
    LPAREN= Suppress("(")
    RPAREN= Suppress(")")

    idxspec = ON + ident + LPAREN + Group(delimitedList(ident)) + RPAREN
    ....
    result = idxspec.parseString(stmt[3][0])
    indices.append([stmt[2] , result[1] , len(result[2]) , result[2]])
    ....
    The returned result[2] (for the Group(delimitedList(ident))) prints as (['stream_defect_id', 'snapshot_element_id'], {}) as in the appended array:

    ['dft_inst_strm_dft_snpsht_el_idx', 'defect_instance', 2, (['stream_defect_id', 'snapshot_element_id'], {})]

    I expected an ['stream_defect_id', 'snapshot_element_id'] for result[2], but looks like a tuple with the extra empty dictionary added.
    Is there an explanation, and a way to extract the "naked" array without the empty dict?
    10:43 am

More