def test_get_lstripped_part(self): self.assertEquals(get_lstripped_part(" foo"), " ", "get_l_stripped_part broken") self.assertEquals(get_lstripped_part("foo "), "", "get_l_stripped_part broken") self.assertEquals(get_lstripped_part(" foo "), " ", "get_l_stripped_part broken") self.assertEquals(get_lstripped_part(""), "", "get_l_stripped_part broken")
def p_fl_naked_worksheet_reference(p): """fl_naked_worksheet_reference : LESSTHAN NAME GREATERTHAN | LESSTHAN FLCELLREFLIKENAME GREATERTHAN | FLNAKEDWORKSHEETREFERENCE""" if len(p) == 2: name, greaterThanWhitespace = p[1].rsplit(">", 1) greaterThan = ">" + greaterThanWhitespace lessThanWhitespace = get_lstripped_part(name[1:]) lessThan = "<" + lessThanWhitespace name = name[1:].lstrip() p[0] = FLNakedWorksheetReference([lessThan, name, greaterThan]) else: p[0] = FLNakedWorksheetReference([p[1], p[2], p[3]])
def _interpretHorribleFLReferenceMess(p, simpleInterpreter): # this is used to deal with the half-dozen ways that valid cell, col, or row references may have been tokenised p_1 = p[1] if len(p) == 2: if '!' not in p_1: #simple reference p[0] = simpleInterpreter(p_1, []) or Atom([Name([p_1])]) return else: worksheetName, cellName = p_1.rsplit('!', 1) exclamationMark = '!' + get_lstripped_part(cellName) cellName = cellName.lstrip() else: worksheetName = GetWorksheetNameFromPotentialNakedWorksheetReference(p_1) exclamationMark = p[2] cellName = p[3] result = simpleInterpreter(cellName, [worksheetName, exclamationMark]) if result is None: raise FormulaError("Error in formula at position %d: unexpected '%s'" % (p.lexer.lexpos - len(cellName) - 1, cellName)) else: p[0] = result
def _interpretHorribleFLReferenceMess(p, simpleInterpreter): # this is used to deal with the half-dozen ways that valid cell, col, or row references may have been tokenised p_1 = p[1] if len(p) == 2: if '!' not in p_1: #simple reference p[0] = simpleInterpreter(p_1, []) or Atom([Name([p_1])]) return else: worksheetName, cellName = p_1.rsplit('!', 1) exclamationMark = '!' + get_lstripped_part(cellName) cellName = cellName.lstrip() else: worksheetName = GetWorksheetNameFromPotentialNakedWorksheetReference( p_1) exclamationMark = p[2] cellName = p[3] result = simpleInterpreter(cellName, [worksheetName, exclamationMark]) if result is None: raise FormulaError("Error in formula at position %d: unexpected '%s'" % (p.lexer.lexpos - len(cellName) - 1, cellName)) else: p[0] = result