pmacs3/regex.py

35 lines
1.2 KiB
Python
Raw Normal View History

2007-03-06 10:05:38 -05:00
import re
# 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
2007-07-11 04:55:54 -04:00
meta_chars = re.compile(r'([\.\^\$\*\+\?\{\}\(\)\[\]\|\"\'\\,])')
# shell
shell_command = re.compile(r'^[^ ]+')
2007-03-06 10:05:38 -05:00
# whitespace regexes
leading_whitespace = re.compile('^ *')
trailing_whitespace = re.compile(' *$')
whitespace = re.compile('^[ \n]*$')
space = re.compile('^ *$')
2007-10-30 16:25:14 -04:00
leading_whitespace2 = re.compile('^( *?)(.*?)\n?$')
2007-03-06 10:05:38 -05:00
# 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(r"^( *)((?:my |our )?[^ ]+)( *)(=(?!>))( *)([^ ].*)$")
perl_function = re.compile(r"^ *sub ([A-Za-z_][A-Za-z0-9_]*)")
2007-03-06 10:05:38 -05:00
# python regexes
python_base = re.compile(r"^[^ ]")
python_dict_cleanup = re.compile(r"^( *)((?:[^'\":]|'(?:\.|[^\'])*'|\"(?:\.|[^\'])*)+?)( *)(:)( *)([^ ].*)$")
python_assign_cleanup = re.compile(r"^( *)([^ ]+)( *)(=)( *)([^ ].*)$")