32 lines
1.5 KiB
Python
32 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from re import Pattern as REPattern, compile as re_compile, IGNORECASE as RE_IGNORECASE, Match as REMatch
|
|
|
|
class RE:
|
|
KEY:REPattern = re_compile(r'^[a-z_][a-z0-9_]*$', RE_IGNORECASE)
|
|
SLASHES:REPattern = re_compile(r'[\\/]+')
|
|
LAST_PATH_ITEM:REPattern = re_compile(r'[\\/][^\\/]+[\\/]?$')
|
|
STRING_VARIABLE:REPattern = re_compile(r'\{([a-z_][a-z0-9_]*)\}', RE_IGNORECASE)
|
|
COMMAND:REPattern = re_compile(r'^([^ \s]+)(?:[ \t]+(.*))?$')
|
|
COMMAND_ARGUMENT:REPattern = re_compile(r'([^\s"\'=]+)(?:=(?:"((?:[^\\"]+|\\.)*)"|\'((?:[^\\\']+|\\.)*)\'|([^\s]+))?)?|"((?:[^\\"]+|\\.)*)"|\'((?:[^\\\']+|\\.)*)\'')
|
|
TO_KEY:REPattern = re_compile(r'[^a-z0-9_]+', RE_IGNORECASE)
|
|
EXCEPTION:REPattern = re_compile(r'^\s*File "([^"]+)", line ([0-9]+), in ([^\n]+)(.*|[\r\n]*)*$')
|
|
BREAK_LINES:REPattern = re_compile(r'\r\n|[\r\n]')
|
|
SQL_LITE:REPattern = re_compile(r'(\-{2}[^\r\n]+|\/\*(?:(?!(?:\*\/))(?:.|[\r\n]+))+(?:\*\/)?)|([^;"\']+)|("(?:(?:[^"]+|""|[\r\n]+)*)"|\'(?:(?:[^\']+|\'{2}|[\r\n]+)*)\')|(;)')
|
|
FILE_PATH:REPattern = re_compile(r'^(?:([^\@\:]+)?(?:\:([^\@]*))?\@)?(?:([^\:]+)(?:\:([0-9]+))?\:)?(.+)$')
|
|
|
|
@staticmethod
|
|
def get_all(
|
|
regex:REPattern,
|
|
string:str
|
|
) -> list[tuple[str|None, ...]]:
|
|
|
|
blocks:list[tuple[str|None, ...]] = []
|
|
matches:REMatch|None
|
|
|
|
while (matches := regex.search(string)) is not None:
|
|
blocks.append(matches.groups())
|
|
string = string[matches.end():]
|
|
|
|
return blocks |