Skip to content

Commit 77d302a

Browse files
committed
marker -> matcher; add support for SQL-style multi-line comments
1 parent 92fc93c commit 77d302a

File tree

3 files changed

+155
-125
lines changed

3 files changed

+155
-125
lines changed

grammar.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ module.exports = grammar({
131131
name: 'CEDARScript',
132132

133133
extras: $ => [
134-
/\s|\r?\n/,
135-
$.comment
134+
$.comment,
135+
/[\s\f\uFEFF\u2060\u200B]|\\\r?\n/
136136
],
137137

138138
rules: {
@@ -264,7 +264,7 @@ module.exports = grammar({
264264
</params>
265265
*/
266266
identifier_from_file: $ => seq(
267-
$.identifierMarker, 'FROM', $.singlefile_clause,
267+
$.identifier_matcher, 'FROM', $.singlefile_clause,
268268
optional($.where_clause)
269269
),
270270

@@ -320,21 +320,21 @@ module.exports = grammar({
320320
// <specifying-locations-in-code>
321321

322322
line_base: $ => seq(optional('LINE'), choice(
323-
field('lineMarker', choice($.string, $.number)), // reference the line content or a context-relative line number
323+
field('line_matcher', choice($.string, $.number)), // match the line content or a context-relative line number
324324
field('empty', 'EMPTY'), // match empty line
325325
seq('REGEX', field('regex', $.string)), // match line by REGEX
326326
seq('PREFIX', field('prefix', $.string)), // match line by its prefix
327327
seq('SUFFIX', field('suffix', $.string)), // match line by its suffix
328328
seq('INDENT', 'LEVEL', field('indent_level', $.number)), // Line has indent level
329329
)),
330-
lineMarker: $ => seq($.line_base, optional($.offset_clause)),
331-
identifierMarker: $ => seq(field('identifier', choice('VARIABLE', 'FUNCTION', 'METHOD', 'CLASS')), field('identifierMarker', $.string), optional($.offset_clause)),
332-
marker: $ => choice($.lineMarker, $.identifierMarker),
330+
line_matcher: $ => seq($.line_base, optional($.offset_clause)),
331+
identifier_matcher: $ => seq(field('identifier', choice('VARIABLE', 'FUNCTION', 'METHOD', 'CLASS')), field('identifier_matcher', $.string), optional($.offset_clause)),
332+
marker: $ => choice($.line_matcher, $.identifier_matcher),
333333
relpos_beforeafter: $ => field('relpos_beforeafter', seq(choice('BEFORE', 'AFTER'), $.marker)),
334-
relpos_into: $ => seq('INTO', field('into', $.identifierMarker), field('topOrBottom', choice('TOP', 'BOTTOM'))),
334+
relpos_into: $ => seq('INTO', field('into', $.identifier_matcher), field('topOrBottom', choice('TOP', 'BOTTOM'))),
335335
relpos_bai: $ => field('relpos_bai', choice($.relpos_beforeafter, $.relpos_into)),
336336
/**
337-
relpos_at: points to a specific `lineMarker`
337+
relpos_at: points to a specific `line_matcher`
338338
*/
339339
relpos_at: $ => seq('AT', field('at', $.marker)),
340340
/**
@@ -394,8 +394,6 @@ module.exports = grammar({
394394
loop_break: $ => field('break', 'BREAK'),
395395
loop_continue: $ => field('continue', 'CONTINUE'),
396396
loop_control: $ => choice($.loop_break, $.loop_continue),
397-
// Matchers (WHEN clause):
398-
case_when: $ => seq('WHEN', $.line_base),
399397
// Actions (THEN clause):
400398
case_action: $ => choice(
401399
$.loop_control,
@@ -408,10 +406,9 @@ module.exports = grammar({
408406
// Filters
409407

410408
case_stmt: $ => seq(
411-
'CASE', repeat(seq(
412-
$.case_when,
413-
'THEN',
414-
$.case_action
409+
'CASE', repeat1(seq(
410+
'WHEN', $.line_base,
411+
'THEN', $.case_action
415412
)),
416413
optional(seq('ELSE', field('else', $.case_action))),
417414
'END'
@@ -509,9 +506,9 @@ module.exports = grammar({
509506

510507
number: $ => seq(optional('-'), /\d+/),
511508

512-
comment: $ => token(prec(-1, seq(
513-
'--',
514-
optional(/[^\n]+/)
509+
comment: $ => token(prec(-1, choice(
510+
seq("--", /.*/),
511+
seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, "/")
515512
))),
516513

517514
command_separator: $ => ';'

test/corpus/misc.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
==================
2+
Comments
3+
==================
4+
5+
/* Comment
6+
still
7+
*/ UPDATE FILE '' DELETE 1
8+
9+
-- Comment
10+
CREATE FILE 'a--b'
11+
WITH CONTENT '''
12+
/* content */
13+
a -- content --
14+
'''
15+
16+
---
17+
18+
(source_file
19+
(comment)
20+
(update_command
21+
(singlefile_clause
22+
(string
23+
(single_quoted_string)))
24+
(update_delete_region_clause
25+
(region_field
26+
(marker_or_segment
27+
(marker
28+
(line_matcher
29+
(line_base
30+
(number))))))))
31+
(comment)
32+
(create_command
33+
(singlefile_clause
34+
(string
35+
(single_quoted_string)))
36+
(content_literal
37+
(string
38+
(multi_line_string)))))

0 commit comments

Comments
 (0)