/// // @ts-check module.exports = grammar({ name: "noil", extras: $ => [ /[ \t]+/, // skip whitespace but not newlines ], rules: { source_file: $ => repeat($.line), line: $ => choice( $.operation_line, $.operation_only_line, $.mapping_line, $.path_only_line, $.empty_line ), empty_line: _ => "\n", path_only_line: $ => seq( ":", field("path", $.file_path), "\n" ), mapping_line: $ => seq( field("prefix", $.prefix), ":", field("path", $.file_path), "\n" ), operation_line: $ => seq( field("operation", $.operation), field("prefix", $.prefix), ":", field("path", $.file_path), "\n" ), operation_only_line: $ => seq( field("operation", $.operation), ":", field("path", $.file_path), "\n" ), prefix: _ => /[a-z0-9]+/, // allow lowercase alphanumeric file_path: _ => /[^ \t\n][^\n]*/, // must not start with space or newline operation: $ => choice( $.op_add, $.op_delete, $.op_move, $.op_copy, $.generic_operation ), op_add: _ => choice("A", "ADD"), op_delete: _ => choice("D", "DELETE"), op_move: _ => choice("M", "MV", "MOVE", "RENAME"), op_copy: _ => choice("C","COPY"), generic_operation: _ => /[A-Z]+/, } });