75 lines
1.2 KiB
JavaScript
75 lines
1.2 KiB
JavaScript
module.exports = grammar({
|
|
name: 'dust',
|
|
|
|
rules: {
|
|
source: $ => repeat(choice(
|
|
$.comment,
|
|
$.statement,
|
|
)),
|
|
|
|
comment: $ => prec.right(seq('#', /.*/, optional('#'))),
|
|
|
|
statement: $ => choice(
|
|
$.closed_statement,
|
|
$.open_statement,
|
|
),
|
|
|
|
closed_statement: $ => seq($.expression, $.close),
|
|
|
|
open_statement: $ => seq($.expression),
|
|
|
|
expression: $ => choice(
|
|
prec(0, $.value),
|
|
prec(1, $.identifier),
|
|
prec(2, $.operation),
|
|
),
|
|
|
|
close: $ => ";",
|
|
|
|
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
|
|
|
|
value: $ => choice(
|
|
$.integer,
|
|
$.float,
|
|
$.string,
|
|
$.list,
|
|
$.empty,
|
|
$.boolean,
|
|
$.function,
|
|
),
|
|
|
|
float: $ => /\d+\.\d*/,
|
|
|
|
integer: $ => /\d+/,
|
|
|
|
string: $ => /("|'|`)(.*?)("|'|`)/,
|
|
|
|
function: $ => /{(.*?)}/,
|
|
|
|
empty: $ => '()',
|
|
|
|
boolean: $ => choice(
|
|
'true',
|
|
'false',
|
|
),
|
|
|
|
list: $ => seq(
|
|
'(',
|
|
repeat1(seq($.value, optional(','))),
|
|
')'
|
|
),
|
|
|
|
operator: $ => choice(
|
|
'+',
|
|
'-',
|
|
'=',
|
|
),
|
|
|
|
operation: $ => prec.left(seq(
|
|
$.expression,
|
|
$.operator,
|
|
$.expression,
|
|
)),
|
|
}
|
|
});
|