You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tokens.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2009-2018 the sqlparse authors and contributors
  4. # <see AUTHORS file>
  5. #
  6. # This module is part of python-sqlparse and is released under
  7. # the BSD License: https://opensource.org/licenses/BSD-3-Clause
  8. #
  9. # The Token implementation is based on pygment's token system written
  10. # by Georg Brandl.
  11. # http://pygments.org/
  12. """Tokens"""
  13. class _TokenType(tuple):
  14. parent = None
  15. def __contains__(self, item):
  16. return item is not None and (self is item or item[:len(self)] == self)
  17. def __getattr__(self, name):
  18. new = _TokenType(self + (name,))
  19. setattr(self, name, new)
  20. new.parent = self
  21. return new
  22. def __repr__(self):
  23. # self can be False only if its the `root` i.e. Token itself
  24. return 'Token' + ('.' if self else '') + '.'.join(self)
  25. Token = _TokenType()
  26. # Special token types
  27. Text = Token.Text
  28. Whitespace = Text.Whitespace
  29. Newline = Whitespace.Newline
  30. Error = Token.Error
  31. # Text that doesn't belong to this lexer (e.g. HTML in PHP)
  32. Other = Token.Other
  33. # Common token types for source code
  34. Keyword = Token.Keyword
  35. Name = Token.Name
  36. Literal = Token.Literal
  37. String = Literal.String
  38. Number = Literal.Number
  39. Punctuation = Token.Punctuation
  40. Operator = Token.Operator
  41. Comparison = Operator.Comparison
  42. Wildcard = Token.Wildcard
  43. Comment = Token.Comment
  44. Assignment = Token.Assignment
  45. # Generic types for non-source code
  46. Generic = Token.Generic
  47. Command = Generic.Command
  48. # String and some others are not direct children of Token.
  49. # alias them:
  50. Token.Token = Token
  51. Token.String = String
  52. Token.Number = Number
  53. # SQL specific tokens
  54. DML = Keyword.DML
  55. DDL = Keyword.DDL
  56. CTE = Keyword.CTE