module.exports = grammar( { name: 'uci', extras: $ => [ $.comment, /[\s\p{Zs}\uFEFF\u2060\u200B]/, ], rules: { config_file: $ => repeat(choice( $.package, $.config )), _name_fragment: $ => /[A-Za-z0-9_]+/, name: $ => choice( $._name_fragment, seq('"', $._name_fragment, '"'), seq("'", $._name_fragment, "'"), ), string: $ => choice( /"[^"\\]*"/, /'[^'\\]*'/, /[^'"\s]+/ ), config: $ => seq( "config", field("type", $.name), optional(field("name", $.name)), repeat(choice($.option, $.list)) ), package: $ => prec.right(seq( "package", $.name, repeat($.config) )), option: $ => seq( "option", field("key", $.name), field("value", $.string), ), list: $ => seq( "list", field("key", $.name), field("value", $.string), ), comment: $ => token(seq("#", /.*/)) } });