Skip to content

Commit 6f43c65

Browse files
committed
Fixed handling '--' inside strings (they shouldn't be interpreted as comments); Updated comment and definition of 'relpos_inside'
1 parent d9f3c50 commit 6f43c65

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

grammar.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,15 @@ module.exports = grammar({
255255
*/
256256
relpos_beforeafter: $ => field('relpos_beforeafter', seq(choice('BEFORE', 'AFTER'), $.marker)),
257257
/**
258-
relpos_inside: Points to inside `identifierMarker` (its top or bottom region).
259-
Use cases: When inserting content at the top or bottom of a function, class or file.
258+
relpos_inside: Points to inside `identifierMarker` (either the body's TOP or BOTTOM region). The reference indentation level is the body's.
259+
Syntax: INSIDE (FUNCTION|CLASS) "<name>" [OFFSET <offset>] (TOP|BOTTOM)
260+
Use cases: When inserting content either at the TOP or BOTTOM of a function or class body.
261+
Examples: <ul>
262+
<li>INSIDE FUNCTION my_function OFFSET 1 BOTTOM -- at the BOTTOM of the function body</li>
263+
<li>INSIDE FUNCTION my_function TOP -- at the TOP of the function body</li>
264+
</ul>
260265
*/
261-
relpos_inside: $ => seq('INSIDE', field('inside', $.identifierMarker), optional(field('topOrBottom', choice('TOP', 'BOTTOM')))),
266+
relpos_inside: $ => seq('INSIDE', field('inside', $.identifierMarker), field('topOrBottom', choice('TOP', 'BOTTOM'))),
262267
relpos_bai: $ => field('relpos_bai', choice($.relpos_beforeafter, $.relpos_inside)),
263268
/**
264269
relpos_at: points to a specific `lineMarker`
@@ -409,6 +414,7 @@ in the target code file.
409414
"'",
410415
repeat(choice(
411416
/[^'\\\n]/,
417+
'--',
412418
$.escape_sequence
413419
)),
414420
"'"
@@ -417,6 +423,7 @@ in the target code file.
417423
'"',
418424
repeat(choice(
419425
/[^"\\\n]/,
426+
'--',
420427
$.escape_sequence
421428
)),
422429
'"'
@@ -432,6 +439,7 @@ in the target code file.
432439
/[^"\\]/,
433440
'"',
434441
'""',
442+
'--',
435443
$.escape_sequence
436444
)),
437445
'"""'
@@ -442,6 +450,7 @@ in the target code file.
442450
/[^'\\]/,
443451
"'",
444452
"''",
453+
'--',
445454
$.escape_sequence
446455
)),
447456
"'''"
@@ -450,7 +459,10 @@ in the target code file.
450459

451460
number: $ => /\d+/,
452461

453-
comment: $ => token(seq('--', /.*/)),
462+
comment: $ => token(prec(-1, seq(
463+
'--',
464+
optional(/[^\n]+/)
465+
))),
454466

455467
command_separator: $ => ';'
456468

src/cedarscript_grammar/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from tree_sitter import Language
66

7-
__version__ = "0.0.8"
7+
__version__ = "0.0.9"
88
__all__ = ("language",)
99

1010
_ROOT_DIR = Path(__file__).parent

0 commit comments

Comments
 (0)