r"""Reads one line from the text. Newline is suppressed if the line ends with \. >>> readline = Parser().readline >>> readline('hello $name!\nbye!') ( , 'bye!') >>> readline('hello $name!\\\nbye!') (<line: [t'hello ', $name, t
(self, text)
| 181 | return SuiteNode(sections) |
| 182 | |
| 183 | def readline(self, text): |
| 184 | r"""Reads one line from the text. Newline is suppressed if the line ends with \. |
| 185 | |
| 186 | >>> readline = Parser().readline |
| 187 | >>> readline('hello $name!\nbye!') |
| 188 | (<line: [t'hello ', $name, t'!\n']>, 'bye!') |
| 189 | >>> readline('hello $name!\\\nbye!') |
| 190 | (<line: [t'hello ', $name, t'!']>, 'bye!') |
| 191 | >>> readline('$f()\n\n') |
| 192 | (<line: [$f(), t'\n']>, '\n') |
| 193 | """ |
| 194 | line, text = splitline(text) |
| 195 | |
| 196 | # suppress new line if line ends with \ |
| 197 | if line.endswith("\\\n"): |
| 198 | line = line[:-2] |
| 199 | |
| 200 | nodes = [] |
| 201 | while line: |
| 202 | node, line = self.read_node(line) |
| 203 | nodes.append(node) |
| 204 | |
| 205 | return LineNode(nodes), text |
| 206 | |
| 207 | def read_node(self, text): |
| 208 | r"""Reads a node from the given text and returns the node and remaining text. |