From ed4a71fce7137c42fdaa4113871dd00c878b4956 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= <hugo@lysator.liu.se>
Date: Tue, 19 Sep 2023 12:12:51 +0200
Subject: [PATCH] Greatly limit the debug verbosity when parsing strings.

Previously, all possible parse instances of a string were shown, which
included the unquoted, single quoted, and double quoted versions,
meaning that "always" was shown as:

    string(([ws] & ('always'
		    | ("'" & ['a', 'l', 'w', 'a', 'y', 's'] & "'")
		    | ('"' & [rich_char(c='a'), rich_char(c='l'), rich_char(c='w'), rich_char(c='a'), rich_char(c='y'), rich_char(c='s')] & '"'))))

This changes the output to:

    string([frequency])
---
 muppet/puppet/format/parser.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/muppet/puppet/format/parser.py b/muppet/puppet/format/parser.py
index 3fcf3b3..e4d3451 100644
--- a/muppet/puppet/format/parser.py
+++ b/muppet/puppet/format/parser.py
@@ -575,10 +575,11 @@ class ParserFormatter(Serializer[ParseDirective]):
         double_quoted = s('"') & [rich_char(c) for c in it.s] & '"'
 
         if it.s == '':
-            parser = ws & (single_quoted | double_quoted)
+            parser = (single_quoted | double_quoted)
         else:
-            parser = ws & (raw_string | single_quoted | double_quoted)
-        return tag('string', parser)
+            parser = (raw_string | single_quoted | double_quoted)
+        # TODO should the whitespace really be here?
+        return ws & tag('string', name(it.s, parser))
 
     @override
     def _puppet_unary_operator(self, it: PuppetUnaryOperator) -> ParseDirective:
-- 
GitLab