Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#67 Move to <<= introduced a bug

v1.0 (example)
closed
Paul McGuire
None
5
2014-04-13
2013-04-21
Luc J. Bourhis
No

In version 1.5.7, <<= is made a synonym of << and in the trunk, it has become the other way around with a deprecation warning for <<. But the problem in that in both cases, __ilshift__ returns None. That means that with, at least with Python 2.x,

expr1 <<= expr2

results in expr1 being None. It can therefore not be reused in any subsequent rules.

Am I missing something, or is it a serious bug?

Discussion

  • Mathias Mamsch
    Mathias Mamsch
    2013-05-21

    I can reproduce the issue on pyparsing 2.0 on python 3.4. Run the following code:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    #!/usr/bin/python
    from pyparsing import Forward, Word
    
    x = Forward() 
    
    x <<= Word("Abc")
    
    if x is None: 
        print ("This is a bug!")
    else:
        print ("This worked!")
    

    A possible fix for the bug is to return the Forward() instance from the ilshift operator in pyparsind::Forward

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    #!/usr/bin/python
    
        def __ilshift__( self, other ):
            if isinstance( other, basestring ):
                other = ParserElement.literalStringClass(other)
            self.expr = other
            self.mayReturnEmpty = other.mayReturnEmpty
            self.strRepr = None
            self.mayIndexError = self.expr.mayIndexError
            self.mayReturnEmpty = self.expr.mayReturnEmpty
            self.setWhitespaceChars( self.expr.whiteChars )
            self.skipWhitespace = self.expr.skipWhitespace
            self.saveAsList = self.expr.saveAsList
            self.ignoreExprs.extend(self.expr.ignoreExprs)
            return None  # <<<- change to "return self"
    
     
    Last edit: Mathias Mamsch 2013-05-21
  • Paul McGuire
    Paul McGuire
    2013-07-17

    Thanks! I have updated the source code in SVN, and will distribute this in version 2.0.1.

     
  • Paul McGuire
    Paul McGuire
    2014-04-13

    Fixed in 2.0.1, and updated in 2.0.2

     
  • Paul McGuire
    Paul McGuire
    2014-04-13

    • status: open --> closed
    • assigned_to: Paul McGuire
    • Group: --> v1.0 (example)