summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-05-17 23:22:41 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-05-17 23:48:35 +0200
commit9ba9db78b2d3d0cf1c24e6e0929f5850940234dd (patch)
tree23a5ef2d4d3fc142ebf47266d2f5695aac5b19b6 /kconfiglib.py
parentc6cb812803741f5e499a2f35673b34a45f575582 (diff)
Move help text parsing into a separate function
More readable.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py107
1 files changed, 54 insertions, 53 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index dba97f1..f3624c4 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -2128,59 +2128,7 @@ class Kconfig(object):
node.dep = self._make_and(node.dep, self._parse_expr(True))
elif t0 == _T_HELP:
- # Find first non-blank (not all-space) line and get its
- # indentation
-
- if node.help is not None:
- self._warn("{} defined with more than one help text -- "
- "only the last one will be used"
- .format(_name_and_loc(node.item)))
-
- # Small optimization. This code is pretty hot.
- readline = self._file.readline
-
- while 1:
- line = readline()
- self._linenr += 1
- if not line or not line.isspace():
- break
-
- if not line:
- self._warn("{} has 'help' but empty help text"
- .format(_name_and_loc(node.item)))
-
- node.help = ""
- break
-
- indent = _indentation(line)
- if indent == 0:
- # If the first non-empty lines has zero indent, there is no
- # help text
- self._warn("{} has 'help' but empty help text"
- .format(_name_and_loc(node.item)))
-
- node.help = ""
- self._saved_line = line # "Unget" the line
- break
-
- help_lines = [_dedent_rstrip(line, indent)]
- # Small optimization
- add_help_line = help_lines.append
-
- # The help text goes on till the first non-empty line with less
- # indent
-
- while 1:
- line = readline()
- self._linenr += 1
- if not (line and (line.isspace() or \
- _indentation(line) >= indent)):
- break
-
- add_help_line(_dedent_rstrip(line, indent))
-
- node.help = "\n".join(help_lines).rstrip() + "\n"
- self._saved_line = line # "Unget" the line
+ self._parse_help(node)
elif t0 == _T_SELECT:
if not isinstance(node.item, Symbol):
@@ -2305,6 +2253,59 @@ class Kconfig(object):
node.prompt = (self._expect_str(), self._parse_cond())
+ def _parse_help(self, node):
+ # Find first non-blank (not all-space) line and get its indentation
+
+ if node.help is not None:
+ self._warn("{} defined with more than one help text -- only the "
+ "last one will be used"
+ .format(_name_and_loc(node.item)))
+
+ # Small optimization. This code is pretty hot.
+ readline = self._file.readline
+
+ while 1:
+ line = readline()
+ self._linenr += 1
+ if not line or not line.isspace():
+ break
+
+ if not line:
+ self._warn("{} has 'help' but empty help text"
+ .format(_name_and_loc(node.item)))
+
+ node.help = ""
+ return
+
+ indent = _indentation(line)
+ if indent == 0:
+ # If the first non-empty lines has zero indent, there is no help
+ # text
+ self._warn("{} has 'help' but empty help text"
+ .format(_name_and_loc(node.item)))
+
+ node.help = ""
+ self._saved_line = line # "Unget" the line
+ return
+
+ help_lines = [_dedent_rstrip(line, indent)]
+ # Small optimization
+ add_help_line = help_lines.append
+
+ # The help text goes on till the first non-empty line with less indent
+
+ while 1:
+ line = readline()
+ self._linenr += 1
+ if not (line and (line.isspace() or \
+ _indentation(line) >= indent)):
+ break
+
+ add_help_line(_dedent_rstrip(line, indent))
+
+ node.help = "\n".join(help_lines).rstrip() + "\n"
+ self._saved_line = line # "Unget" the line
+
def _parse_expr(self, transform_m):
# Parses an expression from the tokens in Kconfig._tokens using a
# simple top-down approach. See the module docstring for the expression