Skip to content

Commit

Permalink
Asm lex bugfix #1895: register re check for boundary (#1961)
Browse files Browse the repository at this point in the history
  • Loading branch information
blu-base committed Nov 17, 2021
1 parent 49d9359 commit d3b0ea1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 68 deletions.
12 changes: 6 additions & 6 deletions pygments/lexers/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GasLexer(RegexLexer):
char = r'[\w$.@-]'
identifier = r'(?:[a-zA-Z$_]' + char + r'*|\.' + char + '+)'
number = r'(?:0[xX][a-fA-F0-9]+|#?-?\d+)'
register = '%' + identifier
register = '%' + identifier + r'\b'

tokens = {
'root': [
Expand Down Expand Up @@ -221,7 +221,7 @@ class HsailLexer(RegexLexer):
identifier = r'[a-zA-Z_][\w.]*'
# Registers
register_number = r'[0-9]+'
register = r'(\$(c|s|d|q)' + register_number + ')'
register = r'(\$(c|s|d|q)' + register_number + r')\b'
# Qualifiers
alignQual = r'(align\(\d+\))'
widthQual = r'(width\((\d+|all)\))'
Expand Down Expand Up @@ -725,9 +725,9 @@ class NasmLexer(RegexLexer):
floatn = decn + r'\.e?' + decn
string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
declkw = r'(?:res|d)[bwdqt]|times'
register = (r'r[0-9][0-5]?[bwd]?|'
register = (r'(r[0-9][0-5]?[bwd]?|'
r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7])\b')
wordop = r'seg|wrt|strict'
type = r'byte|[dq]?word'
# Directives must be followed by whitespace, otherwise CPU will match
Expand Down Expand Up @@ -819,9 +819,9 @@ class TasmLexer(RegexLexer):
floatn = decn + r'\.e?' + decn
string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
declkw = r'(?:res|d)[bwdqt]|times'
register = (r'r[0-9][0-5]?[bwd]|'
register = (r'(r[0-9][0-5]?[bwd]|'
r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7])\b')
wordop = r'seg|wrt|strict'
type = r'byte|[dq]?word'
directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|'
Expand Down
93 changes: 31 additions & 62 deletions tests/examplefiles/tasm/example.tasm.output

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions tests/snippets/nasm/checkid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---input---
print_brick_no_color:
inc bx
mov di, bx ; comment
jmp check_col

---tokens---
'print_brick_no_color:' Name.Label
'\n' Text.Whitespace

' ' Text.Whitespace
'inc' Name.Function
' ' Text.Whitespace
'bx' Name.Builtin
'\n' Text.Whitespace

' ' Text.Whitespace
'mov' Name.Function
' ' Text.Whitespace
'di' Name.Builtin
',' Punctuation
' ' Text.Whitespace
'bx' Name.Builtin
' ' Text.Whitespace
'; comment' Comment.Single
'\n' Text.Whitespace

' ' Text.Whitespace
'jmp' Name.Function
' ' Text.Whitespace
'check_col' Name.Variable
'\n' Text.Whitespace

0 comments on commit d3b0ea1

Please sign in to comment.