Skip to content
This repository has been archived by the owner on Feb 6, 2019. It is now read-only.

Non greedy regular expressions aren't working. #56

Open
jonhue opened this issue Jan 20, 2019 · 1 comment
Open

Non greedy regular expressions aren't working. #56

jonhue opened this issue Jan 20, 2019 · 1 comment

Comments

@jonhue
Copy link

jonhue commented Jan 20, 2019

I have a grammar that uses this regex to match comments (it's in the extras array):

comment: $ => /((\/\/[^\r\n]*)|(\/\*(.|\s)*?\*\/))/

This fails on the following test:

=====================================
Comments
=====================================

1 // C$mment
1// C$mment
1/* C$mment
C$mment

C$mment*/
1

---

(file
  (integer) (comment)
  (integer) (comment)
  (integer) (comment)
  (integer))

However, when I make the regex greedy (/((\/\/[^\r\n]*)|(\/\*(.|\s)*\*\/))/), the test is successful. The regex has to be non greedy for cases like this:

1 // C$mment
1// C$mment
1/* C$mment
C$mment

C$mment*/ + 1
/* C$mment */
1
@maxbrunsfeld
Copy link
Contributor

Yeah, non-greedy regexes are not supported.

It looks like you're trying to match C-style comments. If so, have you tried this regex?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants