boa.py 3.8 KB

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