File: ignored.rb

package info (click to toggle)
ruby-parslet 2.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,260 kB
  • sloc: ruby: 6,157; sh: 8; javascript: 3; makefile: 3
file content (26 lines) | stat: -rw-r--r-- 525 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Ignores the result of a match.
#
# Example:
#
#   str('foo')            # will return 'foo',
#   str('foo').ignore     # will return nil
#
class Parslet::Atoms::Ignored < Parslet::Atoms::Base
  attr_reader :parslet
  def initialize(parslet)
    super()

    @parslet = parslet
  end

  def apply(source, context, consume_all)
    success, _ = result = parslet.apply(source, context, consume_all)

    return result unless success
    succ(nil)
  end
  
  def to_s_inner(prec)
    "ignored(#{parslet.to_s(prec)})"
  end
end