1"""
2 pygments.lexers.ooc
3 ~~~~~~~~~~~~~~~~~~~
4
5 Lexers for the Ooc 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, bygroups, words
12from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
13 Number, Punctuation
14
15__all__ = ['OocLexer']
16
17
18class OocLexer(RegexLexer):
19 """
20 For Ooc source code
21 """
22 name = 'Ooc'
23 url = 'https://ooc-lang.github.io/'
24 aliases = ['ooc']
25 filenames = ['*.ooc']
26 mimetypes = ['text/x-ooc']
27 version_added = '1.2'
28
29 tokens = {
30 'root': [
31 (words((
32 'class', 'interface', 'implement', 'abstract', 'extends', 'from',
33 'this', 'super', 'new', 'const', 'final', 'static', 'import',
34 'use', 'extern', 'inline', 'proto', 'break', 'continue',
35 'fallthrough', 'operator', 'if', 'else', 'for', 'while', 'do',
36 'switch', 'case', 'as', 'in', 'version', 'return', 'true',
37 'false', 'null'), prefix=r'\b', suffix=r'\b'),
38 Keyword),
39 (r'include\b', Keyword, 'include'),
40 (r'(cover)([ \t]+)(from)([ \t]+)(\w+[*@]?)',
41 bygroups(Keyword, Text, Keyword, Text, Name.Class)),
42 (r'(func)((?:[ \t]|\\\n)+)(~[a-z_]\w*)',
43 bygroups(Keyword, Text, Name.Function)),
44 (r'\bfunc\b', Keyword),
45 # Note: %= not listed on https://ooc-lang.github.io/docs/lang/operators/
46 (r'//.*', Comment),
47 (r'(?s)/\*.*?\*/', Comment.Multiline),
48 (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|'
49 r'&&?|\|\|?|\^=?)', Operator),
50 (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text,
51 Name.Function)),
52 (r'[A-Z][A-Z0-9_]+', Name.Constant),
53 (r'[A-Z]\w*([@*]|\[[ \t]*\])?', Name.Class),
54
55 (r'([a-z]\w*(?:~[a-z]\w*)?)((?:[ \t]|\\\n)*)(?=\()',
56 bygroups(Name.Function, Text)),
57 (r'[a-z]\w*', Name.Variable),
58
59 # : introduces types
60 (r'[:(){}\[\];,]', Punctuation),
61
62 (r'0x[0-9a-fA-F]+', Number.Hex),
63 (r'0c[0-9]+', Number.Oct),
64 (r'0b[01]+', Number.Bin),
65 (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float),
66 (r'[0-9_]+', Number.Decimal),
67
68 (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\"])*"',
69 String.Double),
70 (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
71 String.Char),
72 (r'@', Punctuation), # pointer dereference
73 (r'\.', Punctuation), # imports or chain operator
74
75 (r'\\[ \t\n]', Text),
76 (r'[ \t]+', Text),
77 ],
78 'include': [
79 (r'[\w/]+', Name),
80 (r',', Punctuation),
81 (r'[ \t]', Text),
82 (r'[;\n]', Text, '#pop'),
83 ],
84 }