Sha256: d1bd7078acc6bdd5517ad892aace942c36d21ba5c63d07e267caa174b30a1a4a

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# File: anchor.rb

require_relative "atomic_expression"	# Access the superclass

module Regex # This module is used as a namespace
  # An anchor is a zero-width assertion based on the current position.
  class Anchor < AtomicExpression
    # A Hash for converting a lexeme to a symbolic value
    AnchorToSymbol = {
      # Lexeme => Symbol value
      '^' => :soLine,	# Start of line
      '$' => :eoLine,	# End of line
      '\A' => :soSubject,
      '\b' => :wordBoundary,
      '\B' => :nonAtWordBoundary,
      '\G' => :firstMatch,
      '\z' => :eoSubject,
      '\Z' => :eoSubjectOrBeforeNLAtEnd
    }

    # A symbolic value that identifies the type of assertion to perform
    attr_reader(:kind)

    # Constructor
    # @param aKind [String] Lexeme representation of the anchor
    def initialize(aKind)
      @kind = valid_kind(aKind)
    end

    public

    # Conversion method re-definition.
    # Purpose: Return the String representation of the expression.
    def to_str()
      return AnchorToSymbol.rassoc(kind).first()
    end

    private

    # Return the symbolic value corresponding to the given lexeme.
    def valid_kind(aKind)
      return AnchorToSymbol[aKind]
    end

  end # class
end # module

# End of file

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rley-0.6.00 examples/general/SRL/lib/regex/anchor.rb
rley-0.5.14 examples/general/SRL/lib/regex/anchor.rb
rley-0.5.13 examples/general/SRL/lib/regex/anchor.rb
rley-0.5.12 examples/general/SRL/lib/regex/anchor.rb