Class: Puppet::Pops::Validation::Checker3_1
- Defined in:
- lib/puppet/pops/validation/checker3_1.rb
Overview
A Validator validates a model.
Validation is performed on each model element in isolation. Each method should validate the model element’s state but not validate its referenced/contained elements except to check their validity in their respective role. The intent is to drive the validation with a tree iterator that visits all elements in a model.
TODO: Add validation of multiplicities - this is a general validation that can be checked for all
Model objects via their metamodel. (I.e an extra call to multiplicity check in polymorph check).
This is however mostly valuable when validating model to model transformations, and is therefore T.B.D
Constant Summary collapse
Instance Attribute Summary collapse
- #acceptor ⇒ Object readonly
Instance Method Summary collapse
-
#assign(o, *args) ⇒ Object
Checks the LHS of an assignment (is it assignable?).
- #assign_AccessExpression(o, *args) ⇒ Object
- #assign_Object(o, *args) ⇒ Object
-
#assign_VariableExpression(o, *args) ⇒ Object
—ASSIGNMENT CHECKS.
-
#check(o) ⇒ Object
Performs regular validity check.
- #check_AccessExpression(o) ⇒ Object
- #check_AssignmentExpression(o) ⇒ Object
-
#check_AttributeOperation(o) ⇒ Object
Checks that operation with :+> is contained in a ResourceOverride or Collector.
- #check_BinaryExpression(o) ⇒ Object
- #check_CallNamedFunctionExpression(o) ⇒ Object
- #check_CaseExpression(o) ⇒ Object
- #check_CollectExpression(o) ⇒ Object
- #check_Factory(o) ⇒ Object
- #check_ImportExpression(o) ⇒ Object
- #check_InstanceReference(o) ⇒ Object
-
#check_LambdaExpression(o) ⇒ Object
A Lambda is a Definition, but it may appear in other scopes that top scope (Which check_Definition asserts).
- #check_MethodCallExpression(o) ⇒ Object
-
#check_NamedAccessExpression(o) ⇒ Object
Only used for function names, grammar should not be able to produce something faulty, but check anyway if model is created programatically (it will fail in transformation to AST for sure).
-
#check_NamedDefinition(o) ⇒ Object
for ‘class’ and ‘define’.
- #check_NodeDefinition(o) ⇒ Object
-
#check_Object(o) ⇒ Object
—CHECKS.
- #check_Parameter(o) ⇒ Object
-
#check_QualifiedName(o) ⇒ Object
No checking takes place - all expressions using a QualifiedName need to check.
-
#check_QualifiedReference(o) ⇒ Object
Checks that the value is a valid UpperCaseWord (a CLASSREF), and optionally if it contains a hypen.
- #check_QueryExpression(o) ⇒ Object
-
#check_RelationshipExpression(o) ⇒ Object
relationship_side: resource | resourceref | collection | variable | quotedtext | selector | casestatement | hasharrayaccesses.
- #check_ResourceDefaultsExpression(o) ⇒ Object
- #check_ResourceExpression(o) ⇒ Object
- #check_UnaryExpression(o) ⇒ Object
- #check_UnlessExpression(o) ⇒ Object
- #check_VariableExpression(o) ⇒ Object
-
#hostname(o, semantic, single_feature_name = nil) ⇒ Object
Performs check if this is a vaid hostname expression.
-
#hostname_Array(o, semantic, single_feature_name) ⇒ Object
Transforms Array of host matching expressions into a (Ruby) array of AST::HostName.
- #hostname_ConcatenatedString(o, semantic, single_feature_name) ⇒ Object
- #hostname_LiteralDefault(o, semantic, single_feature_name) ⇒ Object
- #hostname_LiteralNumber(o, semantic, single_feature_name) ⇒ Object
- #hostname_LiteralRegularExpression(o, semantic, single_feature_name) ⇒ Object
- #hostname_LiteralValue(o, semantic, single_feature_name) ⇒ Object
- #hostname_Object(o, semantic, single_feature_name) ⇒ Object
- #hostname_QualifiedName(o, semantic, single_feature_name) ⇒ Object
- #hostname_QualifiedReference(o, semantic, single_feature_name) ⇒ Object
- #hostname_String(o, semantic, single_feature_name) ⇒ Object
-
#initialize(diagnostics_producer) ⇒ Checker3_1
constructor
Initializes the validator with a diagnostics producer.
-
#query(o) ⇒ Object
Performs check if this is valid as a query.
-
#query_BooleanExpression(o) ⇒ Object
Allows AND, OR, and checks if left/right are allowed in query.
-
#query_ComparisonExpression(o) ⇒ Object
Puppet AST only allows == and !=.
- #query_LiteralBoolean(o) ⇒ Object
- #query_LiteralNumber(o) ⇒ Object
- #query_LiteralString(o) ⇒ Object
-
#query_Object(o) ⇒ Object
Anything not explicitly allowed is flagged as error.
- #query_ParenthesizedExpression(o) ⇒ Object
- #query_QualifiedName(o) ⇒ Object
- #query_VariableExpression(o) ⇒ Object
-
#relation(o, container) ⇒ Object
Performs check if this is valid as a relationship side.
- #relation_AccessExpression(o, rel_expr) ⇒ Object
- #relation_CaseExpression(o, rel_expr) ⇒ Object
- #relation_CollectExpression(o, rel_expr) ⇒ Object
- #relation_ConcatenatedStringExpression(o, rel_expr) ⇒ Object
- #relation_LiteralString(o, rel_expr) ⇒ Object
- #relation_Object(o, rel_expr) ⇒ Object
- #relation_RelationshipExpression(o, rel_expr) ⇒ Object
- #relation_ResourceExpression(o, rel_expr) ⇒ Object
- #relation_SelectorExpression(o, rel_expr) ⇒ Object
- #relation_VariableExpression(o, rel_expr) ⇒ Object
-
#rvalue(o) ⇒ Object
Performs check if this is valid as a rvalue.
- #rvalue_BlockExpression(o) ⇒ Object
- #rvalue_CaseExpression(o) ⇒ Object
- #rvalue_CollectExpression(o) ⇒ Object
- #rvalue_Definition(o) ⇒ Object
-
#rvalue_Expression(o) ⇒ Object
By default, all expressions are reported as being rvalues Implement specific rvalue checks for those that are not.
- #rvalue_IfExpression(o) ⇒ Object
- #rvalue_ImportExpression(o) ⇒ Object
- #rvalue_NodeDefinition(o) ⇒ Object
- #rvalue_ResourceDefaultsExpression(o) ⇒ Object
- #rvalue_ResourceExpression(o) ⇒ Object
- #rvalue_ResourceOverrideExpression(o) ⇒ Object
- #rvalue_UnaryExpression(o) ⇒ Object
- #rvalue_UnlessExpression(o) ⇒ Object
-
#select_SelectorExpression(o) ⇒ Object
Transformation of SelectorExpression is limited to certain types of expressions.
-
#top(o, definition) ⇒ Object
Performs check if this is valid as a container of a definition (class, define, node).
- #top_BlockExpression(o, definition) ⇒ Object
- #top_HostClassDefinition(o, definition) ⇒ Object
-
#top_LambdaExpression(o, definition) ⇒ Object
A LambdaExpression is a BlockExpression, and this method is needed to prevent the polymorph method for BlockExpression to accept a lambda.
-
#top_NilClass(o, definition) ⇒ Object
—TOP CHECK.
- #top_Object(o, definition) ⇒ Object
-
#transform_KeyedEntry(o) ⇒ Object
Restrictions on hash key are because of the strange key comparisons/and merge rules in the AST evaluation (Even the allowed ones are handled in a strange way).
-
#validate(model) ⇒ Object
Validates the entire model by visiting each model element and calling
check. -
#varname_to_s(o) ⇒ Object
Produces string part of something named, or nil if not a QualifiedName or QualifiedReference.
Constructor Details
#initialize(diagnostics_producer) ⇒ Checker3_1
Initializes the validator with a diagnostics producer. This object must respond to :will_accept? and :accept.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 20 def initialize(diagnostics_producer) @@check_visitor ||= Puppet::Pops::Visitor.new(nil, "check", 0, 0) @@rvalue_visitor ||= Puppet::Pops::Visitor.new(nil, "rvalue", 0, 0) @@hostname_visitor ||= Puppet::Pops::Visitor.new(nil, "hostname", 1, 2) @@assignment_visitor ||= Puppet::Pops::Visitor.new(nil, "assign", 0, 1) @@query_visitor ||= Puppet::Pops::Visitor.new(nil, "query", 0, 0) @@top_visitor ||= Puppet::Pops::Visitor.new(nil, "top", 1, 1) @@relation_visitor ||= Puppet::Pops::Visitor.new(nil, "relation", 1, 1) @acceptor = diagnostics_producer end |
Instance Attribute Details
#acceptor ⇒ Object (readonly)
16 17 18 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 16 def acceptor @acceptor end |
Instance Method Details
#assign(o, *args) ⇒ Object
Checks the LHS of an assignment (is it assignable?). If args is true, assignment via index is checked.
76 77 78 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 76 def assign(o, *args) @@assignment_visitor.visit_this(self, o, *args) end |
#assign_AccessExpression(o, *args) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 98 def assign_AccessExpression(o, *args) # Are indexed assignments allowed at all ? $x[x] = '...' if acceptor.will_accept? Issues::ILLEGAL_INDEXED_ASSIGNMENT acceptor.accept(Issues::ILLEGAL_INDEXED_ASSIGNMENT, o) else # Then the left expression must be assignable-via-index assign(o.left_expr, true) end end |
#assign_Object(o, *args) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 108 def assign_Object(o, *args) # Can not assign to anything else (differentiate if this is via index or not) # i.e. 10 = 'hello' vs. 10['x'] = 'hello' (the root is reported as being in error in both cases) # acceptor.accept(args[0] ? Issues::ILLEGAL_ASSIGNMENT_VIA_INDEX : Issues::ILLEGAL_ASSIGNMENT, o) end |
#assign_VariableExpression(o, *args) ⇒ Object
—ASSIGNMENT CHECKS
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 82 def assign_VariableExpression(o, *args) varname_string = varname_to_s(o.expr) if varname_string =~ /^[0-9]+$/ acceptor.accept(Issues::ILLEGAL_NUMERIC_ASSIGNMENT, o, :varname => varname_string) end # Can not assign to something in another namespace (i.e. a '::' in the name is not legal) if acceptor.will_accept? Issues::CROSS_SCOPE_ASSIGNMENT if varname_string =~ /::/ acceptor.accept(Issues::CROSS_SCOPE_ASSIGNMENT, o, :name => varname_string) end end # TODO: Could scan for reassignment of the same variable if done earlier in the same container # Or if assigning to a parameter (more work). # TODO: Investigate if there are invalid cases for += assignment end |
#check(o) ⇒ Object
Performs regular validity check
43 44 45 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 43 def check(o) @@check_visitor.visit_this(self, o) end |
#check_AccessExpression(o) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 124 def check_AccessExpression(o) # Check multiplicity of keys case o.left_expr when Model::QualifiedName # allows many keys, but the name should really be a QualifiedReference acceptor.accept(Issues::DEPRECATED_NAME_AS_TYPE, o, :name => o.left_expr.value) when Model::QualifiedReference # ok, allows many - this is a resource reference else # i.e. for any other expression that may produce an array or hash if o.keys.size > 1 acceptor.accept(Issues::UNSUPPORTED_RANGE, o, :count => o.keys.size) end if o.keys.size < 1 acceptor.accept(Issues::MISSING_INDEX, o) end end end |
#check_AssignmentExpression(o) ⇒ Object
144 145 146 147 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 144 def check_AssignmentExpression(o) assign(o.left_expr) rvalue(o.right_expr) end |
#check_AttributeOperation(o) ⇒ Object
Checks that operation with :+> is contained in a ResourceOverride or Collector.
Parent of an AttributeOperation can be one of:
-
CollectExpression
-
ResourceOverride
-
ResourceBody (ILLEGAL this is a regular resource expression)
-
ResourceDefaults (ILLEGAL)
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 157 def check_AttributeOperation(o) if o.operator == :'+>' # Append operator use is constrained parent = o.eContainer unless parent.is_a?(Model::CollectExpression) || parent.is_a?(Model::ResourceOverrideExpression) acceptor.accept(Issues::ILLEGAL_ATTRIBUTE_APPEND, o, {:name=>o.attribute_name, :parent=>parent}) end end rvalue(o.value_expr) end |
#check_BinaryExpression(o) ⇒ Object
168 169 170 171 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 168 def check_BinaryExpression(o) rvalue(o.left_expr) rvalue(o.right_expr) end |
#check_CallNamedFunctionExpression(o) ⇒ Object
173 174 175 176 177 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 173 def check_CallNamedFunctionExpression(o) unless o.functor_expr.is_a? Model::QualifiedName acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.functor_expr, :feature => 'function name', :container => o) end end |
#check_CaseExpression(o) ⇒ Object
185 186 187 188 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 185 def check_CaseExpression(o) # There should only be one LiteralDefault case option value # TODO: Implement this check end |
#check_CollectExpression(o) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 190 def check_CollectExpression(o) unless o.type_expr.is_a? Model::QualifiedReference acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.type_expr, :feature=> 'type name', :container => o) end # If a collect expression tries to collect exported resources and storeconfigs is not on # then it will not work... This was checked in the parser previously. This is a runtime checking # thing as opposed to a language thing. if acceptor.will_accept?(Issues::RT_NO_STORECONFIGS) && o.query.is_a?(Model::ExportedQuery) acceptor.accept(Issues::RT_NO_STORECONFIGS, o) end end |
#check_Factory(o) ⇒ Object
120 121 122 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 120 def check_Factory(o) check(o.current) end |
#check_ImportExpression(o) ⇒ Object
220 221 222 223 224 225 226 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 220 def check_ImportExpression(o) o.files.each do |f| unless f.is_a? Model::LiteralString acceptor.accept(Issues::ILLEGAL_EXPRESSION, f, :feature => 'file name', :container => o) end end end |
#check_InstanceReference(o) ⇒ Object
228 229 230 231 232 233 234 235 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 228 def check_InstanceReference(o) # TODO: Original warning is : # Puppet.warning addcontext("Deprecation notice: Resource references should now be capitalized") # This model element is not used in the egrammar. # Either implement checks or deprecate the use of InstanceReference (the same is acheived by # transformation of AccessExpression when used where an Instance/Resource reference is allowed. # end |
#check_LambdaExpression(o) ⇒ Object
A Lambda is a Definition, but it may appear in other scopes that top scope (Which check_Definition asserts).
253 254 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 253 def check_LambdaExpression(o) end |
#check_MethodCallExpression(o) ⇒ Object
179 180 181 182 183 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 179 def check_MethodCallExpression(o) unless o.functor_expr.is_a? Model::QualifiedName acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.functor_expr, :feature => 'function name', :container => o) end end |
#check_NamedAccessExpression(o) ⇒ Object
Only used for function names, grammar should not be able to produce something faulty, but check anyway if model is created programatically (it will fail in transformation to AST for sure).
205 206 207 208 209 210 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 205 def check_NamedAccessExpression(o) name = o.right_expr unless name.is_a? Model::QualifiedName acceptor.accept(Issues::ILLEGAL_EXPRESSION, name, :feature=> 'function name', :container => o.eContainer) end end |
#check_NamedDefinition(o) ⇒ Object
for ‘class’ and ‘define’
213 214 215 216 217 218 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 213 def check_NamedDefinition(o) top(o.eContainer, o) if (acceptor.will_accept? Issues::NAME_WITH_HYPHEN) && o.name.include?('-') acceptor.accept(Issues::NAME_WITH_HYPHEN, o, {:name => o.name}) end end |
#check_NodeDefinition(o) ⇒ Object
256 257 258 259 260 261 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 256 def check_NodeDefinition(o) # Check that hostnames are valid hostnames (or regular expressons) hostname(o.host_matches, o) hostname(o.parent, o, 'parent') unless o.parent.nil? top(o.eContainer, o) end |
#check_Object(o) ⇒ Object
—CHECKS
117 118 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 117 def check_Object(o) end |
#check_Parameter(o) ⇒ Object
308 309 310 311 312 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 308 def check_Parameter(o) if o.name =~ /^[0-9]+$/ acceptor.accept(Issues::ILLEGAL_NUMERIC_PARAMETER, o, :name => o.name) end end |
#check_QualifiedName(o) ⇒ Object
No checking takes place - all expressions using a QualifiedName need to check. This because the rules are slightly different depending on the container (A variable allows a numeric start, but not other names). This means that (if the lexer/parser so chooses) a QualifiedName can be anything when it represents a Bare Word and evaluates to a String.
268 269 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 268 def check_QualifiedName(o) end |
#check_QualifiedReference(o) ⇒ Object
Checks that the value is a valid UpperCaseWord (a CLASSREF), and optionally if it contains a hypen. DOH: QualifiedReferences are created with LOWER CASE NAMES at parse time
273 274 275 276 277 278 279 280 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 273 def check_QualifiedReference(o) # Is this a valid qualified name? if o.value !~ Puppet::Pops::Patterns::CLASSREF acceptor.accept(Issues::ILLEGAL_CLASSREF, o, {:name=>o.value}) elsif (acceptor.will_accept? Issues::NAME_WITH_HYPHEN) && o.value.include?('-') acceptor.accept(Issues::NAME_WITH_HYPHEN, o, {:name => o.value}) end end |
#check_QueryExpression(o) ⇒ Object
282 283 284 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 282 def check_QueryExpression(o) query(o.expr) if o.expr # is optional end |
#check_RelationshipExpression(o) ⇒ Object
relationship_side: resource
| resourceref
| collection
| variable
| quotedtext
| selector
| casestatement
| hasharrayaccesses
323 324 325 326 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 323 def check_RelationshipExpression(o) relation(o.left_expr, o) relation(o.right_expr, o) end |
#check_ResourceDefaultsExpression(o) ⇒ Object
341 342 343 344 345 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 341 def check_ResourceDefaultsExpression(o) if o.form && o.form != :regular acceptor.accept(Issues::NOT_VIRTUALIZEABLE, o) end end |
#check_ResourceExpression(o) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 328 def check_ResourceExpression(o) # A resource expression must have a lower case NAME as its type e.g. 'file { ... }' unless o.type_name.is_a? Model::QualifiedName acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.type_name, :feature => 'resource type', :container => o) end # This is a runtime check - the model is valid, but will have runtime issues when evaluated # and storeconfigs is not set. if acceptor.will_accept?(Issues::RT_NO_STORECONFIGS) && o.exported acceptor.accept(Issues::RT_NO_STORECONFIGS_EXPORT, o) end end |
#check_UnaryExpression(o) ⇒ Object
360 361 362 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 360 def check_UnaryExpression(o) rvalue(o.expr) end |
#check_UnlessExpression(o) ⇒ Object
364 365 366 367 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 364 def check_UnlessExpression(o) # TODO: Unless may not have an elsif # TODO: 3.x unless may not have an else end |
#check_VariableExpression(o) ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 369 def check_VariableExpression(o) # The expression must be a qualified name if !o.expr.is_a? Model::QualifiedName acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, :feature => 'name', :container => o) else # Note, that if it later becomes illegal with hyphen in any name, this special check # can be skipped in favor of the check in QualifiedName, which is now not done if contained in # a VariableExpression name = o.expr.value if (acceptor.will_accept? Issues::VAR_WITH_HYPHEN) && name.include?('-') acceptor.accept(Issues::VAR_WITH_HYPHEN, o, {:name => name}) end end end |
#hostname(o, semantic, single_feature_name = nil) ⇒ Object
Performs check if this is a vaid hostname expression
49 50 51 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 49 def hostname(o, semantic, single_feature_name = nil) @@hostname_visitor.visit_this(self, o, semantic, single_feature_name) end |
#hostname_Array(o, semantic, single_feature_name) ⇒ Object
Transforms Array of host matching expressions into a (Ruby) array of AST::HostName
387 388 389 390 391 392 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 387 def hostname_Array(o, semantic, single_feature_name) if single_feature_name acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, {:feature=>single_feature_name, :container=>semantic}) end o.each {|x| hostname(x, semantic, false) } end |
#hostname_ConcatenatedString(o, semantic, single_feature_name) ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 408 def hostname_ConcatenatedString(o, semantic, single_feature_name) # Puppet 3.1. only accepts a concatenated string without interpolated expressions if the_expr = o.segments.index {|s| s.is_a?(Model::TextExpression) } acceptor.accept(Issues::ILLEGAL_HOSTNAME_INTERPOLATION, o.segments[the_expr].expr) elsif o.segments.size() != 1 # corner case, bad model, concatenation of several plain strings acceptor.accept(Issues::ILLEGAL_HOSTNAME_INTERPOLATION, o) else # corner case, may be ok, but lexer may have replaced with plain string, this is # here if it does not hostname_String(o.segments[0], o.segments[0], false) end end |
#hostname_LiteralDefault(o, semantic, single_feature_name) ⇒ Object
434 435 436 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 434 def hostname_LiteralDefault(o, semantic, single_feature_name) # always ok end |
#hostname_LiteralNumber(o, semantic, single_feature_name) ⇒ Object
430 431 432 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 430 def hostname_LiteralNumber(o, semantic, single_feature_name) # always ok end |
#hostname_LiteralRegularExpression(o, semantic, single_feature_name) ⇒ Object
438 439 440 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 438 def hostname_LiteralRegularExpression(o, semantic, single_feature_name) # always ok end |
#hostname_LiteralValue(o, semantic, single_feature_name) ⇒ Object
404 405 406 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 404 def hostname_LiteralValue(o, semantic, single_feature_name) hostname_String(o.value.to_s, o, single_feature_name) end |
#hostname_Object(o, semantic, single_feature_name) ⇒ Object
442 443 444 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 442 def hostname_Object(o, semantic, single_feature_name) acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, {:feature=> single_feature_name || 'hostname', :container=>semantic}) end |
#hostname_QualifiedName(o, semantic, single_feature_name) ⇒ Object
422 423 424 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 422 def hostname_QualifiedName(o, semantic, single_feature_name) hostname_String(o.value.to_s, o, single_feature_name) end |
#hostname_QualifiedReference(o, semantic, single_feature_name) ⇒ Object
426 427 428 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 426 def hostname_QualifiedReference(o, semantic, single_feature_name) hostname_String(o.value.to_s, o, single_feature_name) end |
#hostname_String(o, semantic, single_feature_name) ⇒ Object
394 395 396 397 398 399 400 401 402 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 394 def hostname_String(o, semantic, single_feature_name) # The 3.x checker only checks for illegal characters - if matching /[^-\w.]/ the name is invalid, # but this allows pathological names like "a..b......c", "----" # TODO: Investigate if more illegal hostnames should be flagged. # if o =~ Puppet::Pops::Patterns::ILLEGAL_HOSTNAME_CHARS acceptor.accept(Issues::ILLEGAL_HOSTNAME_CHARS, semantic, :hostname => o) end end |
#query(o) ⇒ Object
Performs check if this is valid as a query
54 55 56 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 54 def query(o) @@query_visitor.visit_this(self, o) end |
#query_BooleanExpression(o) ⇒ Object
Allows AND, OR, and checks if left/right are allowed in query.
460 461 462 463 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 460 def query_BooleanExpression(o) query o.left_expr query o.right_expr end |
#query_ComparisonExpression(o) ⇒ Object
Puppet AST only allows == and !=
455 456 457 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 455 def query_ComparisonExpression(o) acceptor.accept(Issues::ILLEGAL_QUERY_EXPRESSION, o) unless [:'==', :'!='].include? o.operator end |
#query_LiteralBoolean(o) ⇒ Object
477 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 477 def query_LiteralBoolean(o); end |
#query_LiteralNumber(o) ⇒ Object
473 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 473 def query_LiteralNumber(o); end |
#query_LiteralString(o) ⇒ Object
475 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 475 def query_LiteralString(o); end |
#query_Object(o) ⇒ Object
Anything not explicitly allowed is flagged as error.
449 450 451 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 449 def query_Object(o) acceptor.accept(Issues::ILLEGAL_QUERY_EXPRESSION, o) end |
#query_ParenthesizedExpression(o) ⇒ Object
465 466 467 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 465 def query_ParenthesizedExpression(o) query(o.expr) end |
#query_QualifiedName(o) ⇒ Object
471 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 471 def query_QualifiedName(o); end |
#query_VariableExpression(o) ⇒ Object
469 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 469 def query_VariableExpression(o); end |
#relation(o, container) ⇒ Object
Performs check if this is valid as a relationship side
59 60 61 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 59 def relation(o, container) @@relation_visitor.visit_this(self, o, container) end |
#relation_AccessExpression(o, rel_expr) ⇒ Object
290 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 290 def relation_AccessExpression(o, rel_expr); end |
#relation_CaseExpression(o, rel_expr) ⇒ Object
302 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 302 def relation_CaseExpression(o, rel_expr); end |
#relation_CollectExpression(o, rel_expr) ⇒ Object
292 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 292 def relation_CollectExpression(o, rel_expr); end |
#relation_ConcatenatedStringExpression(o, rel_expr) ⇒ Object
298 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 298 def relation_ConcatenatedStringExpression(o, rel_expr); end |
#relation_LiteralString(o, rel_expr) ⇒ Object
296 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 296 def relation_LiteralString(o, rel_expr); end |
#relation_Object(o, rel_expr) ⇒ Object
286 287 288 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 286 def relation_Object(o, rel_expr) acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, {:feature => o.eContainingFeature, :container => rel_expr}) end |
#relation_RelationshipExpression(o, rel_expr) ⇒ Object
306 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 306 def relation_RelationshipExpression(o, rel_expr); end |
#relation_ResourceExpression(o, rel_expr) ⇒ Object
304 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 304 def relation_ResourceExpression(o, rel_expr); end |
#relation_SelectorExpression(o, rel_expr) ⇒ Object
300 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 300 def relation_SelectorExpression(o, rel_expr); end |
#relation_VariableExpression(o, rel_expr) ⇒ Object
294 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 294 def relation_VariableExpression(o, rel_expr); end |
#rvalue(o) ⇒ Object
Performs check if this is valid as a rvalue
64 65 66 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 64 def rvalue(o) @@rvalue_visitor.visit_this(self, o) end |
#rvalue_BlockExpression(o) ⇒ Object
488 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 488 def rvalue_BlockExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_CaseExpression(o) ⇒ Object
490 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 490 def rvalue_CaseExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_CollectExpression(o) ⇒ Object
502 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 502 def rvalue_CollectExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_Definition(o) ⇒ Object
504 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 504 def rvalue_Definition(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_Expression(o) ⇒ Object
By default, all expressions are reported as being rvalues Implement specific rvalue checks for those that are not.
484 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 484 def rvalue_Expression(o); end |
#rvalue_IfExpression(o) ⇒ Object
492 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 492 def rvalue_IfExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_ImportExpression(o) ⇒ Object
486 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 486 def rvalue_ImportExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_NodeDefinition(o) ⇒ Object
506 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 506 def rvalue_NodeDefinition(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_ResourceDefaultsExpression(o) ⇒ Object
498 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 498 def rvalue_ResourceDefaultsExpression(o); acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_ResourceExpression(o) ⇒ Object
496 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 496 def rvalue_ResourceExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_ResourceOverrideExpression(o) ⇒ Object
500 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 500 def rvalue_ResourceOverrideExpression(o); acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_UnaryExpression(o) ⇒ Object
508 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 508 def rvalue_UnaryExpression(o) ; rvalue o.expr ; end |
#rvalue_UnlessExpression(o) ⇒ Object
494 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 494 def rvalue_UnlessExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#select_SelectorExpression(o) ⇒ Object
Transformation of SelectorExpression is limited to certain types of expressions. This is probably due to constraints in the old grammar rather than any real concerns.
349 350 351 352 353 354 355 356 357 358 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 349 def select_SelectorExpression(o) case o.left_expr when Model::CallNamedFunctionExpression when Model::AccessExpression when Model::VariableExpression when Model::ConcatenatedString else acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.left_expr, :feature => 'left operand', :container => o) end end |
#top(o, definition) ⇒ Object
Performs check if this is valid as a container of a definition (class, define, node)
69 70 71 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 69 def top(o, definition) @@top_visitor.visit_this(self, o, definition) end |
#top_BlockExpression(o, definition) ⇒ Object
521 522 523 524 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 521 def top_BlockExpression(o, definition) # ok, if this is a block representing the body of a class, or is top level top o.eContainer, definition end |
#top_HostClassDefinition(o, definition) ⇒ Object
526 527 528 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 526 def top_HostClassDefinition(o, definition) # ok, stop scanning parents end |
#top_LambdaExpression(o, definition) ⇒ Object
A LambdaExpression is a BlockExpression, and this method is needed to prevent the polymorph method for BlockExpression to accept a lambda. A lambda can not iteratively create classes, nodes or defines as the lambda does not have a closure.
534 535 536 537 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 534 def top_LambdaExpression(o, definition) # fail, stop scanning parents acceptor.accept(Issues::NOT_TOP_LEVEL, definition) end |
#top_NilClass(o, definition) ⇒ Object
—TOP CHECK
512 513 514 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 512 def top_NilClass(o, definition) # ok, reached the top, no more parents end |
#top_Object(o, definition) ⇒ Object
516 517 518 519 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 516 def top_Object(o, definition) # fail, reached a container that is not top level acceptor.accept(Issues::NOT_TOP_LEVEL, definition) end |
#transform_KeyedEntry(o) ⇒ Object
Restrictions on hash key are because of the strange key comparisons/and merge rules in the AST evaluation (Even the allowed ones are handled in a strange way).
240 241 242 243 244 245 246 247 248 249 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 240 def transform_KeyedEntry(o) case o.key when Model::QualifiedName when Model::LiteralString when Model::LiteralNumber when Model::ConcatenatedString else acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.key, :feature => 'hash key', :container => o.eContainer) end end |
#validate(model) ⇒ Object
Validates the entire model by visiting each model element and calling check. The result is collected (or acted on immediately) by the configured diagnostic provider/acceptor given when creating this Checker.
36 37 38 39 40 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 36 def validate(model) # tree iterate the model, and call check for each element check(model) model.eAllContents.each {|m| check(m) } end |
#varname_to_s(o) ⇒ Object
Produces string part of something named, or nil if not a QualifiedName or QualifiedReference
543 544 545 546 547 548 549 550 551 552 |
# File 'lib/puppet/pops/validation/checker3_1.rb', line 543 def varname_to_s(o) case o when Model::QualifiedName o.value when Model::QualifiedReference o.value else nil end end |