Simplify and rename `lookahead`
See original GitHub issueBreaking change suggestion
Currently lookahead
accepts multiple different types of arguments as shorthands, but in the interest of a consistent and predictable API we should change it to only accept a parser as its argument type.
Also, to be consistent with notFollowedBy
it should be renamed to followedBy
. So far I have strived to maintain good backwards compatibility in Parsimmon, so it might be worth keeping around lookahead
as an alias. That being said, the function is undergoing a breaking change, so I think it’s possibly better to just fully rename it so there are obvious errors when people migrate to the new version of Parsimmon.
Also up for discussion is the existence of non-method forms of these functions. followedBy(...)
is equivalent to P.of().followedBy(...)
, so we don’t necessarily need both. Especially because followedBy
doesn’t really make sense in English without a subject to chain off of. But that second construction is a bit awkward looking, so 🤷♂️
Finally, the return value should be null
, not an empty string.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:28 (4 by maintainers)
Top GitHub Comments
In case anyone needs it, I wrote a peek function that worked for me.
Should be easy to convert to JS if you want.
While I think the argument regarding Unit as an output does not carry any information is correct. null has the additional behavior of being falsey whereas matched input would always certainly be truthy. So while I’m certain anyone depending on a value from lookahead is doing something silly it would technically be a breaking change.