DPDK patches and discussions
 help / color / mirror / Atom feed
* [RFC PATCH 1/3] dts: add find float method to text parser
@ 2026-01-05 19:06 Andrew Bailey
  2026-01-05 19:06 ` [RFC PATCH 2/3] dts: add cryptodev package to dts Andrew Bailey
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andrew Bailey @ 2026-01-05 19:06 UTC (permalink / raw)
  To: luca.vizzarro; +Cc: probb, dmarx, dev, Andrew Bailey

Currently, there is no way to gather floats from text using the parser.
Adding a new method to find floats will allow testsuites to utilize
valuable float values that are output from applications.

Signed-off-by: Andrew Bailey <abailey@iol.unh.edu>
---
 dts/framework/parser.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/dts/framework/parser.py b/dts/framework/parser.py
index 4170cdb1dd..3075c36857 100644
--- a/dts/framework/parser.py
+++ b/dts/framework/parser.py
@@ -220,6 +220,34 @@ def find_int(
 
         return TextParser.wrap(TextParser.find(pattern), partial(int, base=int_base))
 
+    @staticmethod
+    def find_float(
+        pattern: str | re.Pattern[str],
+        flags: re.RegexFlag = re.RegexFlag(0),
+    ) -> ParserFn:
+        """Makes a parser function that converts the match of :meth:`~find` to float.
+
+        This function is compatible only with a pattern containing one capturing group.
+
+        Args:
+            pattern: The regular expression pattern.
+            flags: The regular expression flags. Ignored if the given pattern is already compiled.
+
+        Raises:
+            InternalError: If the pattern does not have exactly one capturing group.
+
+        Returns:
+            ParserFn: A dictionary for the `dataclasses.field` metadata argument containing the
+                :meth:`~find` parser function wrapped by the float built-in.
+        """
+        if isinstance(pattern, str):
+            pattern = re.compile(pattern, flags)
+
+        if pattern.groups != 1:
+            raise InternalError("only one capturing group is allowed with this parser function")
+
+        return TextParser.wrap(TextParser.find(pattern), partial(float))
+
     """============ END PARSER FUNCTIONS ============"""
 
     @classmethod
-- 
2.50.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-01-08 16:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 19:06 [RFC PATCH 1/3] dts: add find float method to text parser Andrew Bailey
2026-01-05 19:06 ` [RFC PATCH 2/3] dts: add cryptodev package to dts Andrew Bailey
2026-01-05 19:06 ` [RFC PATCH 3/3] dts: add cryptodev testsuite Andrew Bailey
2026-01-07 22:25   ` Patrick Robb
2026-01-08 16:29     ` Andrew Bailey
2026-01-07 23:05   ` Patrick Robb
2026-01-07 23:05 ` [RFC PATCH 1/3] dts: add find float method to text parser Patrick Robb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).