Skip to content

Commit 055ab60

Browse files
committed
Minor improvements to documentation and tests
1 parent 2b8e167 commit 055ab60

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ IDEs can store the local history of files in CEDARScript format, and this can al
6767
Quick example:
6868

6969
```sql
70-
UPDATE FUNCTION
70+
UPDATE FUNCTION "my_func"
7171
FROM FILE "functional.py"
72-
WHERE NAME = "_conform_to_reference_input"
7372
MOVE WHOLE
7473
INSERT BEFORE LINE "def get_config(self):"
7574
RELATIVE INDENTATION 0;

grammar.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ module.exports = grammar({
176176
// ---
177177

178178
/**
179-
Syntax: (FUNCTION|CLASS) FROM FILE "<path/to/file>" WHERE <where...> [OFFSET <offset>]
180-
Use cases: Specify a function or class of a given file.
179+
Syntax: (VARIABLE|FUNCTION|CLASS) "<name>" [OFFSET <offset>] FROM FILE "<path/to/file>"
180+
Use cases: Specify an identifier in a given file.
181181
<params>
182-
- `where...`: Identifies a function or class as the item of interest in the file.
183-
- `offset`: Specifies how many items to skip. See details in `offset_clause`.
182+
- `<name>`: Identifies the name of a variable, function or class as the item of interest in the file.
183+
- `<offset>`: Specifies how many items to skip. Mandatory when there are 2 or more matching elements. See details in `offset_clause`.
184184
</params>
185185
*/
186186
identifier_from_file: $ => seq(
@@ -288,12 +288,12 @@ module.exports = grammar({
288288
region_field: $ => field('region', choice(BODY_OR_WHOLE, $.marker_or_segment)),
289289

290290
/**
291-
Field `offset`: Integer to identify how many occurrences to skip. *MANDATORY* iff there are 2 or more occurrences.
291+
Field `offset`: Integer to identify how many matches to skip. *MANDATORY* iff there are 2 or more matching elements.
292292
<examples>
293-
<li>`OFFSET 0` is the default. It means to skip 0 items (so, points to the *1st* occurrence).</li>
294-
<li>`OFFSET 1` skips 1 item, so points to the *2nd* occurrence</li>
295-
<li>`OFFSET 2` skips 2 items, so points to the *3rd* occurrence</li>
296-
<li>`OFFSET n` skips n items, thus specifies the (n+1)-th occurrence</li>
293+
<li>`OFFSET 0` is the default when there's only one matching element. It means to skip 0 items (so, points to the *1st* match).</li>
294+
<li>`OFFSET 1` skips 1 matches, so points to the *2nd* matches</li>
295+
<li>`OFFSET 2` skips 2 matches, so points to the *3rd* matches</li>
296+
<li>`OFFSET n` skips n matches, thus specifies the (n+1)-th matches</li>
297297
</examples>
298298
*/
299299
offset_clause: $ => seq('OFFSET', field('offset', $.number)),

test/corpus/update.txt

+23-4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ DELETE SEGMENT
8080
STARTING AT LINE "\"database\": {" OFFSET 1
8181
ENDING BEFORE LINE "}"
8282

83+
UPDATE FILE "my_code.py" REPLACE FUNCTION "my_function" WITH CONTENT """
84+
def other_function(x):
85+
"""
86+
8387
---
8488

8589
(source_file
@@ -266,8 +270,20 @@ DELETE SEGMENT
266270
(marker
267271
(lineMarker
268272
(string
269-
(single_quoted_string)))))))))))
270-
273+
(single_quoted_string))))))))))
274+
(update_command
275+
(singlefile_clause
276+
(string
277+
(single_quoted_string)))
278+
(replace_mos_clause
279+
(marker_or_segment
280+
(marker
281+
(identifierMarker
282+
(string
283+
(single_quoted_string))))))
284+
(content_clause
285+
(string
286+
(multi_line_string)))))
271287

272288
==================
273289
UPDATE Function/Class From File w/o WHERE
@@ -529,7 +545,8 @@ UPDATE Move BODY / WHOLE / LINE
529545
UPDATE FUNCTION "index"
530546
FROM FILE "/app/views.py"
531547
MOVE WHOLE
532-
INSERT BEFORE CLASS "TopClass" OFFSET 1;
548+
INSERT BEFORE CLASS "TopClass" OFFSET 1
549+
RELATIVE INDENTATION 2;
533550

534551
UPDATE FUNCTION "index"
535552
FROM FILE "/app/views.py"
@@ -563,7 +580,9 @@ INSERT AFTER LINE "XXX"
563580
(string
564581
(single_quoted_string))
565582
(offset_clause
566-
(number))))))))))
583+
(number)))))))
584+
(relative_indentation
585+
(number)))))
567586
(command_separator)
568587
(update_command
569588
(identifier_from_file

0 commit comments

Comments
 (0)