Class: Terse::KeywordJava
Overview
A class storing all information about a keyword & what it should be transformed into
Instance Attribute Summary
Attributes inherited from Keyword
#follow_on_regex, #follow_on_substitute, #is_end, #keyword, #needs_inner_end, #needs_inner_start, #needs_line_ending, #needs_top_level_end, #needs_top_level_start, #regex, #substitute, #try_follow_on_regex
Class Method Summary collapse
Instance Method Summary collapse
-
#gen_regex_from_keyword(keyword) ⇒ Object
Simple regex to match a keyword.
-
#gen_regex_from_keyword_including_follow_on(keyword) ⇒ Object
Regex to match a keyword at the start of a line, and the next word on that line E.g.
-
#initialize(keyword) ⇒ KeywordJava
constructor
A new instance of KeywordJava.
Constructor Details
#initialize(keyword) ⇒ KeywordJava
Returns a new instance of KeywordJava.
8 9 10 11 12 |
# File 'lib/terse/keyword_java.rb', line 8 def initialize(keyword) super(keyword) @loop_ending = "}" @line_ending = ";" end |
Class Method Details
.generate_keywords ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/terse/keyword_java.rb', line 28 def self.generate_keywords keywords = [] keys = [:imp, :pk, :c, :ex, :impl, :int, :ab, :e, :st, :v, :m, :p, :pt, :pv, :r, :s, :i, :b, :f, :fn] keys.each do |key| k = KeywordJava.new key # k.keyword = key case key when :imp k.substitute = "import" k.needs_line_ending = true when :pk k.substitute = "package" k.needs_line_ending = true when :c k.substitute = "class" k.needs_top_level_start = true k.needs_top_level_end = true when :ex k.substitute = "extends" when :impl k.substitute = "implements" when :int k.substitute = "interface" when :ab k.substitute = "abstract" when :e k.substitute = "enum" k.needs_top_level_start = true k.needs_top_level_end = true when :st k.substitute = "static" k.needs_line_ending = true when :v k.substitute = "void" k.needs_inner_start = true k.needs_inner_end = true when :m k.substitute = "main" when :p k.substitute = "public" k.needs_line_ending = true when :pt k.substitute = "protected" k.needs_line_ending = true when :pv k.substitute = "private" k.needs_line_ending = true when :r k.substitute = "return" k.needs_inner_end = true k.needs_line_ending = true when :s k.substitute = "String" k.needs_line_ending = true when :i k.substitute = "Integer" k.needs_line_ending = true when :b k.substitute = "Boolean" k.needs_line_ending = true when :f k.substitute = "Float" k.needs_line_ending = true when :fn k.substitute = "final" k.needs_line_ending = true else # raise "Unknown keyword #{key}" puts "Unknown keyword #{key}" end keywords << k end # end keys.each keywords end |
Instance Method Details
#gen_regex_from_keyword(keyword) ⇒ Object
Simple regex to match a keyword
15 16 17 18 |
# File 'lib/terse/keyword_java.rb', line 15 def gen_regex_from_keyword keyword # return /(^|\s+)(#{keyword})(\s+|$)/ return /(^|\s+|\w*\()(#{keyword})(\s+|$)/ end |
#gen_regex_from_keyword_including_follow_on(keyword) ⇒ Object
Regex to match a keyword at the start of a line, and the next word on that line E.g. this will also catch (in $3) the item following the “require” keyword This enables the routine to format this follow-on word, e.g. to turn ‘req a_gem’ into ‘require “a_gem”’
24 25 26 |
# File 'lib/terse/keyword_java.rb', line 24 def gen_regex_from_keyword_including_follow_on keyword return /(^|\s+)(#{keyword})\s+([a-zA-Z0-9_]+)/ end |