This is somewhat difficult to explain, so please bear with me...
Last night while working on a grammar, I added a pattern-block that made Atom hang at 100% CPU usage. After force-quitting the app twice, I scrutinised the last expression for anything that might've triggered infinite recursion. I was drawing blanks until I narrowed it down from this...
((?:\\s*(?:'[^']*'?|[A-Za-z_∆⍙]+[\\w∆⍙¯]*|\\d+))+)
\\s*
( ALPHA | BRAVO )
\\s*
((?:\\s*(?:'[^']*'?|[A-Za-z_∆⍙]+[\\w∆⍙¯]*|\\d+))+)
... to this:
((?:\\s*(?:'[^']*'?|[A-Za-z_∆⍙]+[\\w∆⍙¯]*|\\d+))+)
\\s*
( ALPHA )
\\s*
((?:\\s*(?:'[^']*'?|[A-Za-z_∆⍙]+[\\w∆⍙¯]*|\\d+))+)
All of a sudden, Atom wasn't hanging whenever I switched to the tab that had the grammar's language in it. The patterns themselves didn't match anything. What the patterns were was irrelevant. What's important is that, somehow, this particular capturing group causes Atom to freeze.
I know how good First-Mate is at avoiding infinite loops, which is why this bug is concerning.
I've isolated it to a separate branch in my repo for closer examination.
Reproduction
- Clone and checkout the repo's bug-branch:
git clone https://github.com/Alhadis/language-apl.git && cd language-apl
git checkout fatal-idioms
apm link -d . && atom -d .
- Open
tests/life.apl. It should be fine.
- Run
make in the package's base directory to toggle the problematic capturing group.
- Close
tests/life.apl and restart Atom
- Reopen
tests/life.apl
I noticed Lightshow also has troubles with this particular ruleset, although its handling is somewhat less predictable than Atom's.