parse_full_access_path can match floats inside brackets now

This commit is contained in:
Mose Müller 2024-04-26 09:42:26 +02:00
parent 1ee6a299b2
commit 25e578fbba

View File

@ -50,9 +50,7 @@ def parse_serialized_key(serialized_key: str) -> str | int | float:
def parse_full_access_path(path: str) -> list[str]: def parse_full_access_path(path: str) -> list[str]:
""" """
Splits a full access path into its atomic parts, separating attribute names, numeric Splits a full access path into its atomic parts, separating attribute names, numeric
indices, and string keys within indices. indices (including floating points), and string keys within indices.
The reverse function is given by `get_path_from_path_parts`.
Args: Args:
path: str path: str
@ -63,10 +61,13 @@ def parse_full_access_path(path: str) -> list[str]:
A list of components that make up the path, including attribute names, A list of components that make up the path, including attribute names,
numeric indices, and string keys as separate elements. numeric indices, and string keys as separate elements.
""" """
# <word_with_underscore> | [<any number of digits>] # Matches:
# | ["<anything except ">"] # \w+ - Words
# | ['<anything except '>'] # \[\d+\.\d+\] - Floating point numbers inside brackets
pattern = r'\w+|\[\d+\]|\["[^"]*"\]|\[\'[^\']*\']' # \[\d+\] - Integers inside brackets
# \["[^"]*"\] - Double-quoted strings inside brackets
# \['[^']*'\] - Single-quoted strings inside brackets
pattern = r'\w+|\[\d+\.\d+\]|\[\d+\]|\["[^"]*"\]|\[\'[^\']*\']'
return re.findall(pattern, path) return re.findall(pattern, path)