scripts: dtlib: Suppress _init_tokens() pylint warning

Suppress this pylint warning so that it can be enabled in the upcoming
CI check. The code is safe.

    scripts/dts/dtlib.py:1904:13: W0631: Using possibly undefined loop
    variable 'i' (undefined-loop-variable)

Also add some more comments to clarify _init_tokens().

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
This commit is contained in:
Ulf Magnusson 2019-09-05 13:00:48 +02:00 committed by Kumar Gala
commit ba76b82f5a

View file

@ -1881,6 +1881,10 @@ _line_re = re.compile(
def _init_tokens(): def _init_tokens():
# Builds a (<token 1>)|(<token 2>)|... regex and assigns the index of each
# capturing group to a corresponding _T_<TOKEN> variable. This makes the
# token type appear in match.lastindex after a match.
global _token_re global _token_re
global _T_NUM global _T_NUM
global _T_PROPNODENAME global _T_PROPNODENAME
@ -1888,6 +1892,9 @@ def _init_tokens():
global _T_BYTE global _T_BYTE
global _T_BAD global _T_BAD
# Each pattern must have exactly one capturing group, which can capture any
# part of the pattern. This makes match.lastindex match the token type.
# _Token.val is based on the captured string.
token_spec = (("_T_INCLUDE", r'(/include/\s*"(?:[^\\"]|\\.)*")'), token_spec = (("_T_INCLUDE", r'(/include/\s*"(?:[^\\"]|\\.)*")'),
("_T_LINE", # #line directive ("_T_LINE", # #line directive
r'^#(?:line)?[ \t]+([0-9]+[ \t]+"(?:[^\\"]|\\.)*")(?:[ \t]+[0-9]+)?'), r'^#(?:line)?[ \t]+([0-9]+[ \t]+"(?:[^\\"]|\\.)*")(?:[ \t]+[0-9]+)?'),
@ -1918,6 +1925,7 @@ def _init_tokens():
for i, spec in enumerate(token_spec, 1): for i, spec in enumerate(token_spec, 1):
globals()[spec[0]] = i globals()[spec[0]] = i
# pylint: disable=undefined-loop-variable
_T_NUM = i + 1 _T_NUM = i + 1
_T_PROPNODENAME = i + 2 _T_PROPNODENAME = i + 2
_T_MISC = i + 3 _T_MISC = i + 3