Class: DataMetaDom::PythonLexer::PyRegExRoster
- Inherits:
-
RegExRoster
- Object
- RegExRoster
- DataMetaDom::PythonLexer::PyRegExRoster
- Defined in:
- lib/dataMetaDom/python.rb
Overview
Augment the RegExRoster class with Python specifics
Instance Attribute Summary
Attributes inherited from RegExRoster
Instance Method Summary collapse
-
#to_patterns ⇒ Object
converts the registry to the Python variable – compiled Re.
-
#to_verifications(baseName) ⇒ Object
converts the registry to the verification code for the verify() method.
Methods inherited from RegExRoster
#initialize, ixToVarName, #register
Constructor Details
This class inherits a constructor from DataMetaDom::RegExRoster
Instance Method Details
#to_patterns ⇒ Object
converts the registry to the Python variable – compiled Re
46 47 48 49 50 51 52 |
# 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) ⇒ Object
converts the registry to the verification code for the verify() method
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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 |