Skip to content

Commit 016728e

Browse files
committed
feat: Add support for START, END, and REGEX line markers
1 parent 4540e33 commit 016728e

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grammar.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,20 @@ module.exports = grammar({
256256
*/
257257
// <specifying-locations-in-code>
258258
/**
259-
lineMarker: Points to specific line via either its trimmed contents or its line number.
259+
lineMarker: Points to specific line via:
260+
- its trimmed contents
261+
- its line number
262+
- a string that matches from start of line (PREFIX)
263+
- a string that matches from end of line (SUFFIX)
264+
- a regular expression pattern (REGEX)
260265
*NEVER* use an ambiguous line (one that appears 2 or more times) as reference. Instead, prefer a different, nearby line.
261266
*/
262-
lineMarker: $ => seq('LINE', field('lineMarker', choice($.string, $.number)), optional($.offset_clause)),
267+
lineMarker: $ => seq('LINE', choice(
268+
field('lineMarker', choice($.string, $.number)),
269+
seq('REGEX', field('regexMarker', $.string)),
270+
seq('PREFIX', field('prefixMarker', $.string)),
271+
seq('SUFFIX', field('suffixMarker', $.string))
272+
), optional($.offset_clause)),
263273
/**
264274
identifierMarker: Points to an identifier (variable, function or class).
265275
Use `OFFSET <n>` to pinpoint which (if there are 2 or more with same name)

test/corpus/update.txt

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1+
==================
2+
UPDATE with line markers
3+
==================
4+
5+
UPDATE FILE "/app/main.py"
6+
INSERT AFTER LINE 5
7+
WITH CONTENT "...";
8+
9+
UPDATE FILE "/app/main.py"
10+
INSERT AFTER LINE REGEX ".."
11+
WITH CONTENT "...";
12+
13+
UPDATE FILE "/app/main.py"
14+
INSERT AFTER LINE PREFIX ".."
15+
WITH CONTENT "...";
16+
17+
UPDATE FILE "/app/main.py"
18+
INSERT AFTER LINE SUFFIX ".."
19+
WITH CONTENT "...";
20+
21+
22+
---
23+
24+
(source_file
25+
(update_command
26+
(singlefile_clause
27+
(string
28+
(single_quoted_string)))
29+
(insert_clause
30+
(relpos_bai
31+
(relpos_beforeafter
32+
(marker
33+
(lineMarker
34+
(number))))))
35+
(content_clause
36+
(string
37+
(single_quoted_string))))
38+
(command_separator)
39+
(update_command
40+
(singlefile_clause
41+
(string
42+
(single_quoted_string)))
43+
(insert_clause
44+
(relpos_bai
45+
(relpos_beforeafter
46+
(marker
47+
(lineMarker
48+
(string
49+
(single_quoted_string)))))))
50+
(content_clause
51+
(string
52+
(single_quoted_string))))
53+
(command_separator)
54+
(update_command
55+
(singlefile_clause
56+
(string
57+
(single_quoted_string)))
58+
(insert_clause
59+
(relpos_bai
60+
(relpos_beforeafter
61+
(marker
62+
(lineMarker
63+
(string
64+
(single_quoted_string)))))))
65+
(content_clause
66+
(string
67+
(single_quoted_string))))
68+
(command_separator)
69+
(update_command
70+
(singlefile_clause
71+
(string
72+
(single_quoted_string)))
73+
(insert_clause
74+
(relpos_bai
75+
(relpos_beforeafter
76+
(marker
77+
(lineMarker
78+
(string
79+
(single_quoted_string)))))))
80+
(content_clause
81+
(string
82+
(single_quoted_string))))
83+
(command_separator))
84+
85+
186
==================
287
UPDATE PROJECT
388
==================

0 commit comments

Comments
 (0)