def t_UPPERCASE_IDENTIFIER(self, t): r'[A-Z][-a-zA-z0-9]*' if t.value in self.forbidden_words: raise error.PySmiLexerError("%s is forbidden" % t.value, lineno=t.lineno) if t.value[-1] == '-': raise error.PySmiLexerError( "Identifier should not end with '-': %s" % t.value, lineno=t.lineno) t.type = self.reserved.get(t.value, 'UPPERCASE_IDENTIFIER') return t
def t_LOWERCASE_IDENTIFIER(self, t): r'[a-z][-a-zA-z0-9]*' if t.value[-1] == '-': raise error.PySmiLexerError( "Identifier should not end with '-': %s" % t.value, lineno=t.lineno) return t
def t_NUMBER(self, t): r'-?[0-9]+' t.value = int(t.value) neg = 0 if t.value < 0: neg = 1 val = abs(t.value) if val <= UNSIGNED32_MAX: if neg: t.type = 'NEGATIVENUMBER' elif val <= UNSIGNED64_MAX: if neg: t.type = 'NEGATIVENUMBER64' else: t.type = 'NUMBER64' else: raise error.PySmiLexerError("Number %s is too big" % t.value, lineno=t.lineno) return t
def t_error(self, t): raise error.PySmiLexerError( "Illegal character '%s', %s characters left unparsed at this stage" % (t.value[0], len(t.value) - 1), lineno=t.lineno)