Sha256: e1e884f9ae631c4c32a37f14a940c049748455d28faae27ef63faa2dde788f22

Contents?: true

Size: 1.08 KB

Versions: 15

Compression:

Stored size: 1.08 KB

Contents

# Demonstrates that we have a compatibility fix to mathn's weird idea of 
# integer mathematics. 
# This was contributed by Jonathan Hinkle (https://github.com/hynkle). Thanks!

$:.unshift File.dirname(__FILE__) + "/../lib"

require 'parslet'
require 'parslet/convenience'
include Parslet

def attempt_parse
  possible_whitespace = match['\s'].repeat

  cephalopod =
    str('octopus') |
    str('squid')

  parenthesized_cephalopod =
    str('(') >>
    possible_whitespace >>
    cephalopod >>
    possible_whitespace >>
    str(')')

  parser =
    possible_whitespace >>
    parenthesized_cephalopod >>
    possible_whitespace

  # This parse fails, but that is not the point. When mathn is in the current
  # ruby environment, it modifies integer division in a way that makes 
  # parslet loop indefinitely.
  parser.parse %{(\nsqeed)\n}
rescue Parslet::ParseFailed
end

attempt_parse 
puts 'it terminates before we require mathn'

puts "requiring mathn now"
require 'mathn'
puts "and trying again (will hang without the fix)"
attempt_parse # but it doesn't terminate after requiring mathn
puts "okay!"

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
parslet-1.8.2 example/mathn.rb
parslet-1.8.1 example/mathn.rb
parslet-1.8.0 example/mathn.rb
swift-pyrite-0.1.1 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/example/mathn.rb
swift-pyrite-0.1.0 vendor/bundle/ruby/2.0.0/gems/parslet-1.7.1/example/mathn.rb
parslet-1.7.1 example/mathn.rb
parslet-1.7.0 example/mathn.rb
parslet-1.6.2 example/mathn.rb
parslet-1.6.1 example/mathn.rb
parslet-1.6.0 example/mathn.rb
parslet-1.5.0 example/mathn.rb
ghazel-parslet-1.4.0.2 example/mathn.rb
ghazel-parslet-1.4.0.1 example/mathn.rb
parslet-1.4.0 example/mathn.rb
parslet-1.3.0 example/mathn.rb