thingsdb.py 4.2 KB

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