summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-11-23 02:11:34 +0100
committerUlf Magnusson <ulfalizer@gmail.com>2018-11-23 10:33:23 +0100
commit13a7bae7719c17b43fca5e3c61ff18a225fc6422 (patch)
treeb6a2a0830d4fc6f71c591217540bf41c02419258 /kconfiglib.py
parentab89ef6aa7b8fef0eb410949c86a25e55586a972 (diff)
Flag extra trailing tokens in all contexts
The following cases were let through without a parse error (with the extra tokens just being ignored): - endif/endmenu/enchoice <extra tokens> - default FOO <extra tokens> (though 'default FOO if' flagged an error) Make them generate an error.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index f0abe11..5a5659c 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -2117,7 +2117,7 @@ class Kconfig(object):
self._parse_error("expected nonconstant symbol")
if self._tokens[self._tokens_i] is not None:
- self._parse_error("extra tokens at end of line")
+ self._trailing_tokens_error()
return token
@@ -2138,7 +2138,7 @@ class Kconfig(object):
self._parse_error("expected string")
if self._tokens[self._tokens_i] is not None:
- self._parse_error("extra tokens at end of line")
+ self._trailing_tokens_error()
return token
@@ -2146,7 +2146,7 @@ class Kconfig(object):
expr = self._parse_expr(True)
if self._tokens[self._tokens_i] is not None:
- self._parse_error("extra tokens at end of line")
+ self._trailing_tokens_error()
return expr
@@ -2555,6 +2555,10 @@ class Kconfig(object):
elif t0 is end_token:
# We have reached the end of the block. Terminate the final
# node and return it.
+
+ if self._tokens[self._tokens_i] is not None:
+ self._trailing_tokens_error()
+
prev.next = None
return prev
@@ -2669,8 +2673,12 @@ class Kconfig(object):
# Parses an optional 'if <expr>' construct and returns the parsed
# <expr>, or self.y if the next token is not _T_IF
- return self._expect_expr_and_eol() if self._check_token(_T_IF) \
- else self.y
+ expr = self._parse_expr(True) if self._check_token(_T_IF) else self.y
+
+ if self._tokens[self._tokens_i] is not None:
+ self._trailing_tokens_error()
+
+ return expr
def _parse_properties(self, node):
# Parses and adds properties to the MenuNode 'node' (type, 'prompt',
@@ -3424,13 +3432,13 @@ class Kconfig(object):
.format(_name_and_loc(sym)))
def _parse_error(self, msg):
- if self._filename is None:
- loc = ""
- else:
- loc = "{}:{}: ".format(self._filename, self._linenr)
+ raise KconfigError("{}couldn't parse '{}': {}".format(
+ "" if self._filename is None else
+ "{}:{}: ".format(self._filename, self._linenr),
+ self._line.strip(), msg))
- raise KconfigError(
- "{}couldn't parse '{}': {}".format(loc, self._line.rstrip(), msg))
+ def _trailing_tokens_error(self):
+ self._parse_error("extra tokens at end of line")
def _open(self, filename, mode):
# open() wrapper: