Class: RDParser::ParseMatcher::Parse

Inherits:
Object
  • Object
show all
Defined in:
lib/rdparser/parse_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(expression, root) ⇒ Parse

Returns a new instance of Parse.



3
4
5
6
# File 'lib/rdparser/parse_matcher.rb', line 3

def initialize expression, root
  @expression = expression
  @root       = root
end

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/rdparser/parse_matcher.rb', line 25

def description
  %{parse "#{@expression}" starting with :#{@root}} + (@expected_error_on_position && %{ and with first error on position #{@expected_error_on_position.to_s}} || '')
end

#failure_messageObject



17
18
19
# File 'lib/rdparser/parse_matcher.rb', line 17

def failure_message
  %{Grammar should parse "#{@expression}" starting with :#{@root} but error was catched on position #{@error_on_position}! "#{@expression[0...@error_on_position]}|#{@expression[@error_on_position..@error_on_position]}|#{@expression[@error_on_position+1..-1]}"}
end

#matches?(parser) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'lib/rdparser/parse_matcher.rb', line 8

def matches? parser
  parser.parse(@root, @expression).kind_of?(Array)
  return true
rescue RDParser::ParseError
  @error_on_position = $!.position
  @error_in_content  = $!.content
  return false
end

#negative_failure_messageObject



21
22
23
# File 'lib/rdparser/parse_matcher.rb', line 21

def negative_failure_message
  %{Grammar should not parse "#{@expression}" starting with :#{@root}} + (@expected_error_on_position && %{ and first error should appear on position #{@expected_error_on_position}} || '') + %{!}
end

#with(position) ⇒ Object



29
30
31
32
# File 'lib/rdparser/parse_matcher.rb', line 29

def with position
  @expected_error_on_position = position
  self
end