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