Assume I have the following PEG definition:
    
    
    import pegs
    
    let examplePeg = peg"""
      A <- {L}? {D}?
      L <- \a+
      D <- \d+
    """
    
    
    Run

If I test strings against this PEG, I get: 
    
    
    if "abc" =~ examplePeg:
      # `["abc", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 
"", "", "", ""]`
      echo matches
    
    if "123" =~ examplePeg:
      # `["123", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", 
"", "", "", ""]
      echo matches
    
    
    Run

Now, since the subexpressions `L` and `D` are optional, it seems I need to look 
at the matched strings and check them _again_ despite the PEG already defines 
whether I expect letters or digits for these subexpressions.

The only API I found that gives more control is `eventParser`, which on the 
other hand seems far too complicated for a relatively simple case as this.

Is there a simpler API (or a combination of them) in the `pegs` module, which I 
may have missed?

Reply via email to