reprexlite.parsing¶
Classes¶
LineType ¶
Bases: Enum
An enum for different types of lines in text input to parse.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
CODE
|
str
|
Line is code. |
required |
RESULT
|
str
|
Line is the result of executing code. |
required |
Functions¶
auto_parse ¶
auto_parse(input: str) -> Iterator[Tuple[str, LineType]]
Automatically parse input that is either doctest-style and reprex-style.
Source code in reprexlite/parsing.py
114 115 116 117 118 119 |
|
parse ¶
parse(
input: str,
prompt: Optional[str],
continuation: Optional[str],
comment: Optional[str],
) -> Iterator[Tuple[str, LineType]]
Generator function that parses input into lines of code or results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input
|
str
|
String to parse |
required |
prompt
|
Optional[str]
|
Prefix used as primary prompt of code lines |
required |
continuation
|
Optional[str]
|
Prefix used as continuation prompt of code lines |
required |
comment
|
Optional[str]
|
Prefix used to indicate result lines |
required |
Yields:
Type | Description |
---|---|
Tuple[str, LineType]
|
Iterator[Tuple[str, LineType]]: tuple of parsed line and line type |
Source code in reprexlite/parsing.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
parse_doctest ¶
parse_doctest(input: str) -> Iterator[Tuple[str, LineType]]
Wrapper around parse for parsing doctest-style input.
Source code in reprexlite/parsing.py
109 110 111 |
|
parse_reprex ¶
parse_reprex(input: str) -> Iterator[Tuple[str, LineType]]
Wrapper around parse for parsing reprex-style input.
Source code in reprexlite/parsing.py
104 105 106 |
|
removeprefix ¶
removeprefix(s: str, prefix: str) -> str
Utility function to strip a prefix from a string, whether or not there is a single whitespace character.
Source code in reprexlite/parsing.py
12 13 14 15 16 17 18 19 20 21 22 23 |
|