summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatth?us G. Chajdas <dev@anteru.net>2019-06-22 21:01:26 +0200
committerMatth?us G. Chajdas <dev@anteru.net>2019-06-22 21:01:26 +0200
commitf8e695a96d367c513cad3c711d99161c9d65daa3 (patch)
tree4b124a4d2efad0256437517ecf5b4e228b87dbea
parent1e89285bd1264d9ca50b3385bb39b13c57f1c39b (diff)
downloadpygments-f8e695a96d367c513cad3c711d99161c9d65daa3.tar.gz
Make the NasmLexer the default for *.asm.
NASM is much more popular than TASM, but get_lexer_for_filename('.asm') would return TASM. Resolved by changing the NASM priority to 1, and adding an analyse_text implementation to both NasmLexer and TasmLexer to help resolve which one to use (PROC should be fairly common in TASM code.)
-rw-r--r--pygments/lexers/asm.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py
index 75d65f9f..87dcff38 100644
--- a/pygments/lexers/asm.py
+++ b/pygments/lexers/asm.py
@@ -455,6 +455,10 @@ class NasmLexer(RegexLexer):
filenames = ['*.asm', '*.ASM']
mimetypes = ['text/x-nasm']
+ # Tasm uses the same file endings, but TASM is not as common as NASM, so
+ # we prioritize NASM higher by default
+ priority = 1.0
+
identifier = r'[a-z$._?][\w$.?#@~]*'
hexn = r'(?:0x[0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)'
octn = r'[0-7]+q'
@@ -520,6 +524,11 @@ class NasmLexer(RegexLexer):
],
}
+ def analyse_text(text):
+ # Probably TASM
+ if re.match(r'PROC', text, re.IGNORECASE):
+ return False
+
class NasmObjdumpLexer(ObjdumpLexer):
"""
@@ -614,6 +623,11 @@ class TasmLexer(RegexLexer):
],
}
+ def analyse_text(text):
+ # See above
+ if re.match(r'PROC', text, re.I):
+ return True
+
class Ca65Lexer(RegexLexer):
"""