Class: Citrus::AndPredicate

Inherits:
Object show all
Includes:
Nonterminal
Defined in:
lib/citrus.rb

Overview

An AndPredicate is a Nonterminal that contains a rule that must match. Upon success an empty match is returned and no input is consumed. The Citrus notation is any expression preceded by an ampersand, e.g.:

&expr

Instance Attribute Summary

Attributes included from Nonterminal

#rules

Attributes included from Rule

#extension, #grammar, #label, #name

Instance Method Summary collapse

Methods included from Nonterminal

#grammar=

Methods included from Rule

#==, #===, #default_options, #elide?, #extend_match, for, #inspect, #needs_paren?, #parse, #terminal?, #test, #to_embedded_s, #to_s

Constructor Details

#initialize(rule = '') ⇒ AndPredicate

Returns a new instance of AndPredicate.



1001
1002
1003
# File 'lib/citrus.rb', line 1001

def initialize(rule='')
  super([rule])
end

Instance Method Details

#exec(input, events = []) ⇒ Object

Returns an array of events for this rule on the given input.



1011
1012
1013
1014
1015
1016
1017
1018
1019
# File 'lib/citrus.rb', line 1011

def exec(input, events=[])
  if input.test(rule)
    events << self
    events << CLOSE
    events << 0
  end

  events
end

#ruleObject

Returns the Rule object this rule uses to match.



1006
1007
1008
# File 'lib/citrus.rb', line 1006

def rule
  rules[0]
end

#to_citrusObject

Returns the Citrus notation of this rule as a string.



1022
1023
1024
# File 'lib/citrus.rb', line 1022

def to_citrus # :nodoc:
  '&' + rule.to_embedded_s
end