Class: OracleSqlParser::Grammar::ReservedWordGenerator::KeywordRule

Inherits:
Object
  • Object
show all
Defined in:
lib/oracle-sql-parser/grammar/reserved_word_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword) ⇒ KeywordRule

Returns a new instance of KeywordRule.



13
14
15
# File 'lib/oracle-sql-parser/grammar/reserved_word_generator.rb', line 13

def initialize(keyword)
  @keyword = keyword
end

Instance Attribute Details

#keywordObject (readonly)

Returns the value of attribute keyword.



12
13
14
# File 'lib/oracle-sql-parser/grammar/reserved_word_generator.rb', line 12

def keyword
  @keyword
end

Instance Method Details

#matcherObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oracle-sql-parser/grammar/reserved_word_generator.rb', line 33

def matcher
  matcher = []
  keyword.each_char do |ch|
    if ch.match(/[A-Z]/)
      matcher << "[#{ch.downcase}#{ch.upcase}]"
    else
      matcher << "'#{ch}'"
    end
  end
  matcher << '( ![A-Za-z0-9] )'
  matcher.join(' ')
end

#rule_nameObject



29
30
31
# File 'lib/oracle-sql-parser/grammar/reserved_word_generator.rb', line 29

def rule_name
  "#{@keyword.downcase}_keyword"
end

#to_sObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/oracle-sql-parser/grammar/reserved_word_generator.rb', line 17

def to_s
  content = []
  content << "    rule #{rule_name}"
  content << "      #{matcher} {"
  content << "        def ast"
  content << "          OracleSqlParser::Ast::Keyword.new(:name => text_value)"
  content << "        end"
  content << "      }"
  content << "    end"
  content.join("\n")
end