Esempio n. 1
0
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
Esempio n. 2
0
 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)
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
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
Esempio n. 9
0
def shouldBeNewline(result, pos):
  """Expect a newline here."""
  if not isinstance(result, tuple):
    return Error('MissingNewline', 'Should have newline after ;', pos, LINES)
Esempio n. 10
0
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
Esempio n. 11
0
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
Esempio n. 12
0
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
Esempio n. 13
0
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)
Esempio n. 14
0
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)
Esempio n. 15
0
def expectedHandler(kind, message, value, pos):
  """Handle a syntactically but not stylistically optional token."""
  if not value:
    return Error(kind, message, pos, LINES)
Esempio n. 16
0
def unexpectedHandler(kind, value, pos):
  """Handle a syntactically but not stylistically valid token."""
  return Error(kind, 'Did not expect %r here' % value, pos, LINES)