[RFC PATCH 1/3] dts: add find float method to text parser
Andrew Bailey
abailey at iol.unh.edu
Mon Jan 5 20:06:45 CET 2026
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 at 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
More information about the dev
mailing list