Skip to content
Newer
Older
100644 44 lines (35 sloc) 1.08 KB
c4b4d25 @kschiess ! Fixes interaction with mathn
authored Dec 15, 2011
1 # Demonstrates that we have a compatibility fix to mathn's weird idea of
2 # integer mathematics.
3 # This was contributed by Jonathan Hinkle (https://github.com/hynkle). Thanks!
4
5 $:.unshift File.dirname(__FILE__) + "/../lib"
6
7 require 'parslet'
8 require 'parslet/convenience'
9 include Parslet
10
11 def attempt_parse
12 possible_whitespace = match['\s'].repeat
13
14 cephalopod =
15 str('octopus') |
16 str('squid')
17
18 parenthesized_cephalopod =
19 str('(') >>
20 possible_whitespace >>
21 cephalopod >>
22 possible_whitespace >>
23 str(')')
24
25 parser =
26 possible_whitespace >>
27 parenthesized_cephalopod >>
28 possible_whitespace
29
30 # This parse fails, but that is not the point. When mathn is in the current
31 # ruby environment, it modifies integer division in a way that makes
32 # parslet loop indefinitely.
33 parser.parse %{(\nsqeed)\n}
34 rescue Parslet::ParseFailed
35 end
36
37 attempt_parse
38 puts 'it terminates before we require mathn'
39
40 puts "requiring mathn now"
41 require 'mathn'
42 puts "and trying again (will hang without the fix)"
43 attempt_parse # but it doesn't terminate after requiring mathn
44 puts "okay!"
Something went wrong with that request. Please try again.