Sha256: ca865d2210568671d0f31e9db680531a8e524e9d987956f5e8be1fc3d855d679

Contents?: true

Size: 1.48 KB

Versions: 13

Compression:

Stored size: 1.48 KB

Contents

module RegexpExamples
  # A collection of related helper methods, utilised by the `Parser` class
  module ParseGroupHelper
    protected

    def parse_caret
      if @current_position == 0
        PlaceHolderGroup.new # Ignore the "illegal" character
      else
        raise_anchors_exception!
      end
    end

    def parse_dollar
      if @current_position == (regexp_string.length - 1)
        PlaceHolderGroup.new # Ignore the "illegal" character
      else
        raise_anchors_exception!
      end
    end

    def parse_extended_whitespace
      if @extended
        skip_whitespace
        PlaceHolderGroup.new # Ignore the whitespace/comment
      else
        parse_single_char_group(next_char)
      end
    end

    def skip_whitespace
      whitespace_chars = rest_of_string.match(/#.*|\s+/)[0]
      @current_position += whitespace_chars.length - 1
    end

    def parse_single_char_group(char)
      SingleCharGroup.new(char, @ignorecase)
    end

    def parse_char_group
      @current_position += 1 # Skip past opening "["
      chargroup_parser = ChargroupParser.new(rest_of_string)
      chargroup_parser.parse
      @current_position += (chargroup_parser.length - 1) # Step back to closing "]"
      CharGroup.new(chargroup_parser.result, @ignorecase)
    end

    def parse_dot_group
      DotGroup.new(@multiline)
    end

    def parse_or_group(left_repeaters)
      @current_position += 1
      right_repeaters = parse
      OrGroup.new(left_repeaters, right_repeaters)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
regexp-examples-1.5.1 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.5.0 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.4.4 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.4.3 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.4.2 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.4.1 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.4.0 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.3.2 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.3.1 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.3.0 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.2.1 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.2.0 lib/regexp-examples/parser_helpers/parse_group_helper.rb
regexp-examples-1.1.4 lib/regexp-examples/parser_helpers/parse_group_helper.rb