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
(Discussed on Discord, posting here for future visibility)
It's common to have languages where it's desirable to support expressions like "true or false" without caring about the whitespace (e.g. true or false is also valid).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
(Discussed on Discord, posting here for future visibility)
It's common to have languages where it's desirable to support expressions like
"true or false"
without caring about the whitespace (e.g.true or false
is also valid).A simple solution would look like this:
However, this parser will also accept strings such as
trueorfalse
, which is usually undesirable.The solution to this is to use either positive or negative lookahead.
Personally, I think negative lookahead it's a bit easier to use, as one only needs to enumerate the valid keyword characters.
In this case, it would look something like this:
I recommend using a helper like the
keyword
above, since this is something that can pop up in multiple places.Scastie with the full example: https://scastie.scala-lang.org/e2xliCubRjiQZbdpinWNsA
Beta Was this translation helpful? Give feedback.
All reactions