From 86a3c2da10491f7cec96a9c2720a5cd92b8aad67 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Mon, 2 Jul 2018 04:23:50 +0200 Subject: Refactor tokenization a bit Have _tokenize() take the string to tokenize and return a list of tokens, and handle all the token list management outside. Simplifies the internal logic a bit. Likely faster too. --- testsuite.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'testsuite.py') diff --git a/testsuite.py b/testsuite.py index 64b5bd9..536a98f 100644 --- a/testsuite.py +++ b/testsuite.py @@ -190,15 +190,15 @@ def run_selftests(): # Dummy empty configuration just to get a Kconfig object c = Kconfig("Kconfiglib/tests/empty") - def verify_string_lex(s, res): + def verify_string_lex(s, expected): """ Verifies that a constant symbol with the name 'res' is produced from lexing 's' """ - c.eval_string(s) - verify(c._tokens[0].name == res, + res = c._tokenize("if " + s)[1].name + verify(res == expected, "expected <{}> to produced the constant symbol <{}>, " - 'produced <{}>'.format(s[1:-1], c._tokens[0].name, res)) + 'produced <{}>'.format(s[1:-1], expected, res)) verify_string_lex(r""" "" """, "") verify_string_lex(r""" '' """, "") @@ -1046,9 +1046,9 @@ g def verify_split(to_split, op, operand_strs): # The same hackage as in Kconfig.eval_string() - c._line = "if " + to_split - c._tokenize() - del c._tokens[0] + c._tokens = c._tokenize("if " + to_split)[1:] + c._tokens_i = -1 + operands = split_expr(c._parse_expr(False), op) verify(len(operands) == len(operand_strs), -- cgit v1.2.3