~bduggan/raku-protobuf

4928ccd4ed1b64b5cef334ce173153eb7d1fa4a0 — Brian Duggan 3 months ago 1111fa7
fix field options, support reserved enums
2 files changed, 5 insertions(+), 5 deletions(-)

M lib/Protobuf/Grammar.rakumod
M t/02-parse.rakutest
M lib/Protobuf/Grammar.rakumod => lib/Protobuf/Grammar.rakumod +3 -3
@@ 178,12 178,12 @@ rule field {
}

# fieldOptions = fieldOption { ","  fieldOption }
regex fieldOptions {
rule fieldOptions {
  <fieldOption>+ % ','
}

# fieldOption = optionName "=" constant
regex fieldOption {
rule fieldOption {
 <optionName> '=' <constant>
}



@@ 237,7 237,7 @@ rule enum {

# enumBody = "{" { option | enumField | emptyStatement } "}"
rule enumBody {
  '{' [ <option> | <enumField> | <emptyStatement> ]* '}'
  '{' [ <option> | <enumField> | <emptyStatement> | <reserved> ]* '}'
}

# enumField = ident "=" intLit [ "[" enumValueOption { ","  enumValueOption } "]" ]";"

M t/02-parse.rakutest => t/02-parse.rakutest +2 -2
@@ 26,8 26,7 @@ ok protobuf.parse('map<string, Project> projects = 3;',:rule<mapField>), 'mapFie
ok protobuf.parse('9 to 11',:rule<range>), 'range';
ok protobuf.parse('reserved 2, 15, 9 to 11;',:rule<reserved>), 'reserved';
ok protobuf.parse('2, 9 to 11',:rule<ranges>), 'ranges';
# ok protobuf.parse('reserved "foo", "bar";',:rule<reserved>), 'reserved';
# ok protobuf.parse('"foo", "bar"',:rule<fieldNames>), 'fieldNames';
ok protobuf.parse('reserved 12;',:rule<reserved>), 'reserved';

ok protobuf.parse('UNKNOWN = 0;',:rule<enumField>), 'enumField';
ok protobuf.parse('EnumAllowingAlias',:rule<enumName>), 'enumName';


@@ 39,6 38,7 @@ ok protobuf.parse(q:to/X/, :rule<enum>), 'enum';
    UNKNOWN = 0;
    STARTED = 1;
    RUNNING = 2 [(custom_option) = "hello world"];
    reserved 100;
  }
  X
ok protobuf.parse(q:to/X/,:rule<field>), 'field';