default_key = 'default'

syntax = {
    'formats': {
        'builtin': '{syntax_builtin}',
        'comment': '{syntax_comment}',
        'hexnumber': '{syntax_number}',
        'keyword': '{syntax_keyword}',
        'number': '{syntax_number}',
        'decorator': '{syntax_decorator}',
        'string single': '{syntax_string}',
        'string multi single': '{syntax_string}',
        'string double': '{syntax_string}',
        'string multi double': '{syntax_string}',
        'special': '{syntax_special}',
        'obsolete': '{syntax_obsolete}'
    },

    'contexts': [
        ('default', [
            ('comment', '#'),
            ('string raw multi single', "[buBU]?[rR]'''"),
            ('string raw single', "[buBU]?[rR]'"),
            ('string raw multi double', '[buBU]?[rR]"""'),
            ('string raw double', '[buBU]?[rR]"'),
            ('string multi single', "[buBU]?'''"),
            ('string single', "[buBU]?'"),
            ('string multi double', '[buBU]?"""'),
            ('string double', '[buBU]?"'),
        ], True),
        ('comment', [(None, '\n')]),
        ('string raw multi single', [(None, "'''")], True),
        ('string raw single', [(None, "'")]),
        ('string raw multi double', [(None, '"""')], True),
        ('string raw double', [(None, '"')]),
        ('string multi single', [(None, "'''")], True),
        ('string single', [(None, "'")]),
        ('string multi double', [(None, '"""')], True),
        ('string double', [(None, '"')]),
    ],

    'tokens': {
        default_key: [
            ('hexnumber', '(0x)([0-9a-fA-F])+?'),
            ('number', r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?[jJ]?'),
            ('obsolete', r'\s*\bprint\b(?!\s*\()'),
            ('keyword', [
                'and',
                'as',
                'assert',
                'break',
                'class',
                'continue',
                'def',
                'del',
                'elif',
                'else',
                'except',
                'exec',
                'finally',
                'for',
                'from',
                'global',
                'if',
                'import',
                'in',
                'is',
                'lambda',
                'not',
                'or',
                'pass',
                # 'print',
                'raise',
                'return',
                'try',
                'while',
                'with',
                'yield'
            ], '(^|[\x08\\W])', '(?:[\x08\\W]|$)'),
            ('builtin', [
                'ArithmeticError',
                'AssertionError',
                'AttributeError',
                'BaseException',
                'BufferError',
                'BytesWarning',
                'DeprecationWarning',
                'EOFError',
                'Ellipsis',
                'EnvironmentError',
                'Exception',
                'False',
                'FloatingPointError',
                'FutureWarning',
                'GeneratorExit',
                'IOError',
                'ImportError',
                'ImportWarning',
                'IndentationError',
                'IndexError',
                'KeyError',
                'KeyboardInterrupt',
                'LookupError',
                'MemoryError',
                'NameError',
                'None',
                'NotImplemented',
                'NotImplementedError',
                'OSError',
                'OverflowError',
                'PendingDeprecationWarning',
                'ReferenceError',
                'RuntimeError',
                'RuntimeWarning',
                'StandardError',
                'StopIteration',
                'SyntaxError',
                'SyntaxWarning',
                'SystemError',
                'SystemExit',
                'TabError',
                'True',
                'TypeError',
                'UnboundLocalError',
                'UnicodeDecodeError',
                'UnicodeEncodeError',
                'UnicodeError',
                'UnicodeTranslateError',
                'UnicodeWarning',
                'UserWarning',
                'ValueError',
                'Warning',
                'ZeroDivisionError',
                '__import__',
                '__name__',
                '__file__',
                'abs',
                'all',
                'any',
                'apply',
                'basestring',
                'bin',
                'bool',
                'buffer',
                'bytearray',
                'bytes',
                'callable',
                'chr',
                'classmethod',
                'cmp',
                'coerce',
                'compile',
                'complex',
                'copyright',
                'credits',
                'delattr',
                'dict',
                'dir',
                'divmod',
                'enumerate',
                'eval',
                'execfile',
                'exit',
                'file',
                'filter',
                'float',
                'format',
                'frozenset',
                'getattr',
                'globals',
                'hasattr',
                'hash',
                'help',
                'hex',
                'id',
                'input',
                'int',
                'intern',
                'isinstance',
                'issubclass',
                'iter',
                'len',
                'license',
                'list',
                'locals',
                'long',
                'map',
                'max',
                'memoryview',
                'min',
                'next',
                'object',
                'oct',
                'open',
                'ord',
                'pow',
                'print',
                'property',
                'quit',
                'range',
                'raw_input',
                'reduce',
                'reload',
                'repr',
                'reversed',
                'round',
                'self',
                'set',
                'setattr',
                'slice',
                'sorted',
                'staticmethod',
                'str',
                'sum',
                'super',
                'tuple',
                'type',
                'unichr',
                'unicode',
                'vars',
                'xrange',
                'zip'
            ], '(^|[^\\.\\w])', '(?:[\x08\\W]|$)'),
            ('decorator', r'^\s*@[A-Za-z_][A-Za-z_0-9]*'),
            ('ident', '[A-Za-z_][A-Za-z_0-9]*')
        ],
        ('string multi single', 'string single', 'string multi double', 'string double'): [
            ('special', r'\\(["\'abfnrtv]|[0-7]{1,3}|'
                        r'x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8}|N\{[a-zA-Z0-9\- ]+\}|\s*$)')
        ]
    }
}
