Class: IncludesThenTagAs

Inherits:
GrammarLinter show all
Defined in:
lib/ruby_grammar_builder/linters/includes_then_tag_as.rb

Overview

A pattern that has an includes cannot have any tag_as in @match

Instance Method Summary collapse

Methods inherited from GrammarLinter

#post_lint

Methods inherited from GrammarPlugin

display_options, options

Instance Method Details

#pre_lint(pattern, options) ⇒ Boolean

Runs the linter on each pattern

Parameters:

  • pattern (PatternBase, Symbol, Hash)

    the pattern to lint

  • options (Hash)

    hash of any of the option keys provided by self.options. options will only be populated when pattern is a PatternBase

Returns:

  • (Boolean)

    the result of the lint



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ruby_grammar_builder/linters/includes_then_tag_as.rb', line 30

def pre_lint(pattern, options)
    return true unless pattern.is_a? PatternBase
    return true if pattern.is_a? PatternRange

    return false unless pre_lint(pattern.match, options)

    return true unless pattern.arguments[:includes].is_a? Array
    return true unless tag_as?(pattern.match)

    name = pattern.name
    puts "The pattern `#{name}' has both an includes argument and a match argument that,"
    puts "it or a sub pattern has a tag_as argument."
    puts "this is not supported"

    true # TODO: fix issue
end

#tag_as?(pattern) ⇒ Boolean

Does pattern or any of its children / siblings have a tag_as

Parameters:

Returns:

  • (Boolean)

    if any of the patterns have a tag_as



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_grammar_builder/linters/includes_then_tag_as.rb', line 16

def tag_as?(pattern)
    return false unless pattern.is_a? PatternBase

    pattern.each do |s|
        puts s.arguments[:tag_as] if s.arguments[:tag_as]
        return true if s.arguments[:tag_as]
    end

    false
end