From b7331d8984629b8115199b2e0f1de331219df9cc Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 14 Mar 2014 21:41:17 +0100 Subject: fix tree eval errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- examples/lisp-esque | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/lisp-esque b/examples/lisp-esque index 36b02d2..8b42d6e 100644 --- a/examples/lisp-esque +++ b/examples/lisp-esque @@ -145,7 +145,7 @@ def _monitors(mods, args): @param mods:[] Not used @param args:list Indices of outputs, : or : or 'nil', empty for all ''' - pass + print('Selected monitors: %s' % ','.join(evaluate_tree(args, True))) def _crtc(mods, args): @@ -590,27 +590,33 @@ def evaluate_tree(elements, implied_functions = True): if elements[0] == '.': elements = elements[1:] else: - cand = elements[0].split(':')[0] - if cand in functions.keys(): - elements = ['0' + elements[0], elements[1:]] - for i in range(len(elements)): + if isinstance(elements[0], str): + cand = elements[0].split(':')[0] + if cand in functions.keys(): + elements = [':' + elements[0], elements[1:]] + i, n = 0, len(elements) + while i < n: element = elements[i] - if element.startswith(':'): + if isinstance(element, str) and element.startswith(':'): if i + 1 < len(elements): args = elements[i + 1] i += 1 if isinstance(args, str): args = [args] - element = element[0].split(':') - rc += functions[element[0]](element[1:], args) + element = element[1:].split(':') + ret = functions[element[0]](element[1:], args) + if ret is not None: + rc += ret else: - if not isinstance(args, str): + if not isinstance(element, str): element = evaluate_tree(element, implied_functions) - rc.append(element) + if element is not None: + rc.append(element) + i += 1 return rc # Evaluate tree -parse_tree(conf, True) +evaluate_tree(conf, True) conf = None -- cgit v1.2.3-70-g09d2