Skip to content

Commit a092386

Browse files
committed
Clean up
1 parent 016728e commit a092386

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

grammar.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -238,41 +238,28 @@ module.exports = grammar({
238238

239239
maxdepth_clause: $ => seq('MAX DEPTH', field('depth', $.number)),
240240

241-
/*TODO
242-
1 Add support for line numbers as reference points:
243-
UPDATE FILE "file.py"
244-
INSERT AFTER LINE 123
245-
WITH CONTENT '''...''';
246-
247-
2 Add support for regular expressions to match lines:
248-
UPDATE FILE "file.py"
249-
INSERT AFTER LINE REGEX r'@@\s*={10,}\s*PERFORMANCE\s+METRICS\s*={10,}\s*@@'
250-
WITH CONTENT '''...''';
251-
252-
3 Add support for "anchored" line markers that must match from start/end of line:
253-
UPDATE FILE "file.py"
254-
INSERT AFTER LINE START "@@ ============ PERFORMANCE METRICS"
255-
WITH CONTENT '''...''';
256-
*/
257241
// <specifying-locations-in-code>
258242
/**
259243
lineMarker: Points to specific line via:
260-
- its trimmed contents
261-
- its line number
244+
- its *context-relative line number* (best method, as this is guaranteed to be unambiguous. Must use this if other types failed)
245+
- its *contents*, if it's unambiguous (don't use line content if the line appears multiple times)
262246
- a string that matches from start of line (PREFIX)
263247
- a string that matches from end of line (SUFFIX)
264248
- a regular expression pattern (REGEX)
265-
*NEVER* use an ambiguous line (one that appears 2 or more times) as reference. Instead, prefer a different, nearby line.
266249
*/
267250
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))
251+
field('lineMarker', choice($.string, $.number)), // reference the line content or a context-relative line number
252+
seq('REGEX', field('regexMarker', $.string)), // match line by REGEX
253+
seq('PREFIX', field('prefixMarker', $.string)), // match line by its prefix
254+
seq('SUFFIX', field('suffixMarker', $.string)) // match line by its suffix
272255
), optional($.offset_clause)),
273256
/**
274-
identifierMarker: Points to an identifier (variable, function or class).
275-
Use `OFFSET <n>` to pinpoint which (if there are 2 or more with same name)
257+
identifierMarker: Name of an identifier (variable, function, method or class).
258+
If there are 2 or more with same name, prefixed it with its parent chain (names of its parents separated by a dot) to disambiguate it.
259+
Another way to disambiguate is to use `OFFSET <n>` to pinpoint one.
260+
Example of simple name and parent chains:
261+
- "my_method" (just the name, if it's unique. Matches any method with that name, regardless of its parents)
262+
- "MyClass.my_method" (matches any `my_method` that has `MyClass` as its direct parent. Also matches if `MyClass` itself has other parents)
276263
*/
277264
identifierMarker: $ => seq(field('identifier', choice('VARIABLE', 'FUNCTION', 'METHOD', 'CLASS')), field('identifierMarker', $.string), optional($.offset_clause)),
278265
marker: $ => choice($.lineMarker, $.identifierMarker),

0 commit comments

Comments
 (0)