From f7bd44802ad0abdc116b9dfc30c179cd0addecfe Mon Sep 17 00:00:00 2001 From: David Corbett Date: Sun, 11 May 2014 12:27:08 -0400 Subject: Distinguish between Jasmin and Smali --- pygments/lexers/dalvik.py | 20 ++++++++++++++++++++ pygments/lexers/jvm.py | 10 +++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pygments/lexers/dalvik.py b/pygments/lexers/dalvik.py index 901b7c5a..4f250b02 100644 --- a/pygments/lexers/dalvik.py +++ b/pygments/lexers/dalvik.py @@ -9,6 +9,8 @@ :license: BSD, see LICENSE for details. """ +import re + from pygments.lexer import RegexLexer, include, bygroups from pygments.token import Keyword, Text, Comment, Name, String, Number, \ Punctuation @@ -102,3 +104,21 @@ class SmaliLexer(RegexLexer): (r'#.*?\n', Comment), ], } + + def analyse_text(text): + if not re.search(r'^\s*\.class\s', text, re.MULTILINE): + return 0 + if re.search(r'(\.(catchall|epilogue|restart local|prologue)|' + r'\b(array-data|class-change-error|declared-synchronized|' + r'(field|inline|vtable)@0x[0-9a-fA-F]|generic-error|' + r'illegal-class-access|illegal-field-access|' + r'illegal-method-access|instantiation-error|no-error|' + r'no-such-class|no-such-field|no-such-method|' + r'packed-switch|sparse-switch))\b', text, re.MULTILINE): + return 1 + if re.search(r'\b(check-cast|instance-of|throw-verification-error)\b|' + r'\b(-to|add|[ais]get|[ais]put|and|cmpl|const|div|if|' + r'invoke|move|mul|neg|not|or|rem|return|rsub|shl|shr|sub|' + r'ushr)[-/]|{|}', text, re.MULTILINE): + return 0.8 + return 0.5 diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py index 0e7e1b42..f0fe6a50 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -1507,4 +1507,12 @@ class JasminLexer(RegexLexer): } def analyse_text(text): - return bool(re.search(r'^\s*\.class\s', text, re.MULTILINE)) + if not re.search(r'^\s*\.class\s', text, re.MULTILINE): + return 0 + if re.search(r'^\s*\.(attribute|bytecode|debug|deprecated|enclosing|' + r'inner|interface|limit|set|signature|stack)\b', text, + re.MULTILINE): + return 1 + if re.search(r'^\s*[a-z]+_[a-z]+\b', text, re.MULTILINE): + return 0.8 + return 0.5 -- cgit v1.2.1