Class: Citrus::NotPredicate

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

Overview

A NotPredicate is a Nonterminal that contains a rule that must not match. Upon success an empty match is returned and no input is consumed. The Citrus notation is any expression preceded by an exclamation mark, 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 = '') ⇒ NotPredicate

Returns a new instance of NotPredicate.



1036
1037
1038
# File 'lib/citrus.rb', line 1036

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.



1046
1047
1048
1049
1050
1051
1052
1053
1054
# File 'lib/citrus.rb', line 1046

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

  events
end

#ruleObject

Returns the Rule object this rule uses to match.



1041
1042
1043
# File 'lib/citrus.rb', line 1041

def rule
  rules[0]
end

#to_citrusObject

Returns the Citrus notation of this rule as a string.



1057
1058
1059
# File 'lib/citrus.rb', line 1057

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