/// // @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 operation: _ => /[A-Z]+/, // must be all uppercase file_path: _ => /[^ \t\n][^\n]*/, // must not start with space or newline } });