Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dewyze committed Jul 21, 2021
1 parent 6eb53bd commit 5accaac
Showing 1 changed file with 76 additions and 100 deletions.
176 changes: 76 additions & 100 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,123 +1,99 @@
module.exports = grammar({
name: 'liquid',
name: "liquid",

precedences: $ => [
precedences: ($) => [
[
'unary_not',
'binary_exp',
'binary_times',
'binary_plus',
'binary_in',
'binary_compare',
'binary_relation',
'clause_connective',
"unary_not",
"binary_exp",
"binary_times",
"binary_plus",
"binary_in",
"binary_compare",
"binary_relation",
"clause_connective",
],
],

rules: {
program: $ => repeat1(
seq(
choice('{{', '{%'),
choice(
$.filter,
$.expression,
$.statement
),
choice('}}', '%}'),
),
),

filter: $ => seq(
field("body", choice($.expression, $.filter)),
"|",
field('name', $.identifier),
optional(
program: ($) =>
repeat1(
seq(
":",
$.argument_list,
),
choice("{{", "{%"),
choice($.filter, $.expression, $.statement),
choice("}}", "%}")
)
),
),

statement: $ => choice(
$.assignment,
),
filter: ($) =>
seq(
field("body", choice($.expression, $.filter)),
"|",
field("name", $.identifier),
optional(seq(":", $.argument_list))
),

expression: $ => choice(
$._literal,
$.identifier,
$.predicate
),
statement: ($) => choice($.assignment),

// expression: $ => seq(
// $._expression,
// repeat(
// $.filter
// )
// ),
expression: ($) => choice($._literal, $.identifier, $.predicate),

assignment: $ => seq(
"assign",
field('variable_name', $.identifier),
"=",
field('value', choice($.filter, $.expression)),
),
assignment: ($) =>
seq(
"assign",
field("variable_name", $.identifier),
"=",
field("value", choice($.filter, $.expression))
),

_literal: $ => choice(
$.string,
$.number,
$.boolean,
),
_literal: ($) => choice($.string, $.number, $.boolean),

string: _ => choice(
seq("'", /[^']*/, "'"),
seq('"', /[^"]*/, '"'),
),
string: (_) => choice(seq("'", /[^']*/, "'"), seq('"', /[^"]*/, '"')),

number: _ => /\d+/,
number: (_) => /\d+/,

boolean: _ => choice('true', 'false'),
boolean: (_) => choice("true", "false"),

identifier: _ => /([a-zA-Z_$][0-9a-zA-Z_]*)/,
identifier: (_) => /([a-zA-Z_$][0-9a-zA-Z_]*)/,

argument_list: $ => seq(
choice($._literal, $.identifier, $.argument),
repeat(
seq(",",
choice($._literal, $.identifier, $.argument),
),
argument_list: ($) =>
seq(
choice($._literal, $.identifier, $.argument),
repeat(seq(",", choice($._literal, $.identifier, $.argument)))
),
),

argument: $ => seq(
field('key', $.identifier),
':',
field('value', choice($._literal, $.identifier)),
),
argument: ($) =>
seq(
field("key", $.identifier),
":",
field("value", choice($._literal, $.identifier))
),

predicate: $ => choice(
...[
['+', 'binary_plus'],
['-', 'binary_plus'],
['*', 'binary_times'],
['/', 'binary_times'],
['%', 'binary_times'],
['^', 'binary_exp'],
['==', 'binary_relation'],
['<', 'binary_relation'],
['<=', 'binary_relation'],
['!=', 'binary_relation'],
['>=', 'binary_relation'],
['>', 'binary_relation'],
['and', 'clause_connective'],
['or', 'clause_connective'],
].map(([operator, precedence]) =>
prec.left(precedence, seq(
field('left', $.expression),
field('operator', operator),
field('right', $.expression)
))
)
),
}
predicate: ($) =>
choice(
...[
["+", "binary_plus"],
["-", "binary_plus"],
["*", "binary_times"],
["/", "binary_times"],
["%", "binary_times"],
["^", "binary_exp"],
["==", "binary_relation"],
["<", "binary_relation"],
["<=", "binary_relation"],
["!=", "binary_relation"],
[">=", "binary_relation"],
[">", "binary_relation"],
["and", "clause_connective"],
["or", "clause_connective"],
].map(([operator, precedence]) =>
prec.left(
precedence,
seq(
field("left", $.expression),
field("operator", operator),
field("right", $.expression)
)
)
)
),
},
});

0 comments on commit 5accaac

Please sign in to comment.