ThirdParty/Pygments/pygments/lexers/dalvik.py

changeset 2426
da76c71624de
child 2525
8b507a9a2d40
equal deleted inserted replaced
2425:ace8a08028f3 2426:da76c71624de
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.dalvik
4 ~~~~~~~~~~~~~~~~~~~~~~
5
6 Pygments lexers for Dalvik VM-related languages.
7
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 from pygments.lexer import RegexLexer, include, bygroups
13 from pygments.token import Keyword, Text, Comment, Name, String, Number, \
14 Punctuation
15
16 __all__ = ['SmaliLexer']
17
18
19 class SmaliLexer(RegexLexer):
20 """
21 For `Smali <http://code.google.com/p/smali/>`_ (Android/Dalvik) assembly
22 code.
23
24 *New in Pygments 1.6.*
25 """
26 name = 'Smali'
27 aliases = ['smali']
28 filenames = ['*.smali']
29 mimetypes = ['text/smali']
30
31 tokens = {
32 'root': [
33 include('comment'),
34 include('label'),
35 include('field'),
36 include('method'),
37 include('class'),
38 include('directive'),
39 include('access-modifier'),
40 include('instruction'),
41 include('literal'),
42 include('punctuation'),
43 include('type'),
44 include('whitespace')
45 ],
46 'directive': [
47 (r'^[ \t]*\.(class|super|implements|field|subannotation|annotation|'
48 r'enum|method|registers|locals|array-data|packed-switch|'
49 r'sparse-switch|catchall|catch|line|parameter|local|prologue|'
50 r'epilogue|source)', Keyword),
51 (r'^[ \t]*\.end (field|subannotation|annotation|method|array-data|'
52 'packed-switch|sparse-switch|parameter|local)', Keyword),
53 (r'^[ \t]*\.restart local', Keyword),
54 ],
55 'access-modifier': [
56 (r'(public|private|protected|static|final|synchronized|bridge|'
57 r'varargs|native|abstract|strictfp|synthetic|constructor|'
58 r'declared-synchronized|interface|enum|annotation|volatile|'
59 r'transient)', Keyword),
60 ],
61 'whitespace': [
62 (r'\n', Text),
63 (r'\s+', Text),
64 ],
65 'instruction': [
66 (r'\b[vp]\d+\b', Name.Builtin), # registers
67 (r'\b[a-z][A-Za-z0-9/-]+\s+', Text), # instructions
68 ],
69 'literal': [
70 (r'".*"', String),
71 (r'0x[0-9A-Fa-f]+t?', Number.Hex),
72 (r'[0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
73 (r'[0-9]+L?', Number.Integer),
74 ],
75 'field': [
76 (r'(\$?\b)([A-Za-z0-9_$]*)(:)',
77 bygroups(Punctuation, Name.Variable, Punctuation)),
78 ],
79 'method': [
80 (r'<(?:cl)?init>', Name.Function), # constructor
81 (r'(\$?\b)([A-Za-z0-9_$]*)(\()',
82 bygroups(Punctuation, Name.Function, Punctuation)),
83 ],
84 'label': [
85 (r':[A-Za-z0-9_]+', Name.Label),
86 ],
87 'class': [
88 # class names in the form Lcom/namespace/ClassName;
89 # I only want to color the ClassName part, so the namespace part is
90 # treated as 'Text'
91 (r'(L)((?:[A-Za-z0-9_$]+/)*)([A-Za-z0-9_$]+)(;)',
92 bygroups(Keyword.Type, Text, Name.Class, Text)),
93 ],
94 'punctuation': [
95 (r'->', Punctuation),
96 (r'[{},\(\):=\.-]', Punctuation),
97 ],
98 'type': [
99 (r'[ZBSCIJFDV\[]+', Keyword.Type),
100 ],
101 'comment': [
102 (r'#.*?\n', Comment),
103 ],
104 }

eric ide

mercurial