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