Class: RDParser::ParseMatcher::Parse
- Inherits:
-
Object
- Object
- RDParser::ParseMatcher::Parse
- Defined in:
- lib/rdparser/parse_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(expression, root) ⇒ Parse
constructor
A new instance of Parse.
- #matches?(parser) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #with(position) ⇒ Object
Constructor Details
Instance Method Details
#description ⇒ Object
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_message ⇒ Object
17 18 19 |
# File 'lib/rdparser/parse_matcher.rb', line 17 def %{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
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_message ⇒ Object
21 22 23 |
# File 'lib/rdparser/parse_matcher.rb', line 21 def %{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 |