boa.py 3.8 KB

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