parsingdata / metal

A Java library for parsing binary data formats, using declarative descriptions.
Apache License 2.0
18 stars 9 forks source link

Allow varargs for Ref to reference to defs with different names and return them in parsing order. #392

Closed mvanaken closed 1 year ago

mvanaken commented 1 year ago

You can only specify one argument to ref to reference tokens with a specific name. If you want to select tokens with different names simultanuously, you can use Join, eg: join(ref("a"), ref("b"), ref("c"))

This will have the following properties:

  1. this will select the tokens in the order specified, in this example thatt could be "a", "a", "a", "b", "b", "c"
  2. this will evaluate the separate expressions, and with multiple refs, this would mean traversing the ParseGraph multiple times, in this example 3 times.

If Ref accepts a varargs for the selected elements, e.g.: ref("a", "b", "c")

This will impact to above properties:

  1. this will select the tokens in the parsing order, in this example that could be "a", "b", "c", "b", "a", "a"
  2. to find these elements only one traversal of the ParseGraph is required.