44
55from cedarscript_ast_parser import Command , RmFileCommand , MvFileCommand , UpdateCommand , \
66 SelectCommand , CreateCommand , IdentifierFromFile , Segment , Marker , MoveClause , DeleteClause , \
7- InsertClause , ReplaceClause , EditingAction , BodyOrWhole , RegionClause , MarkerType
7+ InsertClause , ReplaceClause , EditingAction , BodyOrWhole , RegionClause , MarkerType , EdScript
8+ from ed_script_filter import process_ed_script
89from cedarscript_ast_parser .cedarscript_ast_parser import MarkerCompatible , RelativeMarker , \
910 RelativePositionType , Region , SingleFileClause
1011from text_manipulation import (
@@ -148,6 +149,13 @@ def _update_command(self, cmd: UpdateCommand):
148149
149150
150151 match content :
152+ case EdScript () as ed_script :
153+ if not isinstance (action , ReplaceClause ):
154+ raise ValueError ("ED scripts can only be used with REPLACE actions" )
155+ # Process ED script on just the lines in the search range
156+ range_lines = search_range .read (lines )
157+ processed_lines = process_ed_script (range_lines , ed_script .script )
158+ content = processed_lines
151159 case str () | [str (), * _] | (str (), * _):
152160 pass
153161 case (region , relindent_level ):
@@ -161,10 +169,6 @@ def _update_command(self, cmd: UpdateCommand):
161169 case _:
162170 match action :
163171 case MoveClause (insert_position = region , relative_indentation = relindent_level ):
164- # dest_range = restrict_search_range_for_marker(
165- # region, action, lines, RangeSpec.EMPTY, identifier_finder
166- # )
167- # TODO Are the 3 lines above needed?
168172 content = IndentationInfo .shift_indentation (
169173 move_src_range .read (lines ), lines , search_range .indent , relindent_level
170174 )
0 commit comments