pmacs3/regex.py

41 lines
1.5 KiB
Python

import re
# mode stuff (emacs/vi)
auto_mode_emacs = re.compile(r'-\*- ([^ ]+) -\*-')
auto_mode_vi = re.compile('(?:vim|vi|ex):.+?(?:syntax|syn)=([^ ]+)')
# lexing
reserved_token_names = re.compile(r'^(?:rules|null|start|end|middle[0-9]*)$')
valid_token_name = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
middle_token_name = re.compile(r'^middle([0-9]+)$')
# meta regexes
meta_chars = re.compile(r'([\.\^\$\*\+\?\{\}\(\)\[\]\|\"\'\\,])')
# shell
shell_command = re.compile(r'^[^ ]+')
# whitespace regexes
leading_whitespace = re.compile('^ *')
trailing_whitespace = re.compile(' *$')
whitespace = re.compile(r'^[ \n]*$')
space = re.compile('^ *$')
leading_whitespace2 = re.compile('^( *?)(.*?)\n?$')
# word regexes
word = re.compile('^[A-Za-z0-9_]+$')
word_char = re.compile('^[A-Za-z0-9_]$')
# perl regexes
perl_base = re.compile("^sub ")
perl_hash_cleanup = re.compile(r"^( *)([^ ]+|'(?:\.|[^'\'])*'|\"(?:\.|[^\\\"]*)\")( *)(=>)( *)([^ ].*)$")
perl_assign_cleanup = re.compile("^( *)((?:my |our )?[^ ]+)( *)(=(?!>))( *)([^ ].*)$")
perl_function = re.compile("^ *sub ([A-Za-z_][A-Za-z0-9_]*)")
# python regexes
python_base = re.compile("^[^ ]")
python_dict_cleanup = re.compile(r"^( *)((?:[^'\":]|'(?:\.|[^\'])*'|\"(?:\.|[^\'])*)+?)( *)(:)( *)([^ ].*)$")
python_assign_cleanup = re.compile("^( *)([^ ]+)( *)(=)( *)([^ ].*)$")
python_scope = re.compile('^( *)(class|def) ([A-Za-z_][A-Za-z0-9_]*)')
python_indent = re.compile('^( *)')