setResultsName question

  • Jacek Sieka

    Jacek Sieka - 2006-01-25


    my pyparser adventures continue (excellent package by the way).
    Here's are two grammars for parsing the same language, but only the latter gives me the results I expect, and I don't quite understand why, and what to do to avoid the ugly construct:

    from pyparsing import *

    x = Literal('b').setResultsName("xx")
    y = (Literal('b').setResultsName("xx") + Empty())

    print x.parseString("b").asXML("aa")
    print repr(x.parseString("b"))

    print y.parseString("b").asXML("bb")
    print repr(y.parseString("b"))

    (['b'], {'xx': [((['b'], {}), -1)]})

    (['b'], {'xx': [('b', 0)]})


    Anyone else ran into this before? (I hope sf's forum didn't eat too much of my text...)


    • Jacek Sieka

      Jacek Sieka - 2006-01-25

      This will perhaps be better formatted:
      from pyparsing import *

      x = Literal('b').setResultsName('xx')
      y = (Literal('b').setResultsName('xx') + Empty())

      print x.parseString('b').asXML('aa')
      print repr(x.parseString('b'))

      print y.parseString('b').asXML('bb')
      print repr(y.parseString('b'))

      and the output, with the xml chars replaced by []:

      (['b'], {'xx': [((['b'], {}), -1)]})

      (['b'], {'xx': [('b', 0)]})

      (ps, this is with pyparsing 1.4)

    • Paul McGuire

      Paul McGuire - 2006-01-26

      Jacek -

      Thanks for the compliments on pyparsing - it has really taken on a life of its own!

      I will look into your test cases a little further.  asXML() has always been a little dicey, and your examples may help me fix it up a bit.

      I'll respond further when I've made some progress.  For now, your ugly structure is the workaround for this problem.

      -- Paul

    • Jacek Sieka

      Jacek Sieka - 2006-05-15

      Hi, any progress here? Or should I put this one in the bug tracker?

    • Paul McGuire

      Paul McGuire - 2006-05-15

      Sorry, I looked at this briefly, but no significant progress to report.  I will try to have this fixed in time for 1.4.3 release, but I can't promise.

      By all means, add to the bug tracker.

      -- Paul


Log in to post a comment.

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

Sign up for the SourceForge newsletter:

No, thanks