Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/whiley.py: 100%
10 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-01 06:54 +0000
1"""
2 pygments.lexers.whiley
3 ~~~~~~~~~~~~~~~~~~~~~~
5 Lexers for the Whiley language.
7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
9"""
11from pygments.lexer import RegexLexer, bygroups, words
12from pygments.token import Comment, Keyword, Name, Number, Operator, \
13 Punctuation, String, Text
15__all__ = ['WhileyLexer']
18class WhileyLexer(RegexLexer):
19 """
20 Lexer for the Whiley programming language.
22 .. versionadded:: 2.2
23 """
24 name = 'Whiley'
25 url = 'http://whiley.org/'
26 filenames = ['*.whiley']
27 aliases = ['whiley']
28 mimetypes = ['text/x-whiley']
30 # See the language specification:
31 # http://whiley.org/download/WhileyLanguageSpec.pdf
33 tokens = {
34 'root': [
35 # Whitespace
36 (r'\s+', Text),
38 # Comments
39 (r'//.*', Comment.Single),
40 # don't parse empty comment as doc comment
41 (r'/\*\*/', Comment.Multiline),
42 (r'(?s)/\*\*.*?\*/', String.Doc),
43 (r'(?s)/\*.*?\*/', Comment.Multiline),
45 # Keywords
46 (words((
47 'if', 'else', 'while', 'for', 'do', 'return',
48 'switch', 'case', 'default', 'break', 'continue',
49 'requires', 'ensures', 'where', 'assert', 'assume',
50 'all', 'no', 'some', 'in', 'is', 'new',
51 'throw', 'try', 'catch', 'debug', 'skip', 'fail',
52 'finite', 'total'), suffix=r'\b'), Keyword.Reserved),
53 (words((
54 'function', 'method', 'public', 'private', 'protected',
55 'export', 'native'), suffix=r'\b'), Keyword.Declaration),
56 # "constant" & "type" are not keywords unless used in declarations
57 (r'(constant|type)(\s+)([a-zA-Z_]\w*)(\s+)(is)\b',
58 bygroups(Keyword.Declaration, Text, Name, Text, Keyword.Reserved)),
59 (r'(true|false|null)\b', Keyword.Constant),
60 (r'(bool|byte|int|real|any|void)\b', Keyword.Type),
61 # "from" is not a keyword unless used with import
62 (r'(import)(\s+)(\*)([^\S\n]+)(from)\b',
63 bygroups(Keyword.Namespace, Text, Punctuation, Text, Keyword.Namespace)),
64 (r'(import)(\s+)([a-zA-Z_]\w*)([^\S\n]+)(from)\b',
65 bygroups(Keyword.Namespace, Text, Name, Text, Keyword.Namespace)),
66 (r'(package|import)\b', Keyword.Namespace),
68 # standard library: https://github.com/Whiley/WhileyLibs/
69 (words((
70 # types defined in whiley.lang.Int
71 'i8', 'i16', 'i32', 'i64',
72 'u8', 'u16', 'u32', 'u64',
73 'uint', 'nat',
75 # whiley.lang.Any
76 'toString'), suffix=r'\b'), Name.Builtin),
78 # byte literal
79 (r'[01]+b', Number.Bin),
81 # decimal literal
82 (r'[0-9]+\.[0-9]+', Number.Float),
83 # match "1." but not ranges like "3..5"
84 (r'[0-9]+\.(?!\.)', Number.Float),
86 # integer literal
87 (r'0x[0-9a-fA-F]+', Number.Hex),
88 (r'[0-9]+', Number.Integer),
90 # character literal
91 (r"""'[^\\]'""", String.Char),
92 (r"""(')(\\['"\\btnfr])(')""",
93 bygroups(String.Char, String.Escape, String.Char)),
95 # string literal
96 (r'"', String, 'string'),
98 # operators and punctuation
99 (r'[{}()\[\],.;]', Punctuation),
100 (r'[+\-*/%&|<>^!~@=:?'
101 # unicode operators
102 r'\u2200\u2203\u2205\u2282\u2286\u2283\u2287'
103 r'\u222A\u2229\u2264\u2265\u2208\u2227\u2228'
104 r']', Operator),
106 # identifier
107 (r'[a-zA-Z_]\w*', Name),
108 ],
109 'string': [
110 (r'"', String, '#pop'),
111 (r'\\[btnfr]', String.Escape),
112 (r'\\u[0-9a-fA-F]{4}', String.Escape),
113 (r'\\.', String),
114 (r'[^\\"]+', String),
115 ],
116 }