mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
591107cdce
The logic of the `revng ptml` command was too tightly coupled with the parsing of the xml. Overhaul the structure of the ptml code and split it in two locations: * `revng.ptml`: this module contains functions that allow easy manipulation of PTML, both for printing it and for obtaining the split metadata/text version. * `revng.internal.cli._commands.ptml`: this implements the actual `revng ptml` command. This leverages the new logic in the `revng.ptml` module while maintaining the same functionality.
27 lines
718 B
Python
27 lines
718 B
Python
#
|
|
# This file is distributed under the MIT License. See LICENSE.md for details.
|
|
#
|
|
|
|
from dataclasses import dataclass
|
|
from typing import List, Optional
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Location:
|
|
"""A location is a '/'-delimited string with a type at the beginning and
|
|
one or more path components, e.g. `/function/0x1000:Code_x86_64`."""
|
|
|
|
type: str # noqa: A003
|
|
path_components: List[str]
|
|
|
|
@staticmethod
|
|
def parse(string: str) -> Optional["Location"]:
|
|
if not string.startswith("/"):
|
|
return None
|
|
|
|
parts = string.split("/")[1:]
|
|
return Location(parts[0], parts[1:])
|
|
|
|
def to_string(self) -> str:
|
|
return f"/{self.type}/{'/'.join(self.path_components)}"
|