class DataMetaDom::PythonLexer::PyRegExRoster

Augment the RegExRoster class with Python specifics

Public Instance Methods

to_patterns() click to toggle source

converts the registry to the Python variable – compiled Re

# File lib/dataMetaDom/python.rb, line 46
def to_patterns
    i_to_r.keys.map { |ix|
        r = i_to_r[ix]
        rx = r.r.to_s
        %<#{RegExRoster.ixToVarName(ix)} = re.compile(#{rx.inspect}) # #{r.vars.to_a.sort.join(', ')}>
    }.join("\n#{INDENT}")
end
to_verifications(baseName) click to toggle source

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

# File lib/dataMetaDom/python.rb, line 55
        def to_verifications(baseName)
            result = (canned.keys.map { |r|
                r = canned[r]
                vs = r.vars.to_a.sort
                vs.map { |v|
                    rx = r.r.to_s
                    %<\n#{INDENT*2}if(#{r.req? ? '' : "self.__#{v} is not None and "}CannedRe.CANNED_RES[#{rx.inspect}].match(self.__#{v}) is None):
#{INDENT*3}raise AttributeError("Property \\"#{v}\\" == {{%s}} didn't match canned expression \\"#{rx}\\"" % self.__#{v} )>
                }
            }).flatten
            (result << i_to_r.keys.map { |ix|
                r = i_to_r[ix]
                vs = r.vars.to_a.sort
                rv = "#{baseName}.#{RegExRoster.ixToVarName(ix)}"
                vs.map { |v|
                    %<\n#{INDENT*2}if(#{r.req? ? '' : "self.__#{v} is not None and "}#{rv}.match(self.__#{v}) is None):
#{INDENT*3}raise AttributeError("Property \\"#{v}\\" == {{%s}} didn't match custom expression {{%s}}" %(self.__#{v}, #{rv}))>
                }
            }).flatten
            result.join("\n")
        end