[Libreoffice-commits] .: 3 commits - src/formula.py src/xlsrecord.py
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu Apr 14 10:57:10 PDT 2011
src/formula.py | 49 ++++++++++++++++++++++++++++++++++++-------------
src/xlsrecord.py | 7 +++++--
2 files changed, 41 insertions(+), 15 deletions(-)
New commits:
commit f7297f738e736c0ad0d76f48baa55aa35baedc7a
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Apr 14 13:55:37 2011 -0400
Improved parsing of function tokens.
diff --git a/src/formula.py b/src/formula.py
index 440aec0..f5572b3 100644
--- a/src/formula.py
+++ b/src/formula.py
@@ -209,7 +209,7 @@ class PtgRef3d(PtgBase):
def getText (self):
return "(xti=%d,%s)"%(self.ixti, self.cell.getName())
-class _FuncVar(PtgBase):
+class PtgFuncVar(PtgBase):
funcTab = {
0x0000: 'COUNT',
@@ -597,17 +597,13 @@ class _FuncVar(PtgBase):
def getText (self):
if self.isCeTab:
# I'll support this later.
- return ''
+ raise FormulaParserError("special built-in function not supported yet")
- if not _FuncVar.funcTab.has_key(self.funcType):
+ if not PtgFuncVar.funcTab.has_key(self.funcType):
# unknown function name
return '#NAME!'
- if self.argCount > 0:
- # I'll support functions with arguments later.
- return ''
-
- return _FuncVar.funcTab[self.funcType] + "()"
+ return "(func: %s; arg: %d)"%(PtgFuncVar.funcTab[self.funcType], self.argCount)
_tokenMap = {
0x01: PtgExp,
@@ -621,7 +617,7 @@ _tokenMap = {
0x7B: _Area3d,
0x3A: PtgRef3d,
- 0x42: _FuncVar
+ 0x42: PtgFuncVar
}
class FormulaParser(object):
commit 0f888e5c6a676e786c601603cf734afd214bd70f
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Apr 14 13:48:33 2011 -0400
Pick up more formula token types.
diff --git a/src/formula.py b/src/formula.py
index 1b18978..440aec0 100644
--- a/src/formula.py
+++ b/src/formula.py
@@ -151,6 +151,29 @@ class PtgExp(PtgBase):
def getText (self):
return "(ptgexp: row=%d, col=%d)"%(self.row, self.col)
+class PtgMissArg(PtgBase):
+ def parseBytes (self):
+ pass
+
+ def getText (self):
+ return '(arg missing)'
+
+class PtgRef(PtgBase):
+ def parseBytes (self):
+ self.row = self.strm.readUnsignedInt(2)
+ self.col = self.strm.readUnsignedInt(2)
+
+ def getText (self):
+ return "(ref: row=%d, col=%d)"%(self.row, self.col)
+
+class PtgStr(PtgBase):
+ def parseBytes (self):
+ length = self.strm.readUnsignedInt(1)
+ self.value = self.strm.readUnicodeString(length)
+
+ def getText (self):
+ return "(str: '%s')"%self.value
+
class PtgNameX(PtgBase):
def parseBytes (self):
self.xti = self.strm.readUnsignedInt(2)
@@ -159,12 +182,12 @@ class PtgNameX(PtgBase):
def getText (self):
return "(name: xti=%d, name=%d)"%(self.xti, self.nameID)
-class _Int(PtgBase):
+class PtgInt(PtgBase):
def parseBytes (self):
self.value = self.strm.readUnsignedInt(2)
def getText (self):
- return "%d"%self.value
+ return "(int: %d)"%self.value
class _Area3d(PtgBase):
def parseBytes (self):
@@ -588,7 +611,10 @@ class _FuncVar(PtgBase):
_tokenMap = {
0x01: PtgExp,
- 0x1E: _Int,
+ 0x16: PtgMissArg,
+ 0x17: PtgStr,
+ 0x1E: PtgInt,
+ 0x24: PtgRef,
0x3B: _Area3d,
0x59: PtgNameX,
0x5B: _Area3d,
commit 63edbb942b1678bbb08ebdf34cc20ff0b0205403
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Apr 14 13:28:05 2011 -0400
Catch unknown token error from the formula parser.
diff --git a/src/formula.py b/src/formula.py
index 76000ff..1b18978 100644
--- a/src/formula.py
+++ b/src/formula.py
@@ -29,6 +29,7 @@ import struct, sys
import globals
class InvalidCellAddress(Exception): pass
+class FormulaParserError(Exception): pass
def toColName (colID):
if colID > 255:
@@ -614,7 +615,7 @@ associated token classes will be without the leading underscore (_)."""
b = self.strm.readUnsignedInt(1)
if not _tokenMap.has_key(b):
# Unknown token. Stop parsing.
- return
+ raise FormulaParserError("unknown token 0x%2.2X"%b)
token = _tokenMap[b](self.strm, b)
token.parse()
diff --git a/src/xlsrecord.py b/src/xlsrecord.py
index a860af3..3704c8f 100644
--- a/src/xlsrecord.py
+++ b/src/xlsrecord.py
@@ -949,8 +949,11 @@ class Formula(BaseRecordHandler):
def parseBytes (self):
self.__parseBytes()
fparser = formula.FormulaParser(self.header, self.tokens)
- fparser.parse()
- ftext = fparser.getText()
+ try:
+ fparser.parse()
+ ftext = fparser.getText()
+ except formula.FormulaParserError as e:
+ ftext = "(Error: %s)"%e.args[0]
self.appendCellPosition(self.col, self.row)
self.appendLine("XF record ID: %d"%self.xf)
More information about the Libreoffice-commits
mailing list