question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simplify and rename `lookahead`

See original GitHub issue

Breaking 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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:28 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jakepearsoncommented, Mar 16, 2021

In case anyone needs it, I wrote a peek function that worked for me.

function peek<T>(parser: parsimmon.Parser<T>): parsimmon.Parser<T> {
  return parsimmon((input, i) => {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const result = (parser as any)._(input, i);
    result.index = i;
    return result;
  });
}

Should be easy to convert to JS if you want.

1reaction
rzeiglercommented, Jul 28, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Register renaming in which moves are accomplished by swapping ...
Upon detecting a move instruction, the lookahead unit signals a register rename unit, which reassigns the rename register associated with the source ...
Read more >
Regex to rename/modify duplicate lines - Stack Overflow
A very simplified example. We start with the text: z # a a y a x. Now we reverse the text: x a...
Read more >
Homogenizing TV Show Names - Bulk Rename Utility
Hi, I'm trying to use the program iPodifier, which requires that all show names it imports be in the format Showname-S01E01 Episode Name.ext ......
Read more >
Recursively rename files (change extension) in Linux
Rename lookahead workaround ... I have started to put together a tool to provide a simplified interface to common actions.
Read more >
Renaming Fractions - 5th Grade Math - YouTube
Renaming Fractions - 5th Grade Math. 133K views 10 years ago ... Simplifying Fractions, Part 1 - 5th Grade Math. Math and Science....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found