class Terse::KeywordJava

A class storing all information about a keyword & what it should be transformed into

Public Class Methods

generate_keywords() click to toggle source
# 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
new(keyword) click to toggle source
Calls superclass method Terse::Keyword::new
# File lib/terse/keyword_java.rb, line 8
def initialize(keyword)
    super(keyword)
    @loop_ending = "}"
    @line_ending = ";"
end

Public Instance Methods

gen_regex_from_keyword(keyword) click to toggle source

Simple regex to match a keyword

# 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) click to toggle source

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”'

# 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