From 9a9afb6ef6aedf8c3a34356b09e537b14be755dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20=C5=A0karvada?= Date: Tue, 4 Apr 2017 13:52:51 +0200 Subject: [PATCH] builtin functions: improved parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parser rewritten to use pushdown automaton, now it can correctly parse e.g. the following: [variables] cores1=2-5 isolated_cores=${f:cpulist_pack:${f:cpulist_unpack:${cores1}}},${f:cpulist_unpack:6-8} I.e. nested functions are no problem now, multiple functions on the same level also works and it correctly skips unexpanded variables. It's also possible to prevent function expansion by escaping: v=\${f:f1\} Variables expansion could be now probably also moved to this automaton and all could be expanded in one step, but for now keeping it as is (i.e. two steps expansion). Signed-off-by: Jaroslav Škarvada --- tuned/profiles/functions/functions.py | 81 ++++++++++++++++++++------- 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/tuned/profiles/functions/functions.py b/tuned/profiles/functions/functions.py index 71bf112..68ce234 100644 --- a/tuned/profiles/functions/functions.py +++ b/tuned/profiles/functions/functions.py @@ -17,32 +17,73 @@ class Functions(): def __init__(self): self._repository = repository.Repository() + self._parse_init() - def sub_func(self, mo): - sorig = mo.string[mo.start():mo.end()] - if mo.lastindex != 1: - return sorig - s = mo.string[mo.start(1):mo.end(1)] - if len(s) == 0: - return sorig - sl = re.split(r'(?