MCPcopy Create free account
hub / github.com/webpy/webpy / read_section

Method read_section

web/template.py:102–130  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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(&#x27;$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.

Callers 1

read_suiteMethod · 0.95

Calls 6

python_lookaheadMethod · 0.95
read_varMethod · 0.95
read_block_sectionMethod · 0.95
read_keywordMethod · 0.95
read_assignmentMethod · 0.95
readlineMethod · 0.95

Tested by

no test coverage detected