diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2018-01-20 05:05:49 +0100 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2018-01-20 05:19:42 +0100 |
| commit | 707204ac4a5539c9b4d4875d12fec340ba95c1a2 (patch) | |
| tree | c16701e575665d6b6384aa885aae7b0d7aa915de | |
| parent | 4b8d5887667fd24dba8dee15f326f908f3ab142b (diff) | |
Get rid of _next_help_line()
Speeds things up a bit further.
Rework the unget handling to save the ungotten line directly instead of
using a flag.
Add some help texts to tests/Klocation to make sure the line number is
updated properly for those.
| -rw-r--r-- | kconfiglib.py | 32 | ||||
| -rw-r--r-- | tests/Klocation | 13 | ||||
| -rw-r--r-- | testsuite.py | 4 |
3 files changed, 28 insertions, 21 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 1a78b3a..9c5607e 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -507,12 +507,12 @@ class Kconfig(object): # Parsing-related "_parsing_kconfigs", - "_reuse_line", "_file", "_filename", "_linenr", "_filestack", "_line", + "_saved_line", "_tokens", "_tokens_i", "_has_tokens", @@ -623,7 +623,7 @@ class Kconfig(object): # Parse the Kconfig files # These implement a single line of "unget" for the parser - self._reuse_line = False + self._saved_line = None self._has_tokens = False # Keeps track of the location in the parent Kconfig files. Kconfig @@ -1154,13 +1154,14 @@ class Kconfig(object): Fetches and tokenizes the next line from the current Kconfig file. Returns False at EOF and True otherwise. """ - # This provides a single line of "unget" if _reuse_line is set to True - if not self._reuse_line: + # This provides a single line of "unget" after help texts + if self._saved_line: + self._line = self._saved_line + self._saved_line = None + else: self._line = self._file.readline() self._linenr += 1 - self._reuse_line = False - # Handle line joining while self._line.endswith("\\\n"): self._line = self._line[:-2] + self._file.readline() @@ -1172,15 +1173,6 @@ class Kconfig(object): self._tokenize() return True - def _next_help_line(self): - """ - Used for help texts, where lines are not tokenized and no line joining - is done. - """ - self._line = self._file.readline() - self._linenr += 1 - return self._line - # # Tokenization @@ -1729,7 +1721,8 @@ class Kconfig(object): # indentation while 1: - line = self._next_help_line() + line = self._file.readline() + self._linenr += 1 if not line or not line.isspace(): break @@ -1742,7 +1735,7 @@ class Kconfig(object): # If the first non-empty lines has zero indent, there is no # help text node.help = "" - self._reuse_line = True # "Unget" the line + self._saved_line = line # "Unget" the line break help_lines = [_dedent_rstrip(line, indent)] @@ -1751,7 +1744,8 @@ class Kconfig(object): # indent while 1: - line = self._next_help_line() + line = self._file.readline() + self._linenr += 1 if not (line and (line.isspace() or \ _indentation(line) >= indent)): break @@ -1763,7 +1757,7 @@ class Kconfig(object): if not line: break - self._reuse_line = True # "Unget" the line + self._saved_line = line # "Unget" the line elif t0 == _T_SELECT: if not isinstance(node.item, Symbol): diff --git a/tests/Klocation b/tests/Klocation index 737a221..3901ebf 100644 --- a/tests/Klocation +++ b/tests/Klocation @@ -13,6 +13,19 @@ if y && \ y && \ y +# Throw in some help texts too + +config HELP_1 + bool "help 1" + help +config HELP_2 + bool "help 2" + help + foo + bar + + baz + config MULTI_DEF endif diff --git a/testsuite.py b/testsuite.py index dcc5607..7219c07 100644 --- a/testsuite.py +++ b/testsuite.py @@ -766,9 +766,9 @@ g verify_locations(c.syms["MULTI_DEF"].nodes, "tests/Klocation:6", - "tests/Klocation:16", + "tests/Klocation:29", "tests/Klocation_included:3", - "tests/Klocation:32") + "tests/Klocation:45") verify_locations(c.named_choices["CHOICE"].nodes, "tests/Klocation_included:5") |
