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