Skip to content

Commit 040221e

Browse files
committed
feat: Add SUB command to CaseAction
1 parent a200479 commit 040221e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/cedarscript_ast_parser/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CreateCommand, RmFileCommand, MvFileCommand, UpdateCommand,
66
SelectCommand, IdentifierFromFile, SingleFileClause, Segment, Marker, BodyOrWhole, MarkerType, RelativeMarker,
77
RelativePositionType, MoveClause, DeleteClause, InsertClause, ReplaceClause, EditingAction, Region,
8-
WhereClause, RegionClause, EdScript
8+
WhereClause, RegionClause, EdScript, CaseStatement, CaseWhen, CaseAction, LoopControl
99
)
1010

1111
__all__ = [
@@ -14,6 +14,7 @@
1414
"CreateCommand", "RmFileCommand", "MvFileCommand", "UpdateCommand",
1515
"SelectCommand", "IdentifierFromFile", "SingleFileClause", "Segment", "Marker", "BodyOrWhole", "MarkerType",
1616
"RelativeMarker", "RelativePositionType", "MoveClause", "DeleteClause", "InsertClause", "ReplaceClause",
17-
"EditingAction", "Region", "WhereClause", "RegionClause", "EdScript"
17+
"EditingAction", "Region", "WhereClause", "RegionClause", "EdScript", "CaseStatement", "CaseWhen", "CaseAction",
18+
"LoopControl"
1819
]
1920

src/cedarscript_ast_parser/cedarscript_ast_parser.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ class CaseAction:
255255
"""Represents a THEN action in a CASE statement"""
256256
loop_control: LoopControl | None = None
257257
remove: bool = False
258-
replace: str | None = None
258+
sub_pattern: str | None = None # For SUB command pattern
259+
sub_repl: str | None = None # For SUB command replacement
259260
indent: int | None = None
260261
content: Optional[str | tuple[Region, int | None]] = None
261262

@@ -716,8 +717,10 @@ def parse_case_action(self, node) -> CaseAction:
716717
# Parse other action types
717718
if self.find_first_by_field_name(node, 'remove'):
718719
action.remove = True
719-
elif replace := self.find_first_by_field_name(node, 'replace'):
720-
action.replace = self.parse_string(replace)
720+
elif pattern := self.find_first_by_field_name(node, 'pattern'):
721+
action.sub_pattern = re.compile(self.parse_string(pattern))
722+
if repl := self.find_first_by_field_name(node, 'repl'):
723+
action.sub_repl = self.parse_string(repl)
721724
elif indent := self.find_first_by_field_name(node, 'indent'):
722725
action.indent = int(indent.text)
723726
else:

0 commit comments

Comments
 (0)