From d6caa88f99de2f5460ce7bb623a54e1369751e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A1ta=20Hodov=C3=A1n?= Date: Fri, 20 Dec 2024 19:11:22 +0100 Subject: [PATCH] Simplify simple_space_serializer using `tokens()` method (#263) The new `tokens()` method of rule nodes makes it easier to access their leaf node sequences. This update leverages the `tokens()` method to simplify the implementation of `simple_space_serializer`. --- grammarinator/runtime/serializer.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/grammarinator/runtime/serializer.py b/grammarinator/runtime/serializer.py index 6965339..0d116de 100644 --- a/grammarinator/runtime/serializer.py +++ b/grammarinator/runtime/serializer.py @@ -1,12 +1,10 @@ -# Copyright (c) 2017-2023 Renata Hodovan, Akos Kiss. +# Copyright (c) 2017-2024 Renata Hodovan, Akos Kiss. # # Licensed under the BSD 3-Clause License # . # This file may not be copied, modified, or distributed except # according to those terms. -from .rule import ParentRule - def simple_space_serializer(root): """ @@ -17,14 +15,4 @@ def simple_space_serializer(root): :return: The serialized tree as string. :rtype: str """ - - def _tokens(): - stack = [root] - while stack: - node = stack.pop() - if isinstance(node, ParentRule): - stack.extend(reversed(node.children)) - else: - yield node.src - - return ' '.join(token for token in _tokens()) + return ' '.join(root.tokens())