You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven’t had much time recently to continue implementing a few more features I had in mind, and especially document a few things! (But I’m definitely planning to!)
Token is a pattern class that is supposed to be used at most once in a given pattern. When used on two or more places, it can capture multiple sequences per match but it’s not well-defined. The multiple-captures features is only well-defined when a single token object is used within some kind of repeating pattern (like LazilyRepeating): in that case it blindly follows the matching semantics of the repeating pattern.
I see multiple uses of the token within the pattern. Did you instead mean to use a back-reference, which matches a subsequence that a previous token matched? The read-me mentions Referencing but I haven’t gotten around to implementing it yet.
LazilyRepeating already tries to match its sub-pattern as few times as possible, or in your example, by applying the wildcard zero times, once, twice, thrice, and so. In your example output, it’s the first, second, third, … element. forwardMatches(…) returns a lazily evaluated array for every possible match, so you can just take the first match to get the match with the least repetitions.
However, forwardMatches(enteringFrom:) is a foundational method that returns partial matches (matches that might not cover the whole string yet). Larger patterns build on top of these partial matches. The matches(over:) method (in Pattern) does exclude all partial matches, and is the method for “client use”. :)
Hi, and sorry about the very late reply. I liked the syntax in this project so much I implemented something similar in my PEG parser at https://github.com/kareman/Patterns . It made the API far easier to work with (as soon as you find out how to type • and ¿ 😄) .
Activity
ctxppc commentedon Jun 3, 2020
Thanks for your kind words!
I haven’t had much time recently to continue implementing a few more features I had in mind, and especially document a few things! (But I’m definitely planning to!)
Tokenis a pattern class that is supposed to be used at most once in a given pattern. When used on two or more places, it can capture multiple sequences per match but it’s not well-defined. The multiple-captures features is only well-defined when a single token object is used within some kind of repeating pattern (likeLazilyRepeating): in that case it blindly follows the matching semantics of the repeating pattern.I see multiple uses of the token within the pattern. Did you instead mean to use a back-reference, which matches a subsequence that a previous token matched? The read-me mentions
Referencingbut I haven’t gotten around to implementing it yet.LazilyRepeatingalready tries to match its sub-pattern as few times as possible, or in your example, by applying the wildcard zero times, once, twice, thrice, and so. In your example output, it’s the first, second, third, … element.forwardMatches(…)returns a lazily evaluated array for every possible match, so you can just take the first match to get the match with the least repetitions.However,
forwardMatches(enteringFrom:)is a foundational method that returns partial matches (matches that might not cover the whole string yet). Larger patterns build on top of these partial matches. Thematches(over:)method (inPattern) does exclude all partial matches, and is the method for “client use”. :)kareman commentedon Jul 7, 2020
Hi, and sorry about the very late reply. I liked the syntax in this project so much I implemented something similar in my PEG parser at https://github.com/kareman/Patterns . It made the API far easier to work with (as soon as you find out how to type • and ¿ 😄) .
ctxppc commentedon Jul 7, 2020
Looks nice, especially its strong typing and its VM approach! 💯