def testParseNodeShould(self): "test ParseNode should allow registering of node classes" class CustomParseNode(ParseNode): def __init__(self, children): ParseNode.__init__(self, "CUSTOM_NODE_TYPE", children) ParseNode.register_node_type("CUSTOM_NODE_TYPE", CustomParseNode) try: node = ParseNode.construct_node("CUSTOM_NODE_TYPE", []) self.assertEquals( type(node), CustomParseNode, "ParseNode.construct_node didn't dispatch to CustomParseNode") self.assertEquals(node.type, "CUSTOM_NODE_TYPE", "Wrong type attribute") self.assertEquals(node.children, [], "Wrong children") node = ParseNode.construct_node("FISH BOWL", ["gox blamp"]) self.assertEquals( type(node), ParseNode, "ParseNode.construct_node didn't fall back to ParseNode") self.assertEquals(node.type, "FISH BOWL", "Wrong type attribute") self.assertEquals(node.children, ["gox blamp"], "Wrong children") self.assertIsNotNone(ParseNode.classRegistry, "ParseNode didn't have a class registry") finally: del ParseNode.classRegistry["CUSTOM_NODE_TYPE"]
def testParseNodeShould(self): "test ParseNode should allow registering of node classes" class CustomParseNode(ParseNode): def __init__(self, children): ParseNode.__init__(self, "CUSTOM_NODE_TYPE", children) ParseNode.register_node_type("CUSTOM_NODE_TYPE", CustomParseNode) try: node = ParseNode.construct_node("CUSTOM_NODE_TYPE", []) self.assertEquals(type(node), CustomParseNode, "ParseNode.construct_node didn't dispatch to CustomParseNode") self.assertEquals(node.type, "CUSTOM_NODE_TYPE", "Wrong type attribute") self.assertEquals(node.children, [], "Wrong children") node = ParseNode.construct_node("FISH BOWL", ["gox blamp"]) self.assertEquals(type(node), ParseNode, "ParseNode.construct_node didn't fall back to ParseNode") self.assertEquals(node.type, "FISH BOWL", "Wrong type attribute") self.assertEquals(node.children, ["gox blamp"], "Wrong children") self.assertIsNotNone(ParseNode.classRegistry, "ParseNode didn't have a class registry") finally: del ParseNode.classRegistry["CUSTOM_NODE_TYPE"]
def colIndex(self): return column_name_to_index(self.plainColumnName) @property def coords(self): return self.colIndex, 0 def offset(self, count, _, moveAbsolute=False): if not moveAbsolute and self.isAbsolute: return newName = column_index_to_name(self.colIndex + count) if newName: self.plainColumnName = newName else: self.localReference = '#Invalid!' + self.whitespace def __getLocalReference(self): return self.children[-1] def __setLocalReference(self, newCol): self.children[-1] = newCol localReference = property(__getLocalReference, __setLocalReference) def canonicalise(self, wsNames): self.localReference = self.localReference.upper() FLReferenceParseNode.canonicalise(self, wsNames) ParseNode.register_node_type(ParseNode.FL_COLUMN_REFERENCE, FLColumnReferenceParseNode)
# from dirigible.sheet.parser.parse_node import ParseNode class FLCellRangeParseNode(ParseNode): def __init__(self, children): assert len(children) == 3 ParseNode.__init__(self, ParseNode.FL_CELL_RANGE, children) def __get_first_cell_reference(self): return self.children[0] def __set_first_cell_reference(self, cellRef): self.children[0] = cellRef first_cell_reference = property(__get_first_cell_reference, __set_first_cell_reference) def __get_second_cell_reference(self): return self.children[2] def __set_second_cell_reference(self, cellRef): self.children[2] = cellRef second_cell_reference = property(__get_second_cell_reference, __set_second_cell_reference) @property def colon(self): return self.children[1] ParseNode.register_node_type(ParseNode.FL_CELL_RANGE, FLCellRangeParseNode)
localReference = property(__getLocalReference, __setLocalReference) @property def coords(self): return cell_name_to_coordinates(self.plainCellName) def offset(self, dx, dy, move_absolute=False): (col, row) = cell_name_to_coordinates(self.plainCellName) if move_absolute or not self.colAbsolute: col += dx if move_absolute or not self.rowAbsolute: row += dy newName = coordinates_to_cell_name(col, row, colAbsolute=self.colAbsolute, rowAbsolute=self.rowAbsolute) if newName is None: newName = "#Invalid!" self.localReference = newName + self.whitespace def canonicalise(self, wsNames): self.localReference = self.localReference.upper() FLReferenceParseNode.canonicalise(self, wsNames) ParseNode.register_node_type(ParseNode.FL_CELL_REFERENCE, FLCellReferenceParseNode)
localReference = property(__getLocalReference, __setLocalReference) @property def coords(self): return cell_name_to_coordinates(self.plainCellName) def offset(self, dx, dy, move_absolute=False): (col, row) = cell_name_to_coordinates(self.plainCellName) if move_absolute or not self.colAbsolute: col += dx if move_absolute or not self.rowAbsolute: row += dy newName = coordinates_to_cell_name(col, row, colAbsolute=self.colAbsolute, rowAbsolute=self.rowAbsolute) if newName is None: newName = "#Invalid!" self.localReference = newName + self.whitespace def canonicalise(self, wsNames): self.localReference = self.localReference.upper() FLReferenceParseNode.canonicalise(self, wsNames) ParseNode.register_node_type(ParseNode.FL_CELL_REFERENCE, FLCellReferenceParseNode)
@property def rowIndex(self): return int(self.plainRowName) @property def coords(self): return 0, self.rowIndex def offset(self, _, count, moveAbsolute=False): if not moveAbsolute and self.isAbsolute: return newIndex = self.rowIndex + count if newIndex > 0: self.plainRowName = str(newIndex) else: self.localReference = '#Invalid!' + self.whitespace def __getLocalReference(self): return self.children[-1] def __setLocalReference(self, newRow): self.children[-1] = newRow localReference = property(__getLocalReference, __setLocalReference) ParseNode.register_node_type(ParseNode.FL_ROW_REFERENCE, FLRowReferenceParseNode)
plainRowName = property(__getPlainRowName, __setPlainRowName) @property def rowIndex(self): return int(self.plainRowName) @property def coords(self): return 0, self.rowIndex def offset(self, _, count, moveAbsolute=False): if not moveAbsolute and self.isAbsolute: return newIndex = self.rowIndex + count if newIndex > 0: self.plainRowName = str(newIndex) else: self.localReference = '#Invalid!' + self.whitespace def __getLocalReference(self): return self.children[-1] def __setLocalReference(self, newRow): self.children[-1] = newRow localReference = property(__getLocalReference, __setLocalReference) ParseNode.register_node_type(ParseNode.FL_ROW_REFERENCE, FLRowReferenceParseNode)
# Copyright (c) 2005-2009 Resolver Systems Ltd, PythonAnywhere LLP # See LICENSE.md # from dirigible.sheet.parser.parse_node import ParseNode from dirigible.sheet.parser.fl_reference_parse_node import FLReferenceParseNode class FLNamedColumnReferenceParseNode(FLReferenceParseNode): def __init__(self, children): FLReferenceParseNode.__init__(self, ParseNode.FL_NAMED_COLUMN_REFERENCE, children) @property def header(self): return self.children[-1].rstrip().replace("##", "#")[1:-2] ParseNode.register_node_type(ParseNode.FL_NAMED_COLUMN_REFERENCE, FLNamedColumnReferenceParseNode)
class FLCellRangeParseNode(ParseNode): def __init__(self, children): assert len(children) == 3 ParseNode.__init__(self, ParseNode.FL_CELL_RANGE, children) def __get_first_cell_reference(self): return self.children[0] def __set_first_cell_reference(self, cellRef): self.children[0] = cellRef first_cell_reference = property(__get_first_cell_reference, __set_first_cell_reference) def __get_second_cell_reference(self): return self.children[2] def __set_second_cell_reference(self, cellRef): self.children[2] = cellRef second_cell_reference = property(__get_second_cell_reference, __set_second_cell_reference) @property def colon(self): return self.children[1] ParseNode.register_node_type(ParseNode.FL_CELL_RANGE, FLCellRangeParseNode)
# Copyright (c) 2005-2009 Resolver Systems Ltd, PythonAnywhere LLP # See LICENSE.md # from dirigible.sheet.parser.parse_node import ParseNode from dirigible.sheet.parser.fl_reference_parse_node import FLReferenceParseNode class FLNamedRowReferenceParseNode(FLReferenceParseNode): def __init__(self, children): FLReferenceParseNode.__init__(self, ParseNode.FL_NAMED_ROW_REFERENCE, children) @property def header(self): return self.children[-1].rstrip().replace("##", "#")[2:-1] ParseNode.register_node_type(ParseNode.FL_NAMED_ROW_REFERENCE, FLNamedRowReferenceParseNode)
# Copyright (c) 2005-2009 Resolver Systems Ltd, PythonAnywhere LLP # See LICENSE.md # from dirigible.sheet.parser.parse_node import ParseNode from dirigible.sheet.parser.fl_reference_parse_node import FLReferenceParseNode class FLNamedColumnReferenceParseNode(FLReferenceParseNode): def __init__(self, children): FLReferenceParseNode.__init__(self, ParseNode.FL_NAMED_COLUMN_REFERENCE, children) @property def header(self): return self.children[-1].rstrip().replace("##", "#")[1:-2] ParseNode.register_node_type(ParseNode.FL_NAMED_COLUMN_REFERENCE, FLNamedColumnReferenceParseNode)
# Copyright (c) 2005-2009 Resolver Systems Ltd, PythonAnywhere LLP # See LICENSE.md # from dirigible.sheet.parser.parse_node import ParseNode from dirigible.sheet.parser.fl_reference_parse_node import FLReferenceParseNode class FLNamedRowReferenceParseNode(FLReferenceParseNode): def __init__(self, children): FLReferenceParseNode.__init__(self, ParseNode.FL_NAMED_ROW_REFERENCE, children) @property def header(self): return self.children[-1].rstrip().replace("##", "#")[2:-1] ParseNode.register_node_type(ParseNode.FL_NAMED_ROW_REFERENCE, FLNamedRowReferenceParseNode)