boa.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. """
  2. pygments.lexers.boa
  3. ~~~~~~~~~~~~~~~~~~~
  4. Lexers for the Boa language.
  5. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
  6. :license: BSD, see LICENSE for details.
  7. """
  8. import re
  9. from pygments.lexer import RegexLexer, words
  10. from pygments.token import String, Comment, Keyword, Name, Number, Text, \
  11. Operator, Punctuation
  12. __all__ = ['BoaLexer']
  13. line_re = re.compile('.*?\n')
  14. class BoaLexer(RegexLexer):
  15. """
  16. Lexer for the `Boa <http://boa.cs.iastate.edu/docs/>`_ language.
  17. .. versionadded:: 2.4
  18. """
  19. name = 'Boa'
  20. aliases = ['boa']
  21. filenames = ['*.boa']
  22. reserved = words(
  23. ('input', 'output', 'of', 'weight', 'before', 'after', 'stop',
  24. 'ifall', 'foreach', 'exists', 'function', 'break', 'switch', 'case',
  25. 'visitor', 'default', 'return', 'visit', 'while', 'if', 'else'),
  26. suffix=r'\b', prefix=r'\b')
  27. keywords = words(
  28. ('bottom', 'collection', 'maximum', 'mean', 'minimum', 'set', 'sum',
  29. 'top', 'string', 'int', 'bool', 'float', 'time', 'false', 'true',
  30. 'array', 'map', 'stack', 'enum', 'type'), suffix=r'\b', prefix=r'\b')
  31. classes = words(
  32. ('Project', 'ForgeKind', 'CodeRepository', 'Revision', 'RepositoryKind',
  33. 'ChangedFile', 'FileKind', 'ASTRoot', 'Namespace', 'Declaration', 'Type',
  34. 'Method', 'Variable', 'Statement', 'Expression', 'Modifier',
  35. 'StatementKind', 'ExpressionKind', 'ModifierKind', 'Visibility',
  36. 'TypeKind', 'Person', 'ChangeKind'),
  37. suffix=r'\b', prefix=r'\b')
  38. operators = ('->', ':=', ':', '=', '<<', '!', '++', '||',
  39. '&&', '+', '-', '*', ">", "<")
  40. string_sep = ('`', '\"')
  41. built_in_functions = words(
  42. (
  43. # Array functions
  44. 'new', 'sort',
  45. # Date & Time functions
  46. 'yearof', 'dayofyear', 'hourof', 'minuteof', 'secondof', 'now',
  47. 'addday', 'addmonth', 'addweek', 'addyear', 'dayofmonth', 'dayofweek',
  48. 'dayofyear', 'formattime', 'trunctoday', 'trunctohour', 'trunctominute',
  49. 'trunctomonth', 'trunctosecond', 'trunctoyear',
  50. # Map functions
  51. 'clear', 'haskey', 'keys', 'lookup', 'remove', 'values',
  52. # Math functions
  53. 'abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
  54. 'ceil', 'cos', 'cosh', 'exp', 'floor', 'highbit', 'isfinite', 'isinf',
  55. 'isnan', 'isnormal', 'log', 'log10', 'max', 'min', 'nrand', 'pow',
  56. 'rand', 'round', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc',
  57. # Other functions
  58. 'def', 'hash', 'len',
  59. # Set functions
  60. 'add', 'contains', 'remove',
  61. # String functions
  62. 'format', 'lowercase', 'match', 'matchposns', 'matchstrs', 'regex',
  63. 'split', 'splitall', 'splitn', 'strfind', 'strreplace', 'strrfind',
  64. 'substring', 'trim', 'uppercase',
  65. # Type Conversion functions
  66. 'bool', 'float', 'int', 'string', 'time',
  67. # Domain-Specific functions
  68. 'getast', 'getsnapshot', 'hasfiletype', 'isfixingrevision', 'iskind',
  69. 'isliteral',
  70. ),
  71. prefix=r'\b',
  72. suffix=r'\(')
  73. tokens = {
  74. 'root': [
  75. (r'#.*?$', Comment.Single),
  76. (r'/\*.*?\*/', Comment.Multiline),
  77. (reserved, Keyword.Reserved),
  78. (built_in_functions, Name.Function),
  79. (keywords, Keyword.Type),
  80. (classes, Name.Classes),
  81. (words(operators), Operator),
  82. (r'[][(),;{}\\.]', Punctuation),
  83. (r'"(\\\\|\\[^\\]|[^"\\])*"', String.Double),
  84. (r"`(\\\\|\\[^\\]|[^`\\])*`", String.Backtick),
  85. (words(string_sep), String.Delimiter),
  86. (r'[a-zA-Z_]+', Name.Variable),
  87. (r'[0-9]+', Number.Integer),
  88. (r'\s+?', Text), # Whitespace
  89. ]
  90. }