module.exports = grammar({ name: 'dust', word: $ => $.identifier, rules: { root: $ => repeat1($.item), item: $ => choice( $.comment, $.statement, ), comment: $ => prec.left(seq(token('#'), /.*/)), statement: $ => choice( $.open_statement, ), open_statement: $ => prec.left(seq($.expression)), expression: $ => choice( $.value, $.identifier, $.operation, $.control_flow, $.tool, ), identifier: $ => /[a-z|_|.]+/, value: $ => choice( $.integer, $.float, $.string, $.list, $.empty, $.boolean, $.function, $.table, ), float: $ => /\d+\.\d*/, integer: $ => /\d+/, string: $ => /("|'|`)(.*?)("|'|`)/, empty: $ => '()', boolean: $ => choice( 'true', 'false', ), list: $ => seq( '(', repeat1(seq($.value, optional(','))), ')' ), function: $ => seq( 'function', optional(seq('<', repeat(seq($.identifier, optional(','))), '>')), '{', repeat($.statement), '}', ), table: $ => seq( 'table', seq('<', repeat(seq($.identifier, optional(','))), '>'), '{', optional(repeat($.list)), '}', ), operator: $ => choice( '+', '-', '=', '==', ), operation: $ => prec.left(seq( $.expression, $.operator, $.expression, )), control_flow: $ => prec.right(seq( 'if', $.expression, 'then', $.statement, optional(seq('else', $.statement)) )), tool: $ => choice( "output", ), } });