[Python-modules-commits] [xlwt] 01/01: Add patch to de-embbed antlr (rather than a +debian1 package).

Thomas Goirand zigo at moszumanska.debian.org
Thu Oct 26 13:09:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

zigo pushed a commit to branch master
in repository xlwt.

commit 7289a1f4371dd1cb05b773f5c88751281dce50a2
Author: Thomas Goirand <thomas at goirand.fr>
Date:   Thu Oct 26 13:08:46 2017 +0000

    Add patch to de-embbed antlr (rather than a +debian1 package).
---
 debian/changelog                           |    2 +
 debian/patches/remove-embedded-antlr.patch | 2882 ++++++++++++++++++++++++++++
 debian/patches/series                      |    1 +
 3 files changed, 2885 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 60a90ea..a6cc6ff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -13,6 +13,8 @@ xlwt (1.3.0-1) unstable; urgency=medium
   * Generate the doc using sphinx.
   * Fixed dh sequencer call order.
   * Standards-Version is now 4.1.1.
+  * Add patch to de-embbed antlr (rather than a +debian1 package). It's ok to
+    do so as antlr.py is redistribuable.
 
  -- Thomas Goirand <zigo at debian.org>  Wed, 25 Oct 2017 17:00:23 +0000
 
diff --git a/debian/patches/remove-embedded-antlr.patch b/debian/patches/remove-embedded-antlr.patch
new file mode 100644
index 0000000..cabffef
--- /dev/null
+++ b/debian/patches/remove-embedded-antlr.patch
@@ -0,0 +1,2882 @@
+Description: Remove embedded antlr
+Author: Thomas Goirand <zigo at debian.org>
+Forwarded: no
+Last-Update: 2017-10-26
+
+--- xlwt-1.3.0.orig/xlwt/ExcelFormulaParser.py
++++ xlwt-1.3.0/xlwt/ExcelFormulaParser.py
+@@ -1,6 +1,6 @@
+ ### $ANTLR 2.7.7 (20060930): "xlwt/excel-formula.g" -> "ExcelFormulaParser.py"$
+ ### import antlr and other modules ..
+-from . import antlr
++import antlr
+ 
+ ### header action >>>
+ import struct
+--- a/xlwt/antlr.py	2017-10-26 12:59:55.750802321 +0000
++++ /dev/null	2017-10-16 21:43:57.398818308 +0000
+@@ -1,2864 +0,0 @@
+-from __future__ import print_function
+-## This file is part of PyANTLR. See LICENSE.txt for license
+-## details..........Copyright (C) Wolfgang Haefelinger, 2004.
+-
+-## This file was copied for use with xlwt from the 2.7.7 ANTLR distribution. Yes, it
+-## says 2.7.5 below. The 2.7.5 distribution version didn't have a
+-## version in it.
+-
+-## Here is the contents of the ANTLR 2.7.7 LICENSE.txt referred to above.
+-
+-# SOFTWARE RIGHTS
+-#
+-# ANTLR 1989-2006 Developed by Terence Parr
+-# Partially supported by University of San Francisco & jGuru.com
+-#
+-# We reserve no legal rights to the ANTLR--it is fully in the
+-# public domain. An individual or company may do whatever
+-# they wish with source code distributed with ANTLR or the
+-# code generated by ANTLR, including the incorporation of
+-# ANTLR, or its output, into commerical software.
+-#
+-# We encourage users to develop software with ANTLR. However,
+-# we do ask that credit is given to us for developing
+-# ANTLR. By "credit", we mean that if you use ANTLR or
+-# incorporate any source code into one of your programs
+-# (commercial product, research project, or otherwise) that
+-# you acknowledge this fact somewhere in the documentation,
+-# research report, etc... If you like ANTLR and have
+-# developed a nice tool with the output, please mention that
+-# you developed it using ANTLR. In addition, we ask that the
+-# headers remain intact in our source code. As long as these
+-# guidelines are kept, we expect to continue enhancing this
+-# system and expect to make other tools available as they are
+-# completed.
+-#
+-# The primary ANTLR guy:
+-#
+-# Terence Parr
+-# parrt at cs.usfca.edu
+-# parrt at antlr.org
+-
+-## End of contents of the ANTLR 2.7.7 LICENSE.txt ########################
+-
+-## get sys module
+-import sys
+-
+-from .compat import long, basestring, int_types, xrange
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                     global symbols                             ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-### ANTLR Standard Tokens
+-SKIP                = -1
+-INVALID_TYPE        = 0
+-EOF_TYPE            = 1
+-EOF                 = 1
+-NULL_TREE_LOOKAHEAD = 3
+-MIN_USER_TYPE       = 4
+-
+-### ANTLR's EOF Symbol
+-EOF_CHAR            = ''
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                    general functions                           ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-## Version should be automatically derived from configure.in. For now,
+-## we need to bump it ourselfs. Don't remove the <version> tags.
+-## <version>
+-def version():
+-    r = {
+-        'major'  : '2',
+-        'minor'  : '7',
+-        'micro'  : '5',
+-        'patch'  : '' ,
+-        'version': '2.7.5'
+-        }
+-    return r
+-## </version>
+-
+-def error(fmt,*args):
+-    if fmt:
+-        print("error: ", fmt % tuple(args))
+-
+-def ifelse(cond,_then,_else):
+-    if cond :
+-        r = _then
+-    else:
+-        r = _else
+-    return r
+-
+-def is_string_type(x):
+-    # return  (isinstance(x,str) or isinstance(x,unicode))
+-    # Simplify; xlwt doesn't support Python < 2.3
+-    return isinstance(basestring)
+-
+-def assert_string_type(x):
+-    assert is_string_type(x)
+-    pass
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                     ANTLR Exceptions                           ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class ANTLRException(Exception):
+-
+-    def __init__(self, *args):
+-        Exception.__init__(self, *args)
+-
+-
+-class RecognitionException(ANTLRException):
+-
+-    def __init__(self, *args):
+-        ANTLRException.__init__(self, *args)
+-        self.fileName = None
+-        self.line = -1
+-        self.column = -1
+-        if len(args) >= 2:
+-            self.fileName = args[1]
+-        if len(args) >= 3:
+-            self.line = args[2]
+-        if len(args) >= 4:
+-            self.column = args[3]
+-
+-    def __str__(self):
+-        buf = ['']
+-        if self.fileName:
+-            buf.append(self.fileName + ":")
+-        if self.line != -1:
+-            if not self.fileName:
+-                buf.append("line ")
+-            buf.append(str(self.line))
+-            if self.column != -1:
+-                buf.append(":" + str(self.column))
+-            buf.append(":")
+-        buf.append(" ")
+-        return str('').join(buf)
+-
+-    __repr__ = __str__
+-
+-
+-class NoViableAltException(RecognitionException):
+-
+-    def __init__(self, *args):
+-        RecognitionException.__init__(self, *args)
+-        self.token = None
+-        self.node  = None
+-        if isinstance(args[0],AST):
+-            self.node = args[0]
+-        elif isinstance(args[0],Token):
+-            self.token = args[0]
+-        else:
+-            raise TypeError("NoViableAltException requires Token or AST argument")
+-
+-    def __str__(self):
+-        if self.token:
+-            line = self.token.getLine()
+-            col  = self.token.getColumn()
+-            text = self.token.getText()
+-            return "unexpected symbol at line %s (column %s): \"%s\"" % (line,col,text)
+-        if self.node == ASTNULL:
+-            return "unexpected end of subtree"
+-        assert self.node
+-        ### hackish, we assume that an AST contains method getText
+-        return "unexpected node: %s" % (self.node.getText())
+-
+-    __repr__ = __str__
+-
+-
+-class NoViableAltForCharException(RecognitionException):
+-
+-    def __init__(self, *args):
+-        self.foundChar = None
+-        if len(args) == 2:
+-            self.foundChar = args[0]
+-            scanner = args[1]
+-            RecognitionException.__init__(self, "NoViableAlt",
+-                                          scanner.getFilename(),
+-                                          scanner.getLine(),
+-                                          scanner.getColumn())
+-        elif len(args) == 4:
+-            self.foundChar = args[0]
+-            fileName = args[1]
+-            line = args[2]
+-            column = args[3]
+-            RecognitionException.__init__(self, "NoViableAlt",
+-                                          fileName, line, column)
+-        else:
+-            RecognitionException.__init__(self, "NoViableAlt",
+-                                          '', -1, -1)
+-
+-    def __str__(self):
+-        mesg = "unexpected char: "
+-        if self.foundChar >= ' ' and self.foundChar <= '~':
+-            mesg += "'" + self.foundChar + "'"
+-        elif self.foundChar:
+-            mesg += "0x" + hex(ord(self.foundChar)).upper()[2:]
+-        else:
+-            mesg += "<None>"
+-        return mesg
+-
+-    __repr__ = __str__
+-
+-
+-class SemanticException(RecognitionException):
+-
+-    def __init__(self, *args):
+-        RecognitionException.__init__(self, *args)
+-
+-
+-class MismatchedCharException(RecognitionException):
+-
+-    NONE = 0
+-    CHAR = 1
+-    NOT_CHAR = 2
+-    RANGE = 3
+-    NOT_RANGE = 4
+-    SET = 5
+-    NOT_SET = 6
+-
+-    def __init__(self, *args):
+-        self.args = args
+-        if len(args) == 5:
+-            # Expected range / not range
+-            if args[3]:
+-                self.mismatchType = MismatchedCharException.NOT_RANGE
+-            else:
+-                self.mismatchType = MismatchedCharException.RANGE
+-            self.foundChar = args[0]
+-            self.expecting = args[1]
+-            self.upper = args[2]
+-            self.scanner = args[4]
+-            RecognitionException.__init__(self, "Mismatched char range",
+-                                          self.scanner.getFilename(),
+-                                          self.scanner.getLine(),
+-                                          self.scanner.getColumn())
+-        elif len(args) == 4 and is_string_type(args[1]):
+-            # Expected char / not char
+-            if args[2]:
+-                self.mismatchType = MismatchedCharException.NOT_CHAR
+-            else:
+-                self.mismatchType = MismatchedCharException.CHAR
+-            self.foundChar = args[0]
+-            self.expecting = args[1]
+-            self.scanner = args[3]
+-            RecognitionException.__init__(self, "Mismatched char",
+-                                          self.scanner.getFilename(),
+-                                          self.scanner.getLine(),
+-                                          self.scanner.getColumn())
+-        elif len(args) == 4 and isinstance(args[1], BitSet):
+-            # Expected BitSet / not BitSet
+-            if args[2]:
+-                self.mismatchType = MismatchedCharException.NOT_SET
+-            else:
+-                self.mismatchType = MismatchedCharException.SET
+-            self.foundChar = args[0]
+-            self.set = args[1]
+-            self.scanner = args[3]
+-            RecognitionException.__init__(self, "Mismatched char set",
+-                                          self.scanner.getFilename(),
+-                                          self.scanner.getLine(),
+-                                          self.scanner.getColumn())
+-        else:
+-            self.mismatchType = MismatchedCharException.NONE
+-            RecognitionException.__init__(self, "Mismatched char")
+-
+-    ## Append a char to the msg buffer.  If special,
+-    #  then show escaped version
+-    #
+-    def appendCharName(self, sb, c):
+-        if not c or c == 65535:
+-            # 65535 = (char) -1 = EOF
+-            sb.append("'<EOF>'")
+-        elif c == '\n':
+-            sb.append("'\\n'")
+-        elif c == '\r':
+-            sb.append("'\\r'");
+-        elif c == '\t':
+-            sb.append("'\\t'")
+-        else:
+-            sb.append('\'' + c + '\'')
+-
+-    ##
+-    # Returns an error message with line number/column information
+-    #
+-    def __str__(self):
+-        sb = ['']
+-        sb.append(RecognitionException.__str__(self))
+-
+-        if self.mismatchType == MismatchedCharException.CHAR:
+-            sb.append("expecting ")
+-            self.appendCharName(sb, self.expecting)
+-            sb.append(", found ")
+-            self.appendCharName(sb, self.foundChar)
+-        elif self.mismatchType == MismatchedCharException.NOT_CHAR:
+-            sb.append("expecting anything but '")
+-            self.appendCharName(sb, self.expecting)
+-            sb.append("'; got it anyway")
+-        elif self.mismatchType in [MismatchedCharException.RANGE, MismatchedCharException.NOT_RANGE]:
+-            sb.append("expecting char ")
+-            if self.mismatchType == MismatchedCharException.NOT_RANGE:
+-                sb.append("NOT ")
+-            sb.append("in range: ")
+-            self.appendCharName(sb, self.expecting)
+-            sb.append("..")
+-            self.appendCharName(sb, self.upper)
+-            sb.append(", found ")
+-            self.appendCharName(sb, self.foundChar)
+-        elif self.mismatchType in [MismatchedCharException.SET, MismatchedCharException.NOT_SET]:
+-            sb.append("expecting ")
+-            if self.mismatchType == MismatchedCharException.NOT_SET:
+-                sb.append("NOT ")
+-            sb.append("one of (")
+-            for i in range(len(self.set)):
+-                self.appendCharName(sb, self.set[i])
+-            sb.append("), found ")
+-            self.appendCharName(sb, self.foundChar)
+-
+-        return str().join(sb).strip()
+-
+-    __repr__ = __str__
+-
+-
+-class MismatchedTokenException(RecognitionException):
+-
+-    NONE = 0
+-    TOKEN = 1
+-    NOT_TOKEN = 2
+-    RANGE = 3
+-    NOT_RANGE = 4
+-    SET = 5
+-    NOT_SET = 6
+-
+-    def __init__(self, *args):
+-        self.args =  args
+-        self.tokenNames = []
+-        self.token = None
+-        self.tokenText = ''
+-        self.node =  None
+-        if len(args) == 6:
+-            # Expected range / not range
+-            if args[3]:
+-                self.mismatchType = MismatchedTokenException.NOT_RANGE
+-            else:
+-                self.mismatchType = MismatchedTokenException.RANGE
+-            self.tokenNames = args[0]
+-            self.expecting = args[2]
+-            self.upper = args[3]
+-            self.fileName = args[5]
+-
+-        elif len(args) == 4 and isinstance(args[2], int):
+-            # Expected token / not token
+-            if args[3]:
+-                self.mismatchType = MismatchedTokenException.NOT_TOKEN
+-            else:
+-                self.mismatchType = MismatchedTokenException.TOKEN
+-            self.tokenNames = args[0]
+-            self.expecting = args[2]
+-
+-        elif len(args) == 4 and isinstance(args[2], BitSet):
+-            # Expected BitSet / not BitSet
+-            if args[3]:
+-                self.mismatchType = MismatchedTokenException.NOT_SET
+-            else:
+-                self.mismatchType = MismatchedTokenException.SET
+-            self.tokenNames = args[0]
+-            self.set = args[2]
+-
+-        else:
+-            self.mismatchType = MismatchedTokenException.NONE
+-            RecognitionException.__init__(self, "Mismatched Token: expecting any AST node", "<AST>", -1, -1)
+-
+-        if len(args) >= 2:
+-            if isinstance(args[1],Token):
+-                self.token = args[1]
+-                self.tokenText = self.token.getText()
+-                RecognitionException.__init__(self, "Mismatched Token",
+-                                              self.fileName,
+-                                              self.token.getLine(),
+-                                              self.token.getColumn())
+-            elif isinstance(args[1],AST):
+-                self.node = args[1]
+-                self.tokenText = str(self.node)
+-                RecognitionException.__init__(self, "Mismatched Token",
+-                                              "<AST>",
+-                                              self.node.getLine(),
+-                                              self.node.getColumn())
+-            else:
+-                self.tokenText = "<empty tree>"
+-                RecognitionException.__init__(self, "Mismatched Token",
+-                                              "<AST>", -1, -1)
+-
+-    def appendTokenName(self, sb, tokenType):
+-        if tokenType == INVALID_TYPE:
+-            sb.append("<Set of tokens>")
+-        elif tokenType < 0 or tokenType >= len(self.tokenNames):
+-            sb.append("<" + str(tokenType) + ">")
+-        else:
+-            sb.append(self.tokenNames[tokenType])
+-
+-    ##
+-    # Returns an error message with line number/column information
+-    #
+-    def __str__(self):
+-        sb = ['']
+-        sb.append(RecognitionException.__str__(self))
+-
+-        if self.mismatchType == MismatchedTokenException.TOKEN:
+-            sb.append("expecting ")
+-            self.appendTokenName(sb, self.expecting)
+-            sb.append(", found " + self.tokenText)
+-        elif self.mismatchType == MismatchedTokenException.NOT_TOKEN:
+-            sb.append("expecting anything but '")
+-            self.appendTokenName(sb, self.expecting)
+-            sb.append("'; got it anyway")
+-        elif self.mismatchType in [MismatchedTokenException.RANGE, MismatchedTokenException.NOT_RANGE]:
+-            sb.append("expecting token ")
+-            if self.mismatchType == MismatchedTokenException.NOT_RANGE:
+-                sb.append("NOT ")
+-            sb.append("in range: ")
+-            self.appendTokenName(sb, self.expecting)
+-            sb.append("..")
+-            self.appendTokenName(sb, self.upper)
+-            sb.append(", found " + self.tokenText)
+-        elif self.mismatchType in [MismatchedTokenException.SET, MismatchedTokenException.NOT_SET]:
+-            sb.append("expecting ")
+-            if self.mismatchType == MismatchedTokenException.NOT_SET:
+-                sb.append("NOT ")
+-            sb.append("one of (")
+-            for i in range(len(self.set)):
+-                self.appendTokenName(sb, self.set[i])
+-            sb.append("), found " + self.tokenText)
+-
+-        return str().join(sb).strip()
+-
+-    __repr__ = __str__
+-
+-
+-class TokenStreamException(ANTLRException):
+-
+-    def __init__(self, *args):
+-        ANTLRException.__init__(self, *args)
+-
+-
+-# Wraps an Exception in a TokenStreamException
+-class TokenStreamIOException(TokenStreamException):
+-
+-    def __init__(self, *args):
+-        if args and isinstance(args[0], Exception):
+-            io = args[0]
+-            TokenStreamException.__init__(self, str(io))
+-            self.io = io
+-        else:
+-            TokenStreamException.__init__(self, *args)
+-            self.io = self
+-
+-
+-# Wraps a RecognitionException in a TokenStreamException
+-class TokenStreamRecognitionException(TokenStreamException):
+-
+-    def __init__(self, *args):
+-        if args and isinstance(args[0], RecognitionException):
+-            recog = args[0]
+-            TokenStreamException.__init__(self, str(recog))
+-            self.recog = recog
+-        else:
+-            raise TypeError("TokenStreamRecognitionException requires RecognitionException argument")
+-
+-    def __str__(self):
+-        return str(self.recog)
+-
+-    __repr__ = __str__
+-
+-
+-class TokenStreamRetryException(TokenStreamException):
+-
+-    def __init__(self, *args):
+-        TokenStreamException.__init__(self, *args)
+-
+-
+-class CharStreamException(ANTLRException):
+-
+-    def __init__(self, *args):
+-        ANTLRException.__init__(self, *args)
+-
+-
+-# Wraps an Exception in a CharStreamException
+-class CharStreamIOException(CharStreamException):
+-
+-    def __init__(self, *args):
+-        if args and isinstance(args[0], Exception):
+-            io = args[0]
+-            CharStreamException.__init__(self, str(io))
+-            self.io = io
+-        else:
+-            CharStreamException.__init__(self, *args)
+-            self.io = self
+-
+-
+-class TryAgain(Exception):
+-    pass
+-
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                       Token                                    ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class Token(object):
+-    SKIP                = -1
+-    INVALID_TYPE        = 0
+-    EOF_TYPE            = 1
+-    EOF                 = 1
+-    NULL_TREE_LOOKAHEAD = 3
+-    MIN_USER_TYPE       = 4
+-
+-    def __init__(self,**argv):
+-        try:
+-            self.type = argv['type']
+-        except:
+-            self.type = INVALID_TYPE
+-        try:
+-            self.text = argv['text']
+-        except:
+-            self.text = "<no text>"
+-
+-    def isEOF(self):
+-        return (self.type == EOF_TYPE)
+-
+-    def getColumn(self):
+-        return 0
+-
+-    def getLine(self):
+-        return 0
+-
+-    def getFilename(self):
+-        return None
+-
+-    def setFilename(self,name):
+-        return self
+-
+-    def getText(self):
+-        return "<no text>"
+-
+-    def setText(self,text):
+-        if is_string_type(text):
+-            pass
+-        else:
+-            raise TypeError("Token.setText requires string argument")
+-        return self
+-
+-    def setColumn(self,column):
+-        return self
+-
+-    def setLine(self,line):
+-        return self
+-
+-    def getType(self):
+-        return self.type
+-
+-    def setType(self,type):
+-        if isinstance(type,int):
+-            self.type = type
+-        else:
+-            raise TypeError("Token.setType requires integer argument")
+-        return self
+-
+-    def toString(self):
+-        ## not optimal
+-        type_ = self.type
+-        if type_ == 3:
+-            tval = 'NULL_TREE_LOOKAHEAD'
+-        elif type_ == 1:
+-            tval = 'EOF_TYPE'
+-        elif type_ == 0:
+-            tval = 'INVALID_TYPE'
+-        elif type_ == -1:
+-            tval = 'SKIP'
+-        else:
+-            tval = type_
+-        return '["%s",<%s>]' % (self.getText(),tval)
+-
+-    __str__ = toString
+-    __repr__ = toString
+-
+-### static attribute ..
+-Token.badToken = Token( type=INVALID_TYPE, text="<no text>")
+-
+-if __name__ == "__main__":
+-    print("testing ..")
+-    T = Token.badToken
+-    print(T)
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                       CommonToken                              ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class CommonToken(Token):
+-
+-    def __init__(self,**argv):
+-        Token.__init__(self,**argv)
+-        self.line = 0
+-        self.col  = 0
+-        try:
+-            self.line = argv['line']
+-        except:
+-            pass
+-        try:
+-            self.col = argv['col']
+-        except:
+-            pass
+-
+-    def getLine(self):
+-        return self.line
+-
+-    def getText(self):
+-        return self.text
+-
+-    def getColumn(self):
+-        return self.col
+-
+-    def setLine(self,line):
+-        self.line = line
+-        return self
+-
+-    def setText(self,text):
+-        self.text = text
+-        return self
+-
+-    def setColumn(self,col):
+-        self.col = col
+-        return self
+-
+-    def toString(self):
+-        ## not optimal
+-        type_ = self.type
+-        if type_ == 3:
+-            tval = 'NULL_TREE_LOOKAHEAD'
+-        elif type_ == 1:
+-            tval = 'EOF_TYPE'
+-        elif type_ == 0:
+-            tval = 'INVALID_TYPE'
+-        elif type_ == -1:
+-            tval = 'SKIP'
+-        else:
+-            tval = type_
+-        d = {
+-           'text' : self.text,
+-           'type' : tval,
+-           'line' : self.line,
+-           'colm' : self.col
+-           }
+-
+-        fmt = '["%(text)s",<%(type)s>,line=%(line)s,col=%(colm)s]'
+-        return fmt % d
+-
+-    __str__ = toString
+-    __repr__ = toString
+-
+-
+-if __name__ == '__main__' :
+-    T = CommonToken()
+-    print(T)
+-    T = CommonToken(col=15,line=1,text="some text", type=5)
+-    print(T)
+-    T = CommonToken()
+-    T.setLine(1).setColumn(15).setText("some text").setType(5)
+-    print(T)
+-    print(T.getLine())
+-    print(T.getColumn())
+-    print(T.getText())
+-    print(T.getType())
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                    CommonHiddenStreamToken                     ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class CommonHiddenStreamToken(CommonToken):
+-    def __init__(self,*args):
+-        CommonToken.__init__(self,*args)
+-        self.hiddenBefore = None
+-        self.hiddenAfter  = None
+-
+-    def getHiddenAfter(self):
+-        return self.hiddenAfter
+-
+-    def getHiddenBefore(self):
+-        return self.hiddenBefore
+-
+-    def setHiddenAfter(self,t):
+-        self.hiddenAfter = t
+-
+-    def setHiddenBefore(self, t):
+-        self.hiddenBefore = t
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                       Queue                                    ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-## Shall be a circular buffer on tokens ..
+-class Queue(object):
+-
+-    def __init__(self):
+-        self.buffer = [] # empty list
+-
+-    def append(self,item):
+-        self.buffer.append(item)
+-
+-    def elementAt(self,index):
+-        return self.buffer[index]
+-
+-    def reset(self):
+-        self.buffer = []
+-
+-    def removeFirst(self):
+-        self.buffer.pop(0)
+-
+-    def length(self):
+-        return len(self.buffer)
+-
+-    def __str__(self):
+-        return str(self.buffer)
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                       InputBuffer                              ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class InputBuffer(object):
+-    def __init__(self):
+-        self.nMarkers = 0
+-        self.markerOffset = 0
+-        self.numToConsume = 0
+-        self.queue = Queue()
+-
+-    def __str__(self):
+-        return "(%s,%s,%s,%s)" % (
+-           self.nMarkers,
+-           self.markerOffset,
+-           self.numToConsume,
+-           self.queue)
+-
+-    def __repr__(self):
+-        return str(self)
+-
+-    def commit(self):
+-        self.nMarkers -= 1
+-
+-    def consume(self) :
+-        self.numToConsume += 1
+-
+-    ## probably better to return a list of items
+-    ## because of unicode. Or return a unicode
+-    ## string ..
+-    def getLAChars(self) :
+-        i = self.markerOffset
+-        n = self.queue.length()
+-        s = ''
+-        while i<n:
+-            s += self.queue.elementAt(i)
+-        return s
+-
+-    ## probably better to return a list of items
+-    ## because of unicode chars
+-    def getMarkedChars(self) :
+-        s = ''
+-        i = 0
+-        n = self.markerOffset
+-        while i<n:
+-            s += self.queue.elementAt(i)
+-        return s
+-
+-    def isMarked(self) :
+-        return self.nMarkers != 0
+-
+-    def fill(self,k):
+-        ### abstract method
+-        raise NotImplementedError()
+-
+-    def LA(self,k) :
+-        self.fill(k)
+-        return self.queue.elementAt(self.markerOffset + k - 1)
+-
+-    def mark(self) :
+-        self.syncConsume()
+-        self.nMarkers += 1
+-        return self.markerOffset
+-
+-    def rewind(self,mark) :
+-        self.syncConsume()
+-        self.markerOffset = mark
+-        self.nMarkers -= 1
+-
+-    def reset(self) :
+-        self.nMarkers = 0
+-        self.markerOffset = 0
+-        self.numToConsume = 0
+-        self.queue.reset()
+-
+-    def syncConsume(self) :
+-        while self.numToConsume > 0:
+-            if self.nMarkers > 0:
+-                # guess mode -- leave leading characters and bump offset.
+-                self.markerOffset += 1
+-            else:
+-                # normal mode -- remove first character
+-                self.queue.removeFirst()
+-            self.numToConsume -= 1
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                       CharBuffer                               ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class CharBuffer(InputBuffer):
+-    def __init__(self,reader):
+-        ##assert isinstance(reader,file)
+-        super(CharBuffer,self).__init__()
+-        ## a reader is supposed to be anything that has
+-        ## a method 'read(int)'.
+-        self.input = reader
+-
+-    def __str__(self):
+-        base = super(CharBuffer,self).__str__()
+-        return "CharBuffer{%s,%s" % (base,str(input))
+-
+-    def fill(self,amount):
+-        try:
+-            self.syncConsume()
+-            while self.queue.length() < (amount + self.markerOffset) :
+-                ## retrieve just one char - what happend at end
+-                ## of input?
+-                c = self.input.read(1)
+-                ### python's behaviour is to return the empty string  on
+-                ### EOF, ie. no exception whatsoever is thrown. An empty
+-                ### python  string  has  the  nice feature that it is of
+-                ### type 'str' and  "not ''" would return true. Contrary,
+-                ### one can't  do  this: '' in 'abc'. This should return
+-                ### false,  but all we  get  is  then  a TypeError as an
+-                ### empty string is not a character.
+-
+-                ### Let's assure then that we have either seen a
+-                ### character or an empty string (EOF).
+-                assert len(c) == 0 or len(c) == 1
+-
+-                ### And it shall be of type string (ASCII or UNICODE).
+-                assert is_string_type(c)
+-
+-                ### Just append EOF char to buffer. Note that buffer may
+-                ### contain then just more than one EOF char ..
+-
+-                ### use unicode chars instead of ASCII ..
+-                self.queue.append(c)
+-        except Exception as e:
+-            raise CharStreamIOException(e)
+-        ##except: # (mk) Cannot happen ...
+-            ##error ("unexpected exception caught ..")
+-            ##assert 0
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                       LexerSharedInputState                    ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class LexerSharedInputState(object):
+-    def __init__(self,ibuf):
+-        assert isinstance(ibuf,InputBuffer)
+-        self.input = ibuf
+-        self.column = 1
+-        self.line = 1
+-        self.tokenStartColumn = 1
+-        self.tokenStartLine = 1
+-        self.guessing = 0
+-        self.filename = None
+-
+-    def reset(self):
+-        self.column = 1
+-        self.line = 1
+-        self.tokenStartColumn = 1
+-        self.tokenStartLine = 1
+-        self.guessing = 0
+-        self.filename = None
+-        self.input.reset()
+-
+-    def LA(self,k):
+-        return self.input.LA(k)
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                    TokenStream                                 ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class TokenStream(object):
+-    def nextToken(self):
+-        pass
+-
+-    def __iter__(self):
+-        return TokenStreamIterator(self)
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                    TokenStreamIterator                                 ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class TokenStreamIterator(object):
+-    def __init__(self,inst):
+-        if isinstance(inst,TokenStream):
+-            self.inst = inst
+-            return
+-        raise TypeError("TokenStreamIterator requires TokenStream object")
+-
+-    def next(self):
+-        assert self.inst
+-        item = self.inst.nextToken()
+-        if not item or item.isEOF():
+-            raise StopIteration()
+-        return item
+-
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-###                    TokenStreamSelector                        ###
+-###xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx###
+-
+-class TokenStreamSelector(TokenStream):
+-
+-    def __init__(self):
+-        self._input = None
+-        self._stmap = {}
+-        self._stack = []
+-
+-    def addInputStream(self,stream,key):
+-        self._stmap[key] = stream
+-
+-    def getCurrentStream(self):
+-        return self._input
+-
+-    def getStream(self,sname):
+-        try:
+-            stream = self._stmap[sname]
+-        except:
+-            raise ValueError("TokenStream " + sname + " not found");
+-        return stream;
+-
+-    def nextToken(self):
+-        while 1:
+-            try:
+-                return self._input.nextToken()
+-            except TokenStreamRetryException:
+-                ### just retry "forever"
+-                pass
+-
+-    def pop(self):
+-        stream = self._stack.pop();
+-        self.select(stream);
+-        return stream;
+-
+-    def push(self,arg):
+-        self._stack.append(self._input);
... 1919 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/xlwt.git



More information about the Python-modules-commits mailing list