mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Error when using multiple segments with -name->
Previously, PFERD just silently never matched the -name-> arrow. Now, it errors when loading the config file.
This commit is contained in:
parent
80eeb8fe97
commit
9ffd603357
@ -41,9 +41,11 @@ TransformResult = Optional[Union[Transformed, Ignored]]
|
|||||||
@dataclass
|
@dataclass
|
||||||
class Rule:
|
class Rule:
|
||||||
left: str
|
left: str
|
||||||
|
left_index: int
|
||||||
name: str
|
name: str
|
||||||
head: ArrowHead
|
head: ArrowHead
|
||||||
right: RightSide
|
right: RightSide
|
||||||
|
right_index: int
|
||||||
|
|
||||||
def right_result(self, path: PurePath) -> Union[str, Transformed, Ignored]:
|
def right_result(self, path: PurePath) -> Union[str, Transformed, Ignored]:
|
||||||
if isinstance(self.right, str):
|
if isinstance(self.right, str):
|
||||||
@ -345,6 +347,7 @@ def parse_eol(line: Line) -> None:
|
|||||||
|
|
||||||
def parse_rule(line: Line) -> Rule:
|
def parse_rule(line: Line) -> Rule:
|
||||||
parse_zero_or_more_spaces(line)
|
parse_zero_or_more_spaces(line)
|
||||||
|
left_index = line.index
|
||||||
left = parse_left(line)
|
left = parse_left(line)
|
||||||
|
|
||||||
parse_one_or_more_spaces(line)
|
parse_one_or_more_spaces(line)
|
||||||
@ -354,19 +357,19 @@ def parse_rule(line: Line) -> Rule:
|
|||||||
line.expect("-")
|
line.expect("-")
|
||||||
head = parse_arrow_head(line)
|
head = parse_arrow_head(line)
|
||||||
|
|
||||||
index = line.index
|
right_index = line.index
|
||||||
right: RightSide
|
right: RightSide
|
||||||
try:
|
try:
|
||||||
parse_zero_or_more_spaces(line)
|
parse_zero_or_more_spaces(line)
|
||||||
parse_eol(line)
|
parse_eol(line)
|
||||||
right = Empty()
|
right = Empty()
|
||||||
except RuleParseError:
|
except RuleParseError:
|
||||||
line.index = index
|
line.index = right_index
|
||||||
parse_one_or_more_spaces(line)
|
parse_one_or_more_spaces(line)
|
||||||
right = parse_right(line)
|
right = parse_right(line)
|
||||||
parse_eol(line)
|
parse_eol(line)
|
||||||
|
|
||||||
return Rule(left, name, head, right)
|
return Rule(left, left_index, name, head, right, right_index)
|
||||||
|
|
||||||
|
|
||||||
def parse_transformation(line: Line) -> Transformation:
|
def parse_transformation(line: Line) -> Transformation:
|
||||||
@ -377,6 +380,9 @@ def parse_transformation(line: Line) -> Transformation:
|
|||||||
elif rule.name == "exact":
|
elif rule.name == "exact":
|
||||||
return ExactTf(rule)
|
return ExactTf(rule)
|
||||||
elif rule.name == "name":
|
elif rule.name == "name":
|
||||||
|
if len(PurePath(rule.left).parts) > 1:
|
||||||
|
line.index = rule.left_index
|
||||||
|
raise RuleParseError(line, "Expected name, not multiple segments")
|
||||||
return RenamingPartsTf(ExactTf(rule))
|
return RenamingPartsTf(ExactTf(rule))
|
||||||
elif rule.name == "re":
|
elif rule.name == "re":
|
||||||
return RenamingParentsTf(ExactReTf(rule))
|
return RenamingParentsTf(ExactReTf(rule))
|
||||||
|
Loading…
Reference in New Issue
Block a user