import re

from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer
from pygments.token import *


class LLDBIntelLexer(RegexLexer):
    """
    For Nasm (Intel) disassembly from LLDB.

    Based on the NasmLexer included with Pygments
    """
    name = 'LLDBIntel'
    aliases = ['lldb_intel']
    filenames = []
    mimetypes = []

    identifier = r'[a-z$._?][\w$.?#@~]*'
    hexn = r'(?:0[xX][0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)'
    octn = r'[0-7]+q'
    binn = r'[01]+b'
    decn = r'[0-9]+'
    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]|'
                r'[a-d][lh]|[er]?[a-d]x|[er]?[sbi]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
                r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
    wordop = r'seg|wrt|strict'
    type = r'byte|[dq]?word|ptr'


    flags = re.IGNORECASE | re.MULTILINE
    tokens = {
        'root': [
            include('whitespace'),
            (r'^\s*%', Comment.Preproc, 'preproc'),
            (identifier + ':', Name.Label),
            (r'(%s)(\s+)(equ)' % identifier,
                bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
                'instruction-args'),
            (declkw, Keyword.Declaration, 'instruction-args'),
            (identifier, Name.Function, 'instruction-args'),
            (hexn, Number.Hex),
            (r'[:]', Text),
            (r'^->', Error),
            (r'[\r\n]+', Text)
        ],
        'instruction-args': [
            (string, String),
            (hexn, Number.Hex),
            (octn, Number.Oct),
            (binn, Number.Bin),
            (floatn, Number.Float),
            (decn, Number.Integer),
            include('punctuation'),
            (register, Name.Builtin),
            (identifier, Name.Variable),
            (r'[\r\n]+', Text, '#pop'),
            include('whitespace')
        ],
        'preproc': [
            (r'[^;\n]+', Comment.Preproc),
            (r';.*?\n', Comment.Single, '#pop'),
            (r'\n', Comment.Preproc, '#pop'),
        ],
        'whitespace': [
            (r'\n', Text),
            (r'[ \t]+', Text),
            (r';.*', Comment.Single)
        ],
        'punctuation': [
            (r'[,():\[\]]+', Punctuation),
            (r'[&|^<>+*/%~-]+', Operator),
            (r'[$]+', Keyword.Constant),
            (wordop, Operator.Word),
            (type, Keyword.Type)
        ],
    }


all_lexers = {
    'lldb_intel': LLDBIntelLexer
}

@@ -372,16 +372,17 @@
 er = r'%5B
+%3C
 a-z$._?%5D
@@ -390,16 +390,19 @@
 %5Cw$.?#@~
+%5C+%3E
 %5D*'%0A    
@@ -843,16 +843,23 @@
 %7Ctr%5B3-7%5D
+%7C.mm%5Cd*
 ')%0A    w
@@ -2244,16 +2244,54 @@
 (r';.*',
+ Comment.Single),%0A            (r'#.*',
  Comment
@@ -2583,16 +2583,49 @@
 _intel':
+ LLDBIntelLexer,%0A    'gdb_intel':
  LLDBInt

Use LLDB lexer for GDB as well. Needs some work.