Class: AddEnding

Inherits:
GrammarTransform show all
Defined in:
lib/ruby_grammar_builder/transforms/add_ending.rb

Overview

Adds the last portion of the scope name to each tag_as if not already present

Instance Method Summary collapse

Methods inherited from GrammarTransform

#post_transform

Methods inherited from GrammarPlugin

display_options, options

Instance Method Details

#pre_transform(pattern, options) ⇒ Object

adds the ending to any tag_as in pattern if needed



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ruby_grammar_builder/transforms/add_ending.rb', line 10

def pre_transform(pattern, options)
    return pattern.map { |v| pre_transform(v, options) } if pattern.is_a? Array
    return pattern unless pattern.is_a? PatternBase

    ending = options[:grammar].ending
    pattern.transform_tag_as do |tag_as|
        tag_as.split(" ").map do |tag|
            next tag if tag.end_with?(ending)

            tag + "." + ending
        end.join(" ")
    end
end