thingsdb.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. """
  2. pygments.lexers.thingsdb
  3. ~~~~~~~~~~~~~~~~~~~~~~~~
  4. Lexers for the ThingsDB language.
  5. :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. from pygments.lexer import RegexLexer, include, bygroups
  9. from pygments.token import Comment, Keyword, Name, Number, String, Text, \
  10. Operator, Punctuation, Whitespace
  11. __all__ = ['ThingsDBLexer']
  12. class ThingsDBLexer(RegexLexer):
  13. """
  14. Lexer for the ThingsDB programming language.
  15. .. versionadded:: 2.9
  16. """
  17. name = 'ThingsDB'
  18. aliases = ['ti', 'thingsdb']
  19. filenames = ['*.ti']
  20. tokens = {
  21. 'root': [
  22. include('expression'),
  23. ],
  24. 'expression': [
  25. include('comments'),
  26. include('whitespace'),
  27. # numbers
  28. (r'[-+]?0b[01]+', Number.Bin),
  29. (r'[-+]?0o[0-8]+', Number.Oct),
  30. (r'([-+]?0x[0-9a-fA-F]+)', Number.Hex),
  31. (r'[-+]?[0-9]+', Number.Integer),
  32. (r'[-+]?((inf|nan)([^0-9A-Za-z_]|$)|[0-9]*\.[0-9]+(e[+-][0-9]+)?)',
  33. Number.Float),
  34. # strings
  35. (r'(?:"(?:[^"]*)")+', String.Double),
  36. (r"(?:'(?:[^']*)')+", String.Single),
  37. # literals
  38. (r'(true|false|nil)\b', Keyword.Constant),
  39. # regular expressions
  40. (r'(/[^/\\]*(?:\\.[^/\\]*)*/i?)', String.Regex),
  41. # thing id's
  42. (r'#[0-9]+', Comment.Preproc),
  43. # name, assignments and functions
  44. include('names'),
  45. (r'[(){}\[\],;]', Punctuation),
  46. (r'[+\-*/%&|<>^!~@=:?]', Operator),
  47. ],
  48. 'names': [
  49. (r'(\.)'
  50. r'(add|call|contains|del|endswith|extend|filter|find|findindex|'
  51. r'get|has|id|indexof|keys|len|lower|map|pop|push|remove|set|sort|'
  52. r'splice|startswith|test|unwrap|upper|values|wrap)'
  53. r'(\()',
  54. bygroups(Name.Function, Name.Function, Punctuation), 'arguments'),
  55. (r'(array|assert|assert_err|auth_err|backup_info|backups_info|'
  56. r'bad_data_err|bool|closure|collection_info|collections_info|'
  57. r'counters|deep|del_backup|del_collection|del_expired|del_node|'
  58. r'del_procedure|del_token|del_type|del_user|err|float|'
  59. r'forbidden_err|grant|int|isarray|isascii|isbool|isbytes|iserr|'
  60. r'isfloat|isinf|isint|islist|isnan|isnil|israw|isset|isstr|'
  61. r'isthing|istuple|isutf8|lookup_err|max_quota_err|mod_type|new|'
  62. r'new_backup|new_collection|new_node|new_procedure|new_token|'
  63. r'new_type|new_user|node_err|node_info|nodes_info|now|'
  64. r'num_arguments_err|operation_err|overflow_err|procedure_doc|'
  65. r'procedure_info|procedures_info|raise|refs|rename_collection|'
  66. r'rename_user|reset_counters|return|revoke|run|set_log_level|set|'
  67. r'set_quota|set_type|shutdown|str|syntax_err|thing|try|type|'
  68. r'type_err|type_count|type_info|types_info|user_info|users_info|'
  69. r'value_err|wse|zero_div_err)'
  70. r'(\()',
  71. bygroups(Name.Function, Punctuation),
  72. 'arguments'),
  73. (r'(\.[A-Za-z_][0-9A-Za-z_]*)'
  74. r'(\s*)(=)',
  75. bygroups(Name.Attribute, Text, Operator)),
  76. (r'\.[A-Za-z_][0-9A-Za-z_]*', Name.Attribute),
  77. (r'([A-Za-z_][0-9A-Za-z_]*)(\s*)(=)',
  78. bygroups(Name.Variable, Text, Operator)),
  79. (r'[A-Za-z_][0-9A-Za-z_]*', Name.Variable),
  80. ],
  81. 'whitespace': [
  82. (r'\n', Whitespace),
  83. (r'\s+', Whitespace),
  84. ],
  85. 'comments': [
  86. (r'//(.*?)\n', Comment.Single),
  87. (r'/\*', Comment.Multiline, 'comment'),
  88. ],
  89. 'comment': [
  90. (r'[^*/]+', Comment.Multiline),
  91. (r'/\*', Comment.Multiline, '#push'),
  92. (r'\*/', Comment.Multiline, '#pop'),
  93. (r'[*/]', Comment.Multiline),
  94. ],
  95. 'arguments': [
  96. include('expression'),
  97. (',', Punctuation),
  98. (r'\(', Punctuation, '#push'),
  99. (r'\)', Punctuation, '#pop'),
  100. ],
  101. }