Skip to content

Commit 1fc405a

Browse files
committed
THEN REPLACE -> THEN SUB <pattern> <replacement>
1 parent cf4d78f commit 1fc405a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

grammar.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const SELECT_OTHER_TARGETS = choice(
1010

1111
/*
1212
CASE
13-
WHEN REGEX r"print\((.*?)\)" THEN REPLACE r"logger.debug(\1)"
13+
WHEN REGEX r"print\((.*?)\)" THEN SUB r"logger.debug(\1)"
1414
WHEN REGEX r"raise" THEN DELETE
1515
WHEN PREFIX "try" THEN RELINDENT 1
1616
WHEN SUFFIX ";" THEN CONTENT '''xxx''' ELSE CONTENT '''No match'''
@@ -33,7 +33,7 @@ WHEN MATCHES_FILE "*.py" -- File pattern match
3333
WHEN LENGTH > <n> -- Line length condition
3434
3535
-- Actions (THEN clause):
36-
THEN REPLACE r"pattern" -- Replace with regex capture groups
36+
THEN SUB r"pattern" r"replacement" -- Replace with regex capture groups
3737
THEN DELETE -- Remove the line
3838
THEN CONTENT '''text''' -- Replace with specific content
3939
THEN CONTINUE -- Skip this line
@@ -403,7 +403,7 @@ module.exports = grammar({
403403
case_action: $ => choice(
404404
$.loop_control,
405405
seq(field('remove', 'REMOVE'), optional($.loop_control)), // Remove line
406-
seq('REPLACE', field('replace', $.string), optional($.loop_control)), // Replace with regex capture groups
406+
seq('SUB', field('pattern', $.string), field('repl', $.string), optional($.loop_control)), // Replace with regex capture groups
407407
seq('INDENT', field('indent', $.number), optional($.loop_control)), // Change indentation
408408
seq(choice($.content_literal, $.content_from_segment), optional($.loop_control)) // Replace with specific content
409409
),

test/corpus/update.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -991,10 +991,10 @@ REPLACE SEGMENT STARTING AT LINE 1 ENDING BEFORE LINE REGEX "ASDF"
991991
WITH CASE
992992
WHEN EMPTY THEN REMOVE
993993
WHEN LINE NUMBER 4 THEN CONTINUE
994-
WHEN REGEX r"asdf" THEN REPLACE r"asdf" BREAK
994+
WHEN REGEX r"asdf" THEN SUB r"pattern" r"replacement" BREAK
995995
WHEN REGEX r"asdf" THEN INDENT 4
996996
WHEN REGEX r"asdf" THEN BREAK
997-
ELSE REPLACE "af"
997+
ELSE SUB r"pattern" r'replacement'
998998
END;
999999

10001000
---
@@ -1031,6 +1031,8 @@ END;
10311031
(string
10321032
(raw_string)))
10331033
(case_action
1034+
(string
1035+
(raw_string))
10341036
(string
10351037
(raw_string))
10361038
(loop_control
@@ -1048,7 +1050,9 @@ END;
10481050
(loop_break)))
10491051
(case_action
10501052
(string
1051-
(single_quoted_string)))))
1053+
(raw_string))
1054+
(string
1055+
(raw_string)))))
10521056
(command_separator))
10531057

10541058
==================

0 commit comments

Comments
 (0)