r"""Reads a node from the given text and returns the node and remaining text. >>> read_node = Parser().read_node >>> read_node('hello $name') (t'hello ', '$name') >>> read_node('$name') ($name, '')
(self, text)
| 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. |
| 209 | |
| 210 | >>> read_node = Parser().read_node |
| 211 | >>> read_node('hello $name') |
| 212 | (t'hello ', '$name') |
| 213 | >>> read_node('$name') |
| 214 | ($name, '') |
| 215 | """ |
| 216 | if text.startswith("$$"): |
| 217 | return TextNode("$"), text[2:] |
| 218 | elif text.startswith("$#"): # comment |
| 219 | line, text = splitline(text) |
| 220 | return TextNode("\n"), text |
| 221 | elif text.startswith("$"): |
| 222 | text = text[1:] # strip $ |
| 223 | if text.startswith(":"): |
| 224 | escape = False |
| 225 | text = text[1:] # strip : |
| 226 | else: |
| 227 | escape = True |
| 228 | return self.read_expr(text, escape=escape) |
| 229 | else: |
| 230 | return self.read_text(text) |
| 231 | |
| 232 | def read_text(self, text): |
| 233 | r"""Reads a text node from the given text. |