Skip to content

Commit

Permalink
Added grammar and test cases for config and qunatifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishalk91-4 committed Jun 6, 2024
1 parent 04897d7 commit 3dc4c64
Show file tree
Hide file tree
Showing 6 changed files with 56,396 additions and 38,076 deletions.
91 changes: 80 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,28 @@ module.exports = grammar({
'in',
field('quant_target', $.quant_target),
'{',
field('expr1', $.expression),
choice(
field('expr1', $.expression),
seq(
field('dotted_name', $.dotted_name),
field('string', $.string)
)
),
optional(seq(
'if',
field('expr2', $.expression)
)),
'}',
)),

quant_target: $ => choice(
quant_target: $ => prec(1, choice(
field('dictionary_or_list', $.identifier),
$.dictionary,
$.string,
$.list,
$.list_comprehension,
$.config_expr,
$.dictionary_comprehension,
seq(
'[',
field('integer', $.integer),
Expand All @@ -346,7 +361,7 @@ module.exports = grammar({
)),
']'
)
),
)),

quant_op: $ => choice(
'all',
Expand Down Expand Up @@ -460,7 +475,7 @@ module.exports = grammar({
$._dedent,
),

dotted_name: $ => prec.left(1, sep1($.identifier, choice('?.','.',))),
dotted_name: $ => prec.left(2, sep1($.identifier, choice('?.','.',))),

// Patterns

Expand Down Expand Up @@ -507,7 +522,7 @@ module.exports = grammar({
field('alias', $.expression),
)),

primary_expression: $ => choice(
primary_expression: $ => prec(2, choice(
$.binary_operator,
$.identifier,
$.string,
Expand Down Expand Up @@ -535,7 +550,7 @@ module.exports = grammar({
$.null_coalesce,
$.string_literal_expr,
$.config_expr,
),
)),

paren_expression: $ => seq(
'(', $.expression, ')'
Expand Down Expand Up @@ -569,16 +584,70 @@ module.exports = grammar({
'"'
),

config_expr: $ => prec(1, seq(
config_expr: $ => seq(
'{',
sep1(',', seq(
field('key', $.identifier),
'=',
field('value', $.expression)
optional(choice(
$.config_entries,
seq(
'\n',
optional($.config_entries)
)
)),
'}'
),

config_entries: $ => seq(
$.config_entry,
repeat(seq(
choice(
',',
seq(
optional(','),
'\n'
)
),
$.config_entry
)),
optional(','),
optional('\n')
),

config_entry: $ => choice(
seq(
$.test,
choice(':', '=', '+='),
$.test
),
$.dictionary_splat,
$.if_entry
),

test: $ => prec(1, choice(
$.dotted_name,
$.identifier,
$.string,
$.integer,
$.float,
$.paren_expression
)),

dotted_identifier: $ => prec(4, seq(
$.identifier,
repeat(seq('.', $.identifier))
)),

double_star_expr: $ => seq(
'**',
$.expression
),

if_entry: $ => seq(
'if',
$.expression,
'then',
$.expression
),

binary_operator: $ => {
const table = [
[prec.left, '+', PREC.plus],
Expand Down
Loading

0 comments on commit 3dc4c64

Please sign in to comment.