setResultsName question

2006-01-25
2013-05-14
  • Jacek Sieka

    Jacek Sieka - 2006-01-25

    Hello,

    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"))

    <aa>
      <ITEM>b</ITEM>
    </aa>
    (['b'], {'xx': [((['b'], {}), -1)]})

    <bb>
      <xx>b</xx>
    </bb>
    (['b'], {'xx': [('b', 0)]})

    prints:

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

    Thanks!

     
    • 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 []:

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

      [bb]
        [xx]b[/xx]
      [/bb]
      (['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