Class: Peggy::Literal

Inherits:
Element show all
Defined in:
lib/parse/builder.rb

Overview

Matcher of a literal string or regular expression.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Element

build, #report

Constructor Details

#initialize(value = nil) ⇒ Literal

Init the value.



290
291
292
# File 'lib/parse/builder.rb', line 290

def initialize value=nil
  @value = value
end

Instance Attribute Details

#valueObject

Value to match.



287
288
289
# File 'lib/parse/builder.rb', line 287

def value
  @value
end

Instance Method Details

#match(parser, index) ⇒ Object

Match the literal value. If it matches the end index is returned. If no, NO_MATCH is returned.



303
304
305
# File 'lib/parse/builder.rb', line 303

def match parser, index
  report parser.literal?(value, index)
end

#to_sObject

Convert element to String.



308
309
310
# File 'lib/parse/builder.rb', line 308

def to_s
  value.inspect
end