def selectorPartName(value, position): """A name of a class.""" if value[0] == '_' and value[1].islower(): return Error('PrivateSelectorInHeader', 'Selectors starting with _ can not be in header files', position, LINES) if not value[0].islower(): return Error('BadSelectorPartName', 'Selector names must not be capitalized', position, LINES) return None
def cb(value, pos): """The callback for the rule.""" count = len(value) if expectedCount > count: return Error('MissingSpace', 'Expected %d, got %d' % (expectedCount, count), pos, LINES) elif expectedCount < count: return Error('ExtraSpace', 'Expected %d, got %d' % (expectedCount, count), pos, LINES)
def localVarName(value, position): """A name of a class.""" if not value[0].islower(): return Error('BadLocalVariableName', 'Local variable must start with a lower case letter', position, LINES) return None
def namespaceName(value, position): """A name of a namespace.""" if not value[0].islower(): return Error('BadNamespaceName', 'Namespace name must start with a lower case letter', position, LINES) return None
def parameterName(value, position): """A name of a class.""" if not value[0].islower(): return Error('BadParameterName', 'Parameter names must not be capitalized', position, LINES) return None
def ivarName(value, position): """A name of a class.""" if not value[0] == '_' or not value[1].islower(): return Error( 'BadInstanceVariableName', 'Instance variable names start with _ and not be capitalized', position, LINES) return None
def shouldBeSemicolonAndNewline(result, pos): """A place where there should a semicolon, but compiler-wise it is optional.""" errors = [] if result: if isinstance(result, Error): errors.append(result) result = None else: errors.extend([e for e in result if isinstance(e, Error)]) if not result: errors.append(Error('MissingSemicolon', 'Expected a semicolon', pos, LINES)) return errors or None
def setupLines(content, maxLineLength): """Setup line position data.""" LINES[:] = [] pos = -1 LINES.append(0) while True: pos = content.find('\n', pos + 1) if pos == -1: break LINES.append(pos) errors = [] for lineNo in range(1, len(LINES)): lineLength = LINES[lineNo] - LINES[lineNo - 1] - 1 # Remove the \n character. if lineLength > maxLineLength: errors.append(Error( 'LineTooLong', 'Line too long: %d chars over the %d limit' % (lineLength, maxLineLength), LINES[lineNo], LINES)) return errors
def shouldBeNewline(result, pos): """Expect a newline here.""" if not isinstance(result, tuple): return Error('MissingNewline', 'Should have newline after ;', pos, LINES)
def propertyName(value, position): """Checks a property name.""" if not value[0].islower(): return Error('BadPropertyName', 'Property names must not be capitalized', position, LINES) return None
def sizedCType(value, position): """A type modifier.""" for m in re.compile(r'\s\s+').finditer(value): return Error('ExtraSpace', 'Extra space in type name', position + m.start(), LINES) return None
def className(value, position): """A name of a class.""" if not value[0].isupper(): return Error('BadClassName', 'Class names must be capitalized', position, LINES) return None
def docComment(value, pos): """A doc comment.""" value = value.lstrip() stripped = value.lstrip('/').lstrip('*') if stripped and stripped[0] not in (' ', '\n'): return Error('MissingSpace', 'Should have space after /*', pos, LINES)
def lineComment(value, pos): """A line comment.""" value = value.lstrip() if len(value) > 2 and value[2] != ' ': return Error('MissingSpace', 'Should have space after //', pos, LINES)
def expectedHandler(kind, message, value, pos): """Handle a syntactically but not stylistically optional token.""" if not value: return Error(kind, message, pos, LINES)
def unexpectedHandler(kind, value, pos): """Handle a syntactically but not stylistically valid token.""" return Error(kind, 'Did not expect %r here' % value, pos, LINES)