Split user input into initial whitespace, escape character, function part and the rest.
(
line: str, pattern: re.Pattern[str] | None = None
)
| 41 | |
| 42 | |
| 43 | def split_user_input( |
| 44 | line: str, pattern: re.Pattern[str] | None = None |
| 45 | ) -> tuple[str, str, str, str]: |
| 46 | """Split user input into initial whitespace, escape character, function part |
| 47 | and the rest. |
| 48 | """ |
| 49 | assert isinstance(line, str) |
| 50 | |
| 51 | if pattern is None: |
| 52 | pattern = line_split |
| 53 | match = pattern.match(line) |
| 54 | if not match: |
| 55 | # print("match failed for line '%s'" % line) |
| 56 | try: |
| 57 | ifun, the_rest = line.split(None, 1) |
| 58 | except ValueError: |
| 59 | # print("split failed for line '%s'" % line) |
| 60 | ifun, the_rest = line, "" |
| 61 | pre = re.match(r"^(\s*)(.*)", line).groups()[0] |
| 62 | esc = "" |
| 63 | else: |
| 64 | pre, esc, ifun, the_rest = match.groups() |
| 65 | |
| 66 | # print('line:<%s>' % line) # dbg |
| 67 | # print('pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest)) # dbg |
| 68 | return pre, esc or "", ifun.strip(), the_rest |
| 69 | |
| 70 | |
| 71 | class LineInfo: |
searching dependent graphs…