The grammar is wrong. It can't be satisfied.
- Every
file
ends with a clause
.
- Every
clause
ends with a '0'
.
- The
literal
in the clause
, being a greedy reg-exp,will eat
the final '0'
.
Conclusion: No clause
will ever be found.
For example ...
=> (parser "60")
Parse error at line 1, column 3:
60
^
Expected one of:
"0"
#"\s+"
#"-\d+"
#"[1-9]\d*"
We can parse a literal
=> (parser "60" :start :literal)
("60")
... but not a clause
=> (parser "60" :start :clause)
Parse error at line 1, column 3:
60
^
Expected one of:
"0" (followed by end-of-string)
#"\s+"
#"-\d+"
#"[1-9]\d*"
Why is it so slow?
If there is a comment
:
- it can swallow the whole file;
- or be broken at any
'c'
character into successive comment
s;
- or terminate at any point after the initial
'c'
.
This implies that every tail has to be presented to the rest of the grammar, which includes a reg-exp for literal
that Instaparse can't see inside. Hence all have to be tried, and all will ultimately fail. No wonder it's slow.
I suspect that this file is actually divided into lines. And that your problems arise from trying to conflate newlines with other forms of white-space.
May I gently point out that playing with a few tiny examples - which is all I've done - might have saved you a deal of trouble.