Hi Nigel,
thanks for that, very nice work, and i think you got the message that
i've merged it.
PS: I would have responded faster, but i have a house to build. Now i'm
glad i didn't though :-)
Just to let you know, I have now extracted the parser into it's own gem.
No other dependencies but Parslet.
And you may have seen 252 tests, so a safe playground.
Btw, you can invoke a single test by, eg : ruby test/test_fail.rb
So, if you would want to spend more time improving it, like removing the
necessity for braces, or mult-assignment (nice and jucy stuff), i would
be happy to give you write access.
The repo is here https://github.com/ruby-in-ruby/crystal-reader
Thanks
Torsten
Nigel Thorne <mailto:[email protected]>
4 Jun 2014 15:27
Ok, I've sent a pull request that detects infinite loops. .
Basically within a repeat atom, where there is no max specified, if
you get an iteration of the 'repeat' that matches a zero length,
nothing will stop you doing that again on the next iteration, so you
are in an infinite loop.
It would be nice to detect it statically, but at least this way while
unit testing you should spot the problem.
Cheers
Nigel
---
"Man, I'm going to have so many chickens when this lot hatch!"
Nigel Thorne <mailto:[email protected]>
4 Jun 2014 06:59
Sure. That sounds very possible.
Kaspar Schiess <mailto:[email protected]>
3 Jun 2014 18:48
We could detect loops.. contributions welcome ;)
(Like in 'debug' mode, for speed reasons)
kaspar
Nigel Thorne <mailto:[email protected]>
3 Jun 2014 14:04
Hi.
Great work on the parser. It's looking smashing.
You get hanging when you have a rule that can execute without
consuming anything.
I find that naming any rule that can possibly consume nothing with a
"?" at then end of the rule name makes it easier to statically analyse
the rules in turn to find the problem.
I have seen people monkey patch the parser to get a trace of the parse
as it runs.. so you can see where your grammar gets stuck.
That sounds like it might help.
---
"No man is an island... except Philip"
Torsten Ruger <mailto:[email protected]>
3 Jun 2014 09:59
So,
I am adding features to my parser at an amazing rate, 250+ tests
already. It's so easy that i catch myself thinking i am cheating.
The other day i added qualified function calls in like 10 minutes or so.
_Great_
But now i have hit this "hanging" issue and am not sure how to even
debug. Generally speaking, sometimes when i make a small typing mistake,
instead of getting an error from parslet i get silence. No matter how
long i let it run, when i interrupt, it's always about the same
stack-trace (below):
I put a test case for this up :
https://github.com/ruby-in-ruby/crystal/blob/master/test/parser/test_fails.rb
If you look, it defines a function in a class, and generally speaking
that works.
But the case has no brackets on the function, as is legal in ruby. But I
haven't implemented that, so in my parser it's not legal.
Iif i add () after the function it works.
The function is defined here:
https://github.com/ruby-in-ruby/crystal/blob/master/lib/parser/call_site.rb
but i that alone can't be the problem, because outside a class
definition i do get the error, not the hang.
So, as i said, any clues to how i can debug that kind of thing ?
Torsten
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/source.rb:84:in
`bytepos=': Interrupt
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/context.rb:46:in
`try_with_cache'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:83:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/repetition.rb:35:in
`block in try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/repetition.rb:34:in
`loop'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/repetition.rb:34:in
`try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/context.rb:31:in
`try_with_cache'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:83:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/named.rb:17:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/sequence.rb:29:in
`block in try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/sequence.rb:27:in
`each'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/sequence.rb:27:in
`each_with_index'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/sequence.rb:27:in
`try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/context.rb:31:in
`try_with_cache'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:83:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/entity.rb:21:in
`try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/context.rb:31:in
`try_with_cache'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:83:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/alternative.rb:35:in
`block in try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/alternative.rb:34:in
`map'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/alternative.rb:34:in
`try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/context.rb:31:in
`try_with_cache'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:83:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/repetition.rb:35:in
`block in try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/repetition.rb:34:in
`loop'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/repetition.rb:34:in
`try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/context.rb:31:in
`try_with_cache'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:83:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/entity.rb:21:in
`try'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/context.rb:31:in
`try_with_cache'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:83:in
`apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:70:in
`setup_and_apply'
from
/Users/raisa/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/parslet-1.6.1/lib/parslet/atoms/base.rb:30:in
`parse'