def __init__(self, ctx, line, name, level): super(ParserRule, self).__init__() #: Level of the rule in the kv self.level = level #: Associated parser self.ctx = ctx #: Line of the rule self.line = line #: Name of the rule self.name = name #: List of children to create self.children = [] #: Id given to the rule self.id = None #: Properties associated to the rule self.properties = OrderedDict() #: Canvas normal self.canvas_root = None #: Canvas before self.canvas_before = None #: Canvas after self.canvas_after = None #: Handlers associated to the rule self.handlers = [] #: Properties cache list: mark which class have already been checked self.cache_marked = [] if level == 0: self._detect_selectors() else: self._forbid_selectors()
def __init__(self): PythonConfigParser.__init__(self) self._sections = OrderedDict() self.filename = None self._callbacks = []
def __init__(self): ConfigParser.__init__(self) self._sections = OrderedDict()
def parse_level(self, level, lines): '''Parse the current level (level * 4) indentation ''' indent = 4 * level objects = [] current_object = None current_property = None i = 0 while i < len(lines): line = lines[i] ln, content = line # Get the number of space tmp = content.lstrip(' \t') # Replace any tab with 4 spaces tmp = content[:len(content) - len(tmp)] tmp = tmp.replace('\t', ' ') count = len(tmp) if count % 4 != 0: raise ParserError( self, ln, 'Invalid indentation, must be a multiple of 4') content = content.strip() # Level finished if count < indent: return objects, lines[i - 1:] # Current level, create an object elif count == indent: current_object = OrderedDict() current_object['__line__'] = ln current_object['__ctx__'] = self current_property = None x = content.split(':', 1) if not len(x[0]): raise ParserError(self, ln, 'Identifier missing') if len(x) == 2 and len(x[1]): raise ParserError(self, ln, 'Invalid data after declaration') objects.append((x[0], current_object)) # Next level, is it a property or an object ? elif count == indent + 4: x = content.split(':', 1) if not len(x[0]): raise ParserError(self, ln, 'Identifier missing') # It's a class, add to the current object as a children current_property = None name = x[0] if ord(name[0]) in Parser.CLASS_RANGE or name[0] == '+': _objects, _lines = self.parse_level(level + 1, lines[i:]) current_object['children'] = (_objects, ln, self) lines = _lines i = 0 # It's a property else: if len(x) == 1: raise ParserError(self, ln, 'Syntax error') value = x[1].strip() if len(value): current_object[name] = (value, ln, self) else: current_property = name # Two more level ? elif count == indent + 8: if current_property not in ('canvas', 'canvas.after', 'canvas.before'): raise ParserError( self, ln, 'Invalid indentation, only allowed ' 'for canvas') _objects, _lines = self.parse_level(level + 2, lines[i:]) current_object[current_property] = (_objects, ln, self) current_property = None lines = _lines i = 0 # Too much indent, invalid else: raise ParserError(self, ln, 'Invalid indentation (too much level)') # Check the next line i += 1 return objects, []