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.

Hello!

First of all let me thank you for your amazing library and willingness to answer questions 🎉

I am trying to write a parser that looks like this

type Result = { kind: 'BrackedText', text: string } | { kind: 'Text', text: string }

const result: Result[] = alt(
  seq(string('['), letters, string(']')).map<Result>(...),
  i_dont_know.map<Result>(...)
).many().tryParse(input)

And I expect it to parse string "Hey [hello] how are [world] you?" into the following

[
  { kind: 'Text', text: 'hey ' },
  { kind: 'BrackedText', text: 'hello' },
  { kind: 'Text', text: ' how are ' },
  { kind: 'BrackedText', text: 'world' },
  { kind: 'Text', text: ' you?' },
]

Basically I want the entire parser to work so, that it parses pieces of string in between BrackedText as just strings regardless of what they contain. But I am stuck writing i_dont_know parser.

This is a very simplified example. In reality I have several different kind of structures instead of BrackedText which I want to parse. So writing parser takeWhile(x => x !== '[') wont do the trick.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
wavebeemcommented, Jan 25, 2021

Something like this should work. Click “Run” to see the results.

https://runkit.com/wavebeem/parsimmon-issues-316

You could make it faster using a custom regexp for other that matches more characters at a time, but this is the easiest approach.

0reactions
wavebeemcommented, Jan 29, 2021

Yeah, the regexp solution is often difficult, haha.

All I meant was that bread-n-butter is SemVer 0.x, so releases may contain breaking changes. Maybe I will update that text later 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

System Of A Down - Question! (Official HD Video) - YouTube
Official HD music video for ” Question !" by System of a DownListen to System of a Down: https://SystemOfADown.lnk.to/listenYDSubscribe to the ...
Read more >
Question Definition & Meaning - Merriam-Webster
noun ; b · a subject or aspect in dispute or open for discussion : issue ; d · the specific point at...
Read more >
Question Definition & Meaning | Dictionary.com
a problem for discussion or under discussion; a matter for investigation. a matter of some uncertainty or difficulty; problem (usually followed by of):...
Read more >
Meaning of question in English - Cambridge Dictionary
a sentence or phrase used to find out information: The police asked me questions all day. Why won't you answer my question?
Read more >
Question - Wikipedia
A question is an utterance which serves as a request for information. Questions are sometimes distinguished from interrogatives, which are the grammatical ...
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