ThirdParty/Pygments/pygments/lexers/dalvik.py

changeset 4172
4f20dba37ab6
parent 3145
a9de05d4a22f
child 4697
c2e9bf425554
equal deleted inserted replaced
4170:8bc578136279 4172:4f20dba37ab6
3 pygments.lexers.dalvik 3 pygments.lexers.dalvik
4 ~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Pygments lexers for Dalvik VM-related languages. 6 Pygments lexers for Dalvik VM-related languages.
7 7
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 from __future__ import unicode_literals 12 import re
13 13
14 from pygments.lexer import RegexLexer, include, bygroups 14 from pygments.lexer import RegexLexer, include, bygroups
15 from pygments.token import Keyword, Text, Comment, Name, String, Number, \ 15 from pygments.token import Keyword, Text, Comment, Name, String, Number, \
16 Punctuation 16 Punctuation
17 17
18 __all__ = ['SmaliLexer'] 18 __all__ = ['SmaliLexer']
19 19
20 20
21 class SmaliLexer(RegexLexer): 21 class SmaliLexer(RegexLexer):
22 """ 22 """
23 For `Smali <http://code.google.com/p/smali/>`_ (Android/Dalvik) assembly 23 For `Smali <http://code.google.com/p/smali/>`_ (Android/Dalvik) assembly
24 code. 24 code.
25 25
26 *New in Pygments 1.6.* 26 .. versionadded:: 1.6
27 """ 27 """
28 name = 'Smali' 28 name = 'Smali'
29 aliases = ['smali'] 29 aliases = ['smali']
30 filenames = ['*.smali'] 30 filenames = ['*.smali']
31 mimetypes = ['text/smali'] 31 mimetypes = ['text/smali']
63 'whitespace': [ 63 'whitespace': [
64 (r'\n', Text), 64 (r'\n', Text),
65 (r'\s+', Text), 65 (r'\s+', Text),
66 ], 66 ],
67 'instruction': [ 67 'instruction': [
68 (r'\b[vp]\d+\b', Name.Builtin), # registers 68 (r'\b[vp]\d+\b', Name.Builtin), # registers
69 (r'\b[a-z][A-Za-z0-9/-]+\s+', Text), # instructions 69 (r'\b[a-z][A-Za-z0-9/-]+\s+', Text), # instructions
70 ], 70 ],
71 'literal': [ 71 'literal': [
72 (r'".*"', String), 72 (r'".*"', String),
73 (r'0x[0-9A-Fa-f]+t?', Number.Hex), 73 (r'0x[0-9A-Fa-f]+t?', Number.Hex),
74 (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), 74 (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
75 (r'[0-9]+L?', Number.Integer), 75 (r'[0-9]+L?', Number.Integer),
76 ], 76 ],
77 'field': [ 77 'field': [
78 (r'(\$?\b)([A-Za-z0-9_$]*)(:)', 78 (r'(\$?\b)([\w$]*)(:)',
79 bygroups(Punctuation, Name.Variable, Punctuation)), 79 bygroups(Punctuation, Name.Variable, Punctuation)),
80 ], 80 ],
81 'method': [ 81 'method': [
82 (r'<(?:cl)?init>', Name.Function), # constructor 82 (r'<(?:cl)?init>', Name.Function), # constructor
83 (r'(\$?\b)([A-Za-z0-9_$]*)(\()', 83 (r'(\$?\b)([\w$]*)(\()',
84 bygroups(Punctuation, Name.Function, Punctuation)), 84 bygroups(Punctuation, Name.Function, Punctuation)),
85 ], 85 ],
86 'label': [ 86 'label': [
87 (r':[A-Za-z0-9_]+', Name.Label), 87 (r':\w+', Name.Label),
88 ], 88 ],
89 'class': [ 89 'class': [
90 # class names in the form Lcom/namespace/ClassName; 90 # class names in the form Lcom/namespace/ClassName;
91 # I only want to color the ClassName part, so the namespace part is 91 # I only want to color the ClassName part, so the namespace part is
92 # treated as 'Text' 92 # treated as 'Text'
93 (r'(L)((?:[A-Za-z0-9_$]+/)*)([A-Za-z0-9_$]+)(;)', 93 (r'(L)((?:[\w$]+/)*)([\w$]+)(;)',
94 bygroups(Keyword.Type, Text, Name.Class, Text)), 94 bygroups(Keyword.Type, Text, Name.Class, Text)),
95 ], 95 ],
96 'punctuation': [ 96 'punctuation': [
97 (r'->', Punctuation), 97 (r'->', Punctuation),
98 (r'[{},\(\):=\.-]', Punctuation), 98 (r'[{},():=.-]', Punctuation),
99 ], 99 ],
100 'type': [ 100 'type': [
101 (r'[ZBSCIJFDV\[]+', Keyword.Type), 101 (r'[ZBSCIJFDV\[]+', Keyword.Type),
102 ], 102 ],
103 'comment': [ 103 'comment': [
104 (r'#.*?\n', Comment), 104 (r'#.*?\n', Comment),
105 ], 105 ],
106 } 106 }
107
108 def analyse_text(text):
109 score = 0
110 if re.search(r'^\s*\.class\s', text, re.MULTILINE):
111 score += 0.5
112 if re.search(r'\b((check-cast|instance-of|throw-verification-error'
113 r')\b|(-to|add|[ais]get|[ais]put|and|cmpl|const|div|'
114 r'if|invoke|move|mul|neg|not|or|rem|return|rsub|shl|'
115 r'shr|sub|ushr)[-/])|{|}', text, re.MULTILINE):
116 score += 0.3
117 if re.search(r'(\.(catchall|epilogue|restart local|prologue)|'
118 r'\b(array-data|class-change-error|declared-synchronized|'
119 r'(field|inline|vtable)@0x[0-9a-fA-F]|generic-error|'
120 r'illegal-class-access|illegal-field-access|'
121 r'illegal-method-access|instantiation-error|no-error|'
122 r'no-such-class|no-such-field|no-such-method|'
123 r'packed-switch|sparse-switch))\b', text, re.MULTILINE):
124 score += 0.6
125 return score

eric ide

mercurial