## INFO ## ## INFO ## #-- CHEATSHEET ----------------------------------------------------------------# # HOWTO: http://sublimetext.info/docs/en/reference/syntaxdefs.html # REGEX: http://manual.macromates.com/en/regular_expressions # Import python modules from copy import deepcopy # Import user modules from src.common import syntax as original # Syntax Definition syntax = deepcopy(original) # Auto-recognition syntax['fileTypes'] = ['py'] syntax['keyEquivalent'] = '^~P' # Shebang syntax['firstLineMatch'] = r'^#!/.*\bpython[\d.-]*\b' # Folding marks for the TextEditor syntax['foldingStartMarker'] = (r'^\s*(def|class)\s+([.\w>]+)\s*(\((.*)\))?\s*:' r'|\{\s*$|\(\s*$|\[\s*$|^\s*"""(?=.)(?!.*""")') syntax['foldingStopMarker'] = r'^\s*$|^\s*\}|^\s*\]|^\s*\)|^\s*"""\s*$' # Language ID syntax['uuid'] = '851B1429-B8B4-4C1E-8030-399BDA994393' # Patterns syntax['patterns'].update({ #-- COMMENT -------------------------------------------------------------------# # ALL ARE COMMON #-- KEYWORDS ------------------------------------------------------------------# 0x0080: { 'name' : 'storage.modifier.declaration.{SCOPE}', 'match': r'\b(global|nonlocal)\b' }, 0x0090: { 'name' : 'keyword.control.import_and_import_from.{SCOPE}', 'match': r'\b(import|from)\b' }, 0x00A0: { 'name' : 'keyword.control.flow_block_delimiters.{SCOPE}', 'match': ( r'\b(elif|else|except|finally|for|if|try|while|' r'with|break|continue|pass|raise|return|yield)\b' ) }, 0x00C0: { 'name' : 'keyword.other.{SCOPE}', 'match': r'\b(as|assert|del)\b' }, #-- OPERATORS -----------------------------------------------------------------# # ALL ARE COMMON #-- CLASS ---------------------------------------------------------------------# 0x0110: { 'name' : 'meta.class.{SCOPE}', 'begin': r'^\s*(class)\s+(?=[a-zA-Z_]\w*(\s*\()?)', 'beginCaptures': { 1: {'name': 'storage.type.class.{SCOPE}'} }, 'patterns': [ {'include': '#class_entity_name'}, {'include': '#class_inheritance'} ], 'end' : r'(\)?\s*:|\s+([\w#\s:]+))', 'endCaptures': { 3: {'name': 'invalid.illegal.missing_section_begin.{SCOPE}'} } }, #-- FUNCTION ------------------------------------------------------------------# 0x0120: { 'name' : 'meta.function.{SCOPE}', 'begin': r'^\s*(async\s)?\s*(def)\s+(?=[a-zA-Z_]\w*\s*\()', 'beginCaptures': { 1: {'name': 'storage.modifier.coroutine.{SCOPE}'}, 2: {'name': 'storage.type.function.{SCOPE}'} }, 'patterns': [ # Function name {'include': '#function_entity_name'}, # Arguments {'include': '#function_arguments'}, # Annotation assignment (function) {'include': '#function_annotation'} ], # TODO: add illegal 'end': r'(\s*:)', 'endCaptures': { 2: {'name': 'invalid.illegal.missing_section_begin.{SCOPE}'} } }, #-- LAMBDA --------------------------------------------------------------------# # ALL ARE COMMON #-- DECORATOR -----------------------------------------------------------------# # ALL ARE COMMONE #-- CONSTANTS -----------------------------------------------------------------# 0x0160: { 'name' : 'constant.language.word_like.{SCOPE}', 'match': r'\b(None|True|False|Ellipsis|NotImplemented)\b' }, #-- STORAGES ------------------------------------------------------------------# 0x0180: { 'name' : 'storage.type.function.{SCOPE}', 'match': r'\b(def|lambda)\b' }, #-- BUILTINS ------------------------------------------------------------------# # ALL ARE COMMON #-- MAGIC STUFFS --------------------------------------------------------------# # ALL ARE COMMON #-- ETC -----------------------------------------------------------------------# # ALL ARE COMMON #-- STRUCTURES ----------------------------------------------------------------# # ALL ARE COMMON #-- ACCESS --------------------------------------------------------------------# # ALL ARE COMMON #-- STRING --------------------------------------------------------------------# # ALL ARE COMMON }) #-- REPOSITORY ----------------------------------------------------------------# syntax['repository'].update({ #-- COMMENTS ------------------------------------------------------------------# # ALL ARE COMMON #-- CLASS ---------------------------------------------------------------------# # ALL ARE COMMON #-- FUNCTION ------------------------------------------------------------------# # ALL ARE COMMON #-- BUILTINS ------------------------------------------------------------------# # TODO: rearrange -> what is builtin function and what is builtin type? 'builtin_functions': { 'name' : 'support.function.builtin.{SCOPE}', 'match': ( r'(? what is magic function and what is magic variable? 'magic_function_names': { 'name' : 'support.function.magic.{SCOPE}', 'match': ( r'\b__(' r'abs|add|and|await|bool|bytes|call|ceil|complex|contains|copy|' r'deepcopy|del|delattr|delete|delitem|dir|div|divmod|a?enter|eq|' r'a?exit|float|floor|floordiv|format|ge|get|getattr|getattribute|' r'getinitargs|getitem|getnewargs|getstate|gt|hash|hex|iadd|' r'iand|idiv|ifloordiv|ilshift|imul|index|init|instancecheck|' r'int|invert|ior|ipow|irshift|isub|a?iter|itruediv|ixor|le|len|' r'lshift|lt|metaclass|missing|mod|mul|ne|neg|new|a?next|oct|or|' r'pos|pow|prepare|radd|rand|rdiv|rdivmod|reduce|reduce_ex|' r'repr|reversed|rfloordiv|rlshift|rmod|rmul|ror|round|rpow|' r'rrshift|rshift|rsub|rtruediv|rxor|set|setattr|setitem|' r'setstate|sizeof|str|sub|subclasscheck|subclasshook|truediv|' r'trunc|unicode|weakref|xor' r')__\b' ) }, #-- STRING --------------------------------------------------------------------# # ALL ARE COMMON #-- REGEX ---------------------------------------------------------------------# # ALL ARE COMMON })