summaryrefslogtreecommitdiff
path: root/kconfiglib.py
diff options
context:
space:
mode:
authorUlf Magnusson <ulfalizer@gmail.com>2018-07-01 23:40:15 +0200
committerUlf Magnusson <ulfalizer@gmail.com>2018-07-02 00:31:20 +0200
commit0c28974bedd21e5c992ae9667e75f800dc04fe32 (patch)
tree1aee41104e8d194bcccdb0c9ef6830e31fa980cf /kconfiglib.py
parentc19fc11355b13d75d97286402c7a933fb23d3b70 (diff)
Number tokens from 1 to simplify some checks
This makes all tokens except empty strings truthy, getting rid of some 'is (not) None' checks.
Diffstat (limited to 'kconfiglib.py')
-rw-r--r--kconfiglib.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/kconfiglib.py b/kconfiglib.py
index 461fc31..b851a40 100644
--- a/kconfiglib.py
+++ b/kconfiglib.py
@@ -1593,7 +1593,7 @@ class Kconfig(object):
# Tricky implementation detail: While parsing a token, 'token' refers
# to the previous token. See _STRING_LEX for why this is needed.
token = _get_keyword(command_match.group(1))
- if token is None:
+ if not token:
self._parse_error("expected keyword as first token")
self._tokens = [token]
@@ -1617,7 +1617,7 @@ class Kconfig(object):
name = id_keyword_match.group(1)
keyword = _get_keyword(name)
- if keyword is not None:
+ if keyword:
# It's a keyword
token = keyword
@@ -2075,7 +2075,7 @@ class Kconfig(object):
# End of file reached. Terminate the final node and return it.
- if end_token is not None:
+ if end_token:
raise KconfigError("Unexpected end of file " + self._filename)
prev.next = None
@@ -5239,7 +5239,8 @@ STR_TO_TRI = {
# Are we running on Python 2?
_IS_PY2 = sys.version_info[0] < 3
-# Tokens
+# Tokens, with values 1, 2, ... . Avoiding 0 simplifies some checks by making
+# all tokens except empty strings truthy.
(
_T_ALLNOCONFIG_Y,
_T_AND,
@@ -5288,7 +5289,7 @@ _IS_PY2 = sys.version_info[0] < 3
_T_TRISTATE,
_T_UNEQUAL,
_T_VISIBLE,
-) = range(47)
+) = range(1, 48)
# Public integers representing expression types
#