module.exports = grammar({ name: 'Dust', rules: { source_file: $ => repeat(choice( $.comment, $.expression, $.value, $.yield, $.chain )), comment: $ => /(#)(.+?)([\n\r])/, expression: $ => choice( $.identifier, $.tool, seq($.identifier, $.operator, $.expression), seq($.value, $.operator, $.value) ), value: $ => choice( $.integer, $.float, $.string, $.list, $.empty, ), 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: $ => /"(.*?)\"/, function: $ => /'(.*?)\'/, empty: $ => "()", list: $ => seq( '(', repeat1(seq($.expression, optional(','))), ')' ), } });