Class: LegacyPattern

Inherits:
PatternBase show all
Defined in:
lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb

Overview

LegacyPattern allows for a hash to be treated as a Pattern It implements the minimum required to be sucessfully generated by the grammar

Instance Attribute Summary

Attributes inherited from PatternBase

#arguments, #match, #next_pattern, #original_arguments

Instance Method Summary collapse

Methods inherited from PatternBase

#==, #__deep_clone_self__, #collect_group_attributes, #convert_group_attributes_to_captures, #convert_includes_to_patterns, #do_add_attributes, #do_collect_self_groups, #do_evaluate_self, #do_get_to_s_name, #each, #eql?, #evaluate_operator, #fixup_regex_references, #groupless, #groupless?, #hash, #insert, #inspect, #lookAheadFor, #lookAheadToAvoid, #lookAround, #lookBehindFor, #lookBehindToAvoid, #map, #map_includes!, #matchResultOf, #maybe, #name, #needs_to_capture?, #oneOf, #oneOrMoreOf, #optimize_outer_group?, #or, #placeholder, #raise_if_regex_has_capture_group, #reTag, #recursivelyMatch, #resolve, #run_self_tests, #self_scramble_references, #single_entity?, #then, #to_r, #to_s, #transform_includes, #transform_tag_as, #zeroOrMoreOf

Constructor Details

#initialize(hash) ⇒ LegacyPattern

Returns a new instance of LegacyPattern.



10
11
12
13
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 10

def initialize(hash)
    super("placeholder")
    @hash = hash.transform_keys(&:to_sym)
end

Instance Method Details

#__deep_clone__PatternBase

Deeply clone self

Returns:



58
59
60
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 58

def __deep_clone__
    self.class.new(@hash)
end

#evaluate(*_ignored) ⇒ Object

LegacyPattern cannot be evaluated



16
17
18
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 16

def evaluate(*_ignored)
    raise "LegacyPattern cannot be used as a part of a Pattern"
end

#insert!(_pattern) ⇒ Object

LegacyPattern cannot be chained



21
22
23
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 21

def insert!(_pattern)
    raise "LegacyPattern cannot be used as a part of a Pattern"
end

#map! {|self| ... } ⇒ self

Uses a block to transform all Patterns in the list

Parameters:

  • map_includes (Boolean)

    should include patterns be mapped?

Yields:

  • (self)

    invokes the block with self for modification

Returns:

  • (self)


44
45
46
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 44

def map!(*)
    self
end

#run_testsBoolean

Runs the unit tests, recursively

Returns:

  • (Boolean)

    If all test passed return true, otherwise false



37
38
39
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 37

def run_tests
    true
end

#start_patternself

To aid in Linters all Patterns support start_pattern which return the pattern for initial match, for a single match pattern that is itself

Returns:

  • (self)

    This pattern



51
52
53
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 51

def start_pattern
    ""
end

#to_tagHash

converts a PatternBase to a Hash representing a textmate rule

Returns:

  • (Hash)

    The pattern as a textmate grammar rule

  • (Hash)

    The hash it was constructed with



30
31
32
# File 'lib/ruby_grammar_builder/pattern_variations/legacy_pattern.rb', line 30

def to_tag
    @hash
end