module.exports = grammar({ name: 'dust', rules: { source_file: $ => repeat(choice( $.comment, $.expression, $.yield, $.chain )), expression: $ => choice( prec(2, $.value), prec(1, $.identifier), $.tool, seq($.identifier, $.operator, $.expression), ), value: $ => choice( $.integer, $.float, $.string, $.list, $.empty, $.boolean, ), comment: $ => /(#)(.+?)([\n\r])/, yield: $ => "->", chain: $ => ";", identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/, operator: $ => choice( '=', '-', '+', '/', '|', '&' ), tool: $ => choice( "random", "random_boolean", "random_integer", "random_string", "random_float" ), float: $ => /\d+\.\d*/, integer: $ => /\d+/, string: $ => seq( '"', repeat(), '"' ), function: $ => /\{(.*?)\}/, empty: $ => "()", boolean: $ => choice( "true", "false" ), list: $ => seq( '(', repeat1(seq($.expression, optional(','))), ')' ), } });