Basic question: how to best handle this case
See original GitHub issueHi there, I have a very simple DSL that I’m writing a parser for. However, I’m having trouble coming up with an elegant solution.
The DSL looks like this:
foo
foo or bar
foo or bar or baz
(foo or bar) and baz
So the pattern is (ignoring nested expressions and assuming all tuples are of size 1 or 2):
const word = regex(/.*/)
const separator = alt(
string('or'),
string('and')
)
const expression = alt(
seq(word, separator, word),
word
)
However, word
also matches or
and and
! Words can contain numbers, spaces, and special characters, so I can’t just make the regex more specific. What I ended up doing was adding a negative lookahead to the regex: (?! and )(?! or )
.
Is there a more elegant way to express this, without resorting to negative lookaheads?
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:7
Top Results From Across the Web
10 Case Interview Question Examples (Plus Tips on ... - Indeed
The following are 10 examples of case interview questions. You can use these examples to get a better understanding of how case interview ......
Read more >How to Solve a Case Study – A Structured Approach
1. Restate the question and make sure you understand the problem statement by confirming with the interviewer · 2. Clarify the goals ·...
Read more >Case Interview Questions - MConsultingPrep
There are the four basic steps to answer case interview questions: •Step 1: Clarify any unclear points in the question. •Step 2: Announce...
Read more >100 Case Study Interview Questions [Updated for 2020]
A good case study is designed to build trust. Ask clients to describe the tools and processes they used before your product or...
Read more >10 Common Job Interview Questions and How to Answer Them
How do you deal with pressure or stressful situations? ... When you answer this question, highlight the best traits of your personality and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Something like this might be useful to you:
Output
If that looks useful, feel free to ask questions and I can dive into more detail later.
You’re welcome! Best of luck on your parser.