kursjan / petitparser2

A high-performance top-down parser
MIT License
41 stars 19 forks source link

PP2FlexiblePredicateSequenceNode #65

Open seandenigris opened 3 years ago

seandenigris commented 3 years ago

Matches input against a predicate block, like PP2PredicateSequenceNode, but for an unknown/variable length.

For example, whereas for fixed-length matches you can already do: parser := PP2PredicateSequenceNode on: [ :value | value first isUppercase ] message: 'uppercase 3 letter words' size: 3. (parser parse: 'Abc') isPetitFailure not.

Now you can do: parser := PP2FlexiblePredicateSequenceNode on: [ :value | Object new respondsTo: value asSymbol ] message: 'message to an object' while: [ :e | e ~= Character space ].

    (parser parse: 'hash ijk') isPetitFailure not. 
    (parser parse: '99 ijk') isPetitFailure.