0

I'm attempting to write a Nearley grammar that will parse a .pbtxt file (a protobuf in textual format). I'm very close but seem to be encountering an infinite loop when tested in the Nearley playground (https://omrelli.ug/nearley-playground/). Can someone more comfortable with Nearley grammars spot the issue more readily?

@builtin "number.ne"
@builtin "string.ne"
@builtin "whitespace.ne"

Start -> Field:+

Field -> _ (ScalarField | MessageField) _ "\n":*
ScalarField -> FieldName _ ":" _ (ScalarValue | ScalarList) _
MessageField -> FieldName _ ":" _ (MessageValue | MessageList) _

FieldName -> [A-Za-z0-9_]:+

MessageValue -> "{" Field:+ "}"
MessageList -> "{" Field (_ "\n":+ Field):* "}"

ScalarValue -> String | Float | Integer
ScalarList -> "{" _ ScalarValue (_ "\n":+ ScalarValue):* "}"

String -> sqstring | dqstring | [A-Za-z0-9_]:+
Float -> decimal
Integer -> int

Here's an example .pbtxt that should pe parseable:

something: WHATEVER
some_list: {
    bins: 32
    bins: 64
    bins: 128
    bins: 256
}


things: {
    some_path: "Data/thingything"
    weight: 2
    other_weights: {
        positive_dense_bin: 8
        low_heat: 1
    }
}
ScoPi
  • 1,193
  • 9
  • 14

0 Answers0