Class: DataMetaDom::PojoLexer::JavaRegExRoster

Inherits:
RegExRoster
  • Object
show all
Defined in:
lib/dataMetaDom/pojo.rb

Overview

Augment the class with Java specifics

Instance Attribute Summary

Attributes inherited from RegExRoster

#canned, #i_to_r, #r_to_i

Instance Method Summary collapse

Methods inherited from RegExRoster

#initialize, ixToVarName, #register

Constructor Details

This class inherits a constructor from DataMetaDom::RegExRoster

Instance Method Details

#to_patternsObject

converts the registry to the java declarations for the class



46
47
48
49
50
51
52
53
# File 'lib/dataMetaDom/pojo.rb', line 46

def to_patterns
    i_to_r.keys.map { |ix|
       r = i_to_r[ix]
       rx = r.r.to_s
       %<#{INDENT}private static final java.util.regex.Pattern #{RegExRoster.ixToVarName(ix)} = // #{r.vars.to_a.sort.join(', ')}
#{INDENT*2}java.util.regex.Pattern.compile(#{rx.inspect});>
    }.join("\n\n")
end

#to_verificationsObject

converts the registry to the verification code for the verify() method



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/dataMetaDom/pojo.rb', line 56

def to_verifications
    result = (canned.keys.map { |r|
        r = canned[r]
        vs = r.vars.to_a.sort
        vs.map { |v|
            rx = r.r.to_s
            %<#{INDENT*2}if(#{r.req? ? '' : "#{v} != null && "}!getCannedRegEx(#{rx.inspect}).matcher(#{v}).matches())
#{INDENT*3}throw new VerificationException("Variable \\"#{v}\\" == {{" + #{v} + "}} didn't match canned expression \\"#{rx}\\"" );>
        }
    }).flatten
    (result << i_to_r.keys.map { |ix|
        r = i_to_r[ix]
        vs = r.vars.to_a.sort
        rv = RegExRoster.ixToVarName(ix)
        vs.map { |v|
           %<#{INDENT*2}if(#{r.req? ? '' : "#{v} != null && "}!#{rv}.matcher(#{v}).matches())
#{INDENT*3}throw new VerificationException("Variable \\"#{v}\\" == {{" + #{v} + "}} didn't match custom expression {{" + #{rv} + "}}");>
        }
    }).flatten
    result.join("\n")

end