boa.py 3.8 KB

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