r""" Represents a single block of text embedded in another file. If dsl_name is None, the block represents verbatim text, raw original text from the file, in which case "input" will be the only non-false member. If dsl_name is not None, the block represents a Clinic block.
| 14 | |
| 15 | @dc.dataclass(slots=True, repr=False) |
| 16 | class Block: |
| 17 | r""" |
| 18 | Represents a single block of text embedded in |
| 19 | another file. If dsl_name is None, the block represents |
| 20 | verbatim text, raw original text from the file, in |
| 21 | which case "input" will be the only non-false member. |
| 22 | If dsl_name is not None, the block represents a Clinic |
| 23 | block. |
| 24 | |
| 25 | input is always str, with embedded \n characters. |
| 26 | input represents the original text from the file; |
| 27 | if it's a Clinic block, it is the original text with |
| 28 | the body_prefix and redundant leading whitespace removed. |
| 29 | |
| 30 | dsl_name is either str or None. If str, it's the text |
| 31 | found on the start line of the block between the square |
| 32 | brackets. |
| 33 | |
| 34 | signatures is a list. |
| 35 | It may only contain clinic.Module, clinic.Class, and |
| 36 | clinic.Function objects. At the moment it should |
| 37 | contain at most one of each. |
| 38 | |
| 39 | output is either str or None. If str, it's the output |
| 40 | from this block, with embedded '\n' characters. |
| 41 | |
| 42 | indent is a str. It's the leading whitespace |
| 43 | that was found on every line of input. (If body_prefix is |
| 44 | not empty, this is the indent *after* removing the |
| 45 | body_prefix.) |
| 46 | |
| 47 | "indent" is different from the concept of "preindent" |
| 48 | (which is not stored as state on Block objects). |
| 49 | "preindent" is the whitespace that |
| 50 | was found in front of every line of input *before* the |
| 51 | "body_prefix" (see the Language object). If body_prefix |
| 52 | is empty, preindent must always be empty too. |
| 53 | |
| 54 | To illustrate the difference between "indent" and "preindent": |
| 55 | |
| 56 | Assume that '_' represents whitespace. |
| 57 | If the block processed was in a Python file, and looked like this: |
| 58 | ____#/*[python] |
| 59 | ____#__for a in range(20): |
| 60 | ____#____print(a) |
| 61 | ____#[python]*/ |
| 62 | "preindent" would be "____" and "indent" would be "__". |
| 63 | |
| 64 | """ |
| 65 | input: str |
| 66 | dsl_name: str | None = None |
| 67 | signatures: list[Module | Class | Function] = dc.field(default_factory=list) |
| 68 | output: Any = None # TODO: Very dynamic; probably untypeable in its current form? |
| 69 | indent: str = '' |
| 70 | |
| 71 | def __repr__(self) -> str: |
| 72 | dsl_name = self.dsl_name or "text" |
| 73 | def summarize(s: object) -> str: |
searching dependent graphs…