r"""Reads one section from the given text. section -> block | assignment | line >>> read_section = Parser().read_section >>> read_section('foo\nbar\n') ( , 'bar\n') >>> read_section('$ a = b + 1\nfoo\n') (<assignm
(self, text)
| 100 | return "", text |
| 101 | |
| 102 | def read_section(self, text): |
| 103 | r"""Reads one section from the given text. |
| 104 | |
| 105 | section -> block | assignment | line |
| 106 | |
| 107 | >>> read_section = Parser().read_section |
| 108 | >>> read_section('foo\nbar\n') |
| 109 | (<line: [t'foo\n']>, 'bar\n') |
| 110 | >>> read_section('$ a = b + 1\nfoo\n') |
| 111 | (<assignment: 'a = b + 1'>, 'foo\n') |
| 112 | |
| 113 | read_section('$for in range(10):\n hello $i\nfoo) |
| 114 | """ |
| 115 | if text.lstrip(" ").startswith("$"): |
| 116 | index = text.index("$") |
| 117 | begin_indent, text2 = text[:index], text[index + 1 :] |
| 118 | ahead = self.python_lookahead(text2) |
| 119 | |
| 120 | if ahead == "var": |
| 121 | return self.read_var(text2) |
| 122 | elif ahead in self.statement_nodes: |
| 123 | return self.read_block_section(text2, begin_indent) |
| 124 | elif ahead in self.keywords: |
| 125 | return self.read_keyword(text2) |
| 126 | elif ahead.strip() == "": |
| 127 | # assignments starts with a space after $ |
| 128 | # ex: $ a = b + 2 |
| 129 | return self.read_assignment(text2) |
| 130 | return self.readline(text) |
| 131 | |
| 132 | def read_var(self, text): |
| 133 | r"""Reads a var statement. |
no test coverage detected