Class: Puppet::Pops::Validation::Checker4_0 Private
- Defined in:
- lib/puppet/pops/validation/checker4_0.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This is however mostly valuable when validating model to model transformations, and is therefore T.B.D
Constant Summary collapse
- RESERVED_TYPE_NAMES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ 'type' => true, 'any' => true, 'unit' => true, 'scalar' => true, 'boolean' => true, 'numeric' => true, 'integer' => true, 'float' => true, 'collection' => true, 'array' => true, 'hash' => true, 'tuple' => true, 'struct' => true, 'variant' => true, 'optional' => true, 'enum' => true, 'regexp' => true, 'pattern' => true, 'runtime' => true, }
- FUTURE_RESERVED_WORDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ 'application' => true, 'produces' => true, 'consumes' => true }
- RESERVED_PARAMETERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ 'name' => true, 'title' => true, }
Instance Attribute Summary collapse
- #acceptor ⇒ Object readonly private
- #migration_checker ⇒ Object readonly private
Instance Method Summary collapse
-
#assign(o, via_index = false) ⇒ Object
private
Checks the LHS of an assignment (is it assignable?).
- #assign_AccessExpression(o, via_index) ⇒ Object private
- #assign_LiteralList(o, via_index) ⇒ Object private
- #assign_Object(o, via_index) ⇒ Object private
-
#assign_VariableExpression(o, via_index) ⇒ Object
private
—ASSIGNMENT CHECKS.
-
#check(o) ⇒ Object
private
Performs regular validity check.
- #check_AccessExpression(o) ⇒ Object private
- #check_AssignmentExpression(o) ⇒ Object private
-
#check_AttributeOperation(o) ⇒ Object
private
Checks that operation with :+> is contained in a ResourceOverride or Collector.
- #check_AttributesOperation(o) ⇒ Object private
- #check_BinaryExpression(o) ⇒ Object private
- #check_BlockExpression(o) ⇒ Object private
- #check_CallNamedFunctionExpression(o) ⇒ Object private
- #check_CapabilityMapping(o) ⇒ Object private
- #check_CaseExpression(o) ⇒ Object private
- #check_CaseOption(o) ⇒ Object private
- #check_CollectExpression(o) ⇒ Object private
- #check_EppExpression(o) ⇒ Object private
- #check_Factory(o) ⇒ Object private
- #check_FunctionDefinition(o) ⇒ Object private
- #check_HostClassDefinition(o) ⇒ Object private
- #check_IfExpression(o) ⇒ Object private
- #check_KeyedEntry(o) ⇒ Object private
- #check_LambdaExpression(o) ⇒ Object private
- #check_LiteralList(o) ⇒ Object private
- #check_MethodCallExpression(o) ⇒ Object private
-
#check_NamedAccessExpression(o) ⇒ Object
private
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
private
for ‘class’, ‘define’, and function.
- #check_NodeDefinition(o) ⇒ Object private
-
#check_Object(o) ⇒ Object
private
—CHECKS.
- #check_Parameter(o) ⇒ Object private
-
#check_QualifiedName(o) ⇒ Object
private
No checking takes place - all expressions using a QualifiedName need to check.
-
#check_QualifiedReference(o) ⇒ Object
private
Checks that the value is a valid UpperCaseWord (a CLASSREF), and optionally if it contains a hypen.
- #check_QueryExpression(o) ⇒ Object private
-
#check_RelationshipExpression(o) ⇒ Object
private
relationship_side: resource | resourceref | collection | variable | quotedtext | selector | casestatement | hasharrayaccesses.
- #check_ReservedWord(o) ⇒ Object private
- #check_ResourceBody(o) ⇒ Object private
- #check_ResourceDefaultsExpression(o) ⇒ Object private
- #check_ResourceExpression(o) ⇒ Object private
- #check_ResourceOverrideExpression(o) ⇒ Object private
- #check_ResourceTypeDefinition(o) ⇒ Object private
- #check_SelectorEntry(o) ⇒ Object private
- #check_SelectorExpression(o) ⇒ Object private
- #check_TypeAlias(o) ⇒ Object private
- #check_TypeDefinition(o) ⇒ Object private
- #check_UnaryExpression(o) ⇒ Object private
- #check_UnlessExpression(o) ⇒ Object private
-
#check_VariableExpression(o) ⇒ Object
private
Checks that variable is either strictly 0, or a non 0 starting decimal number, or a valid VAR_NAME.
-
#ends_with_idem(o) ⇒ Object
private
Returns the last expression in a block, or the expression, if that expression is idem.
-
#hostname(o, semantic) ⇒ Object
private
Performs check if this is a vaid hostname expression.
-
#hostname_Array(o, semantic) ⇒ Object
private
Transforms Array of host matching expressions into a (Ruby) array of AST::HostName.
- #hostname_ConcatenatedString(o, semantic) ⇒ Object private
- #hostname_LiteralDefault(o, semantic) ⇒ Object private
- #hostname_LiteralNumber(o, semantic) ⇒ Object private
- #hostname_LiteralRegularExpression(o, semantic) ⇒ Object private
- #hostname_LiteralValue(o, semantic) ⇒ Object private
- #hostname_Object(o, semantic) ⇒ Object private
- #hostname_QualifiedName(o, semantic) ⇒ Object private
- #hostname_QualifiedReference(o, semantic) ⇒ Object private
- #hostname_String(o, semantic) ⇒ Object private
-
#idem(o) ⇒ Boolean
private
Checks if the expression has side effect (‘idem’ is latin for ‘the same’, here meaning that the evaluation state is known to be unchanged after the expression has been evaluated).
- #idem_AccessExpression(o) ⇒ Object private
- #idem_AssignmentExpression(o) ⇒ Object private
- #idem_BinaryExpression(o) ⇒ Object private
- #idem_BlockExpression(o) ⇒ Object private
-
#idem_CaseExpression(o) ⇒ Object
private
Case expression is idem, if test, and all options are idem.
-
#idem_CaseOption(o) ⇒ Object
private
An option is idem if values and the then_expression are idem.
-
#idem_ConcatenatedString(o) ⇒ Object
private
Returns true even though there may be interpolated expressions that have side effect.
- #idem_Factory(o) ⇒ Object private
-
#idem_HeredocExpression(o) ⇒ Object
private
Heredoc is just a string, but may contain interpolated string (which may have side effects).
- #idem_IfExpression(o) ⇒ Object private
- #idem_Literal(o) ⇒ Object private
- #idem_LiteralHash(o) ⇒ Object private
- #idem_LiteralList(o) ⇒ Object private
- #idem_NilClass(o) ⇒ Object private
- #idem_Nop(o) ⇒ Object private
-
#idem_Object(o) ⇒ Object
private
–IDEM CHECK.
-
#idem_ParenthesizedExpression(o) ⇒ Object
private
Allow (no-effect parentheses) to be used around a productive expression.
- #idem_RelationshipExpression(o) ⇒ Object private
- #idem_RenderExpression(o) ⇒ Object private
- #idem_RenderStringExpression(o) ⇒ Object private
-
#idem_SelectorExpression(o) ⇒ Object
private
May technically have side effects inside the Selector, but this is bad design - treat as idem.
-
#idem_UnaryExpression(o) ⇒ Object
private
Handles UnaryMinusExpression, NotExpression, VariableExpression.
-
#initialize(diagnostics_producer) ⇒ Checker4_0
constructor
private
Initializes the validator with a diagnostics producer.
- #internal_check_capture_last(o) ⇒ Object private
- #internal_check_future_reserved_word(o, name) ⇒ Object private
- #internal_check_illegal_assignment(o) ⇒ Object private
- #internal_check_no_capture(o, container = o) ⇒ Object private
- #internal_check_no_idem_last(o) ⇒ Object private
- #internal_check_parameter_name_uniqueness(o) ⇒ Object private
- #internal_check_reserved_params(o) ⇒ Object private
- #internal_check_reserved_type_name(o, name) ⇒ Object private
- #internal_check_type_ref(o, r) ⇒ Object private
-
#query(o) ⇒ Object
private
Performs check if this is valid as a query.
-
#query_BooleanExpression(o) ⇒ Object
private
Allows AND, OR, and checks if left/right are allowed in query.
-
#query_ComparisonExpression(o) ⇒ Object
private
Puppet AST only allows == and !=.
- #query_LiteralBoolean(o) ⇒ Object private
- #query_LiteralNumber(o) ⇒ Object private
- #query_LiteralString(o) ⇒ Object private
-
#query_Object(o) ⇒ Object
private
Anything not explicitly allowed is flagged as error.
- #query_ParenthesizedExpression(o) ⇒ Object private
- #query_QualifiedName(o) ⇒ Object private
- #query_VariableExpression(o) ⇒ Object private
-
#relation(o) ⇒ Object
private
Performs check if this is valid as a relationship side.
- #relation_CollectExpression(o) ⇒ Object private
- #relation_Object(o) ⇒ Object private
- #relation_RelationshipExpression(o) ⇒ Object private
- #resource_without_title?(o) ⇒ Boolean private
-
#rvalue(o) ⇒ Object
private
Performs check if this is valid as a rvalue.
- #rvalue_CollectExpression(o) ⇒ Object private
- #rvalue_Definition(o) ⇒ Object private
-
#rvalue_Expression(o) ⇒ Object
private
By default, all expressions are reported as being rvalues Implement specific rvalue checks for those that are not.
- #rvalue_NodeDefinition(o) ⇒ Object private
- #rvalue_UnaryExpression(o) ⇒ Object private
-
#top(o, definition) ⇒ Object
private
Performs check if this is valid as a container of a definition (class, define, node).
- #top_BlockExpression(o, definition) ⇒ Object private
- #top_HostClassDefinition(o, definition) ⇒ Object private
-
#top_LambdaExpression(o, definition) ⇒ Object
private
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
private
—TOP CHECK.
- #top_Object(o, definition) ⇒ Object private
- #top_Program(o, definition) ⇒ Object private
-
#validate(model) ⇒ Object
private
Validates the entire model by visiting each model element and calling ‘check`.
-
#varname_to_s(o) ⇒ Object
private
Produces string part of something named, or nil if not a QualifiedName or QualifiedReference.
Constructor Details
#initialize(diagnostics_producer) ⇒ Checker4_0
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the validator with a diagnostics producer. This object must respond to ‘:will_accept?` and `:accept`.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 21 def initialize(diagnostics_producer) @@check_visitor ||= Visitor.new(nil, "check", 0, 0) @@rvalue_visitor ||= Visitor.new(nil, "rvalue", 0, 0) @@hostname_visitor ||= Visitor.new(nil, "hostname", 1, 2) @@assignment_visitor ||= Visitor.new(nil, "assign", 0, 1) @@query_visitor ||= Visitor.new(nil, "query", 0, 0) @@top_visitor ||= Visitor.new(nil, "top", 1, 1) @@relation_visitor ||= Visitor.new(nil, "relation", 0, 0) @@idem_visitor ||= Visitor.new(self, "idem", 0, 0) @acceptor = diagnostics_producer # Use null migration checker unless given in context @migration_checker = (Puppet.lookup(:migration_checker) { Migration::MigrationChecker.new() }) end |
Instance Attribute Details
#acceptor ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 15 def acceptor @acceptor end |
#migration_checker ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 16 def migration_checker @migration_checker end |
Instance Method Details
#assign(o, via_index = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks the LHS of an assignment (is it assignable?). If args is true, assignment via index is checked.
81 82 83 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 81 def assign(o, via_index = false) @@assignment_visitor.visit_this_1(self, o, via_index) end |
#assign_AccessExpression(o, via_index) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
122 123 124 125 126 127 128 129 130 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 122 def assign_AccessExpression(o, via_index) # 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_LiteralList(o, via_index) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
132 133 134 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 132 def assign_LiteralList(o, via_index) o.values.each {|x| assign(x) } end |
#assign_Object(o, via_index) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
136 137 138 139 140 141 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 136 def assign_Object(o, via_index) # 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(via_index ? Issues::ILLEGAL_ASSIGNMENT_VIA_INDEX : Issues::ILLEGAL_ASSIGNMENT, o) end |
#assign_VariableExpression(o, via_index) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
—ASSIGNMENT CHECKS
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 106 def assign_VariableExpression(o, via_index) varname_string = varname_to_s(o.expr) if varname_string =~ Patterns::NUMERIC_VAR_NAME 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). end |
#check(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs regular validity check
48 49 50 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 48 def check(o) @@check_visitor.visit_this_0(self, o) end |
#check_AccessExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
152 153 154 155 156 157 158 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 152 def check_AccessExpression(o) # Only min range is checked, all other checks are RT checks as they depend on the resulting type # of the LHS. if o.keys.size < 1 acceptor.accept(Issues::MISSING_INDEX, o) end end |
#check_AssignmentExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 160 def check_AssignmentExpression(o) case o.operator when :'=' assign(o.left_expr) rvalue(o.right_expr) when :'+=', :'-=' acceptor.accept(Issues::APPENDS_DELETES_NO_LONGER_SUPPORTED, o, {:operator => o.operator}) else acceptor.accept(Issues::UNSUPPORTED_OPERATOR, o, {:operator => o.operator}) end end |
#check_AttributeOperation(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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)
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 180 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_AttributesOperation(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 191 def check_AttributesOperation(o) # Append operator use is constrained parent1 = o.eContainer case parent1 when Model::AbstractResource when Model::CollectExpression when Model::CapabilityMapping acceptor.accept(Issues::UNSUPPORTED_OPERATOR_IN_CONTEXT, parent1, :operator=>'* =>') else # protect against just testing a snippet that has no parent, error message will be a bit strange # but it is not for a real program. parent2 = parent1.nil? ? o : parent1.eContainer unless parent2.is_a?(Model::AbstractResource) acceptor.accept(Issues::UNSUPPORTED_OPERATOR_IN_CONTEXT, parent2, :operator=>'* =>') end end rvalue(o.expr) end |
#check_BinaryExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
210 211 212 213 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 210 def check_BinaryExpression(o) rvalue(o.left_expr) rvalue(o.right_expr) end |
#check_BlockExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 224 def check_BlockExpression(o) if resource_without_title?(o) acceptor.accept(Issues::RESOURCE_WITHOUT_TITLE, o, :name => o.statements[0].value) else o.statements[0..-2].each do |statement| if idem(statement) acceptor.accept(Issues::IDEM_EXPRESSION_NOT_LAST, statement) break # only flag the first end end end end |
#check_CallNamedFunctionExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 237 def check_CallNamedFunctionExpression(o) case o.functor_expr when Model::QualifiedName # ok nil when Model::RenderStringExpression # helpful to point out this easy to make Epp error acceptor.accept(Issues::ILLEGAL_EPP_PARAMETERS, o) else acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.functor_expr, {:feature=>'function name', :container => o}) end end |
#check_CapabilityMapping(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 250 def check_CapabilityMapping(o) ok = case o.component when Model::QualifiedName name = o.component.value acceptor.accept(Issues::ILLEGAL_CLASSREF, o.component, {:name=>name}) unless name =~ Patterns::CLASSREF_EXT true when Model::AccessExpression keys = o.component.keys expr = o.component.left_expr if expr.is_a?(Model::QualifiedReference) && keys.size == 1 key = keys[0] key.is_a?(Model::LiteralString) || key.is_a?(Model::QualifiedName) || key.is_a?(Model::QualifiedReference) else false end else false end acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.component, :feature=>'capability mapping', :container => o) unless ok if o.capability !~ Patterns::CLASSREF_EXT acceptor.accept(Issues::ILLEGAL_CLASSREF, o, {:name=>o.capability}) end end |
#check_CaseExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
289 290 291 292 293 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 289 def check_CaseExpression(o) rvalue(o.test) # There should only be one LiteralDefault case option value # TODO: Implement this check end |
#check_CaseOption(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
295 296 297 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 295 def check_CaseOption(o) o.values.each { |v| rvalue(v) } end |
#check_CollectExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
299 300 301 302 303 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 299 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 end |
#check_EppExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
276 277 278 279 280 281 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 276 def check_EppExpression(o) if o.eContainer.is_a?(Model::LambdaExpression) internal_check_no_capture(o.eContainer, o) internal_check_parameter_name_uniqueness(o.eContainer) end end |
#check_Factory(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
148 149 150 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 148 def check_Factory(o) check(o.current) end |
#check_FunctionDefinition(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
365 366 367 368 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 365 def check_FunctionDefinition(o) check_NamedDefinition(o) internal_check_parameter_name_uniqueness(o) end |
#check_HostClassDefinition(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
370 371 372 373 374 375 376 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 370 def check_HostClassDefinition(o) check_NamedDefinition(o) internal_check_no_capture(o) internal_check_parameter_name_uniqueness(o) internal_check_reserved_params(o) internal_check_no_idem_last(o) end |
#check_IfExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
451 452 453 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 451 def check_IfExpression(o) rvalue(o.test) end |
#check_KeyedEntry(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
455 456 457 458 459 460 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 455 def check_KeyedEntry(o) rvalue(o.key) rvalue(o.value) # In case there are additional things to forbid than non-rvalues # acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.key, :feature => 'hash key', :container => o.eContainer) end |
#check_LambdaExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
462 463 464 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 462 def check_LambdaExpression(o) internal_check_capture_last(o) end |
#check_LiteralList(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
466 467 468 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 466 def check_LiteralList(o) o.values.each {|v| rvalue(v) } end |
#check_MethodCallExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
283 284 285 286 287 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 283 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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).
307 308 309 310 311 312 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 307 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
for ‘class’, ‘define’, and function
343 344 345 346 347 348 349 350 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 343 def check_NamedDefinition(o) top(o.eContainer, o) if o.name !~ Patterns::CLASSREF acceptor.accept(Issues::ILLEGAL_DEFINITION_NAME, o, {:name=>o.name}) end internal_check_reserved_type_name(o, o.name) internal_check_future_reserved_word(o, o.name) end |
#check_NodeDefinition(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 470 def check_NodeDefinition(o) # Check that hostnames are valid hostnames (or regular expressions) hostname(o.host_matches, o) top(o.eContainer, o) if violator = ends_with_idem(o.body) acceptor.accept(Issues::IDEM_NOT_ALLOWED_LAST, violator, {:container => o}) unless resource_without_title?(violator) end unless o.parent.nil? acceptor.accept(Issues::ILLEGAL_NODE_INHERITANCE, o.parent) end end |
#check_Object(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
—CHECKS
145 146 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 145 def check_Object(o) end |
#check_Parameter(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
511 512 513 514 515 516 517 518 519 520 521 522 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 511 def check_Parameter(o) if o.name =~ /^(?:0x)?[0-9]+$/ acceptor.accept(Issues::ILLEGAL_NUMERIC_PARAMETER, o, :name => o.name) end unless o.name =~ Patterns::PARAM_NAME acceptor.accept(Issues::ILLEGAL_PARAM_NAME, o, :name => o.name) end return unless o.value internal_check_illegal_assignment(o.value) end |
#check_QualifiedName(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
487 488 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 487 def check_QualifiedName(o) end |
#check_QualifiedReference(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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
492 493 494 495 496 497 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 492 def check_QualifiedReference(o) # Is this a valid qualified name? if o.value !~ Patterns::CLASSREF acceptor.accept(Issues::ILLEGAL_CLASSREF, o, {:name=>o.value}) end end |
#check_QueryExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
499 500 501 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 499 def check_QueryExpression(o) query(o.expr) if o.expr # is optional end |
#check_RelationshipExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
relationship_side: resource
| resourceref
| collection
| variable
| quotedtext
| selector
| casestatement
| hasharrayaccesses
543 544 545 546 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 543 def check_RelationshipExpression(o) relation(o.left_expr) relation(o.right_expr) end |
#check_ReservedWord(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
580 581 582 583 584 585 586 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 580 def check_ReservedWord(o) if o.future acceptor.accept(Issues::FUTURE_RESERVED_WORD, o, :word => o.word) else acceptor.accept(Issues::RESERVED_WORD, o, :word => o.word) end end |
#check_ResourceBody(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 555 def check_ResourceBody(o) seenUnfolding = false o.operations.each do |ao| if ao.is_a?(Model::AttributesOperation) if seenUnfolding acceptor.accept(Issues::MULTIPLE_ATTRIBUTES_UNFOLD, ao) else seenUnfolding = true end end end end |
#check_ResourceDefaultsExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
568 569 570 571 572 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 568 def check_ResourceDefaultsExpression(o) if o.form && o.form != :regular acceptor.accept(Issues::NOT_VIRTUALIZEABLE, o) end end |
#check_ResourceExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
548 549 550 551 552 553 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 548 def check_ResourceExpression(o) # The expression for type name cannot be statically checked - this is instead done at runtime # to enable better error message of the result of the expression rather than the static instruction. # (This can be revised as there are static constructs that are illegal, but require updating many # tests that expect the detailed reporting). end |
#check_ResourceOverrideExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
574 575 576 577 578 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 574 def check_ResourceOverrideExpression(o) if o.form && o.form != :regular acceptor.accept(Issues::NOT_VIRTUALIZEABLE, o) end end |
#check_ResourceTypeDefinition(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
378 379 380 381 382 383 384 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 378 def check_ResourceTypeDefinition(o) check_NamedDefinition(o) internal_check_no_capture(o) internal_check_parameter_name_uniqueness(o) internal_check_reserved_params(o) internal_check_no_idem_last(o) end |
#check_SelectorEntry(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
592 593 594 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 592 def check_SelectorEntry(o) rvalue(o.matching_expr) end |
#check_SelectorExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
588 589 590 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 588 def check_SelectorExpression(o) rvalue(o.left_expr) end |
#check_TypeAlias(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
352 353 354 355 356 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 352 def check_TypeAlias(o) top(o.eContainer, o) internal_check_reserved_type_name(o, o.name) internal_check_type_ref(o, o.type_expr) end |
#check_TypeDefinition(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
358 359 360 361 362 363 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 358 def check_TypeDefinition(o) top(o.eContainer, o) internal_check_reserved_type_name(o, o.name) # TODO: Check TypeDefinition body. For now, just error out acceptor.accept(Issues::UNSUPPORTED_EXPRESSION, o) end |
#check_UnaryExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
596 597 598 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 596 def check_UnaryExpression(o) rvalue(o.expr) end |
#check_UnlessExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
600 601 602 603 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 600 def check_UnlessExpression(o) rvalue(o.test) # TODO: Unless may not have an else part that is an IfExpression (grammar denies this though) end |
#check_VariableExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks that variable is either strictly 0, or a non 0 starting decimal number, or a valid VAR_NAME
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 606 def check_VariableExpression(o) # The expression must be a qualified name or an integer name_expr = o.expr return if name_expr.is_a?(Model::LiteralInteger) if !name_expr.is_a?(Model::QualifiedName) acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, :feature => 'name', :container => o) else # name must be either a decimal string value, or a valid NAME name = o.expr.value if name[0,1] =~ /[0-9]/ unless name =~ Patterns::NUMERIC_VAR_NAME acceptor.accept(Issues::ILLEGAL_NUMERIC_VAR_NAME, o, :name => name) end else unless name =~ Patterns::VAR_NAME acceptor.accept(Issues::ILLEGAL_VAR_NAME, o, :name => name) end end end end |
#ends_with_idem(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the last expression in a block, or the expression, if that expression is idem
95 96 97 98 99 100 101 102 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 95 def ends_with_idem(o) if o.is_a?(Model::BlockExpression) last = o.statements[-1] idem(last) ? last : nil else idem(o) ? o : nil end end |
#hostname(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs check if this is a vaid hostname expression
54 55 56 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 54 def hostname(o, semantic) @@hostname_visitor.visit_this_1(self, o, semantic) end |
#hostname_Array(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Transforms Array of host matching expressions into a (Ruby) array of AST::HostName
630 631 632 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 630 def hostname_Array(o, semantic) o.each {|x| hostname(x, semantic) } end |
#hostname_ConcatenatedString(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 648 def hostname_ConcatenatedString(o, semantic) # 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]) end end |
#hostname_LiteralDefault(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
674 675 676 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 674 def hostname_LiteralDefault(o, semantic) # always ok end |
#hostname_LiteralNumber(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
670 671 672 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 670 def hostname_LiteralNumber(o, semantic) # always ok end |
#hostname_LiteralRegularExpression(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
678 679 680 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 678 def hostname_LiteralRegularExpression(o, semantic) # always ok end |
#hostname_LiteralValue(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
644 645 646 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 644 def hostname_LiteralValue(o, semantic) hostname_String(o.value.to_s, o) end |
#hostname_Object(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
682 683 684 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 682 def hostname_Object(o, semantic) acceptor.accept(Issues::ILLEGAL_EXPRESSION, o, {:feature => 'hostname', :container => semantic}) end |
#hostname_QualifiedName(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
662 663 664 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 662 def hostname_QualifiedName(o, semantic) hostname_String(o.value.to_s, o) end |
#hostname_QualifiedReference(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
666 667 668 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 666 def hostname_QualifiedReference(o, semantic) hostname_String(o.value.to_s, o) end |
#hostname_String(o, semantic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
634 635 636 637 638 639 640 641 642 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 634 def hostname_String(o, semantic) # 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 =~ Patterns::ILLEGAL_HOSTNAME_CHARS acceptor.accept(Issues::ILLEGAL_HOSTNAME_CHARS, semantic, :hostname => o) end end |
#idem(o) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if the expression has side effect (‘idem’ is latin for ‘the same’, here meaning that the evaluation state is known to be unchanged after the expression has been evaluated). The result is not 100% authoritative for negative answers since analysis of function behavior is not possible.
90 91 92 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 90 def idem(o) @@idem_visitor.visit_this_0(self, o) end |
#idem_AccessExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
803 804 805 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 803 def idem_AccessExpression(o) true end |
#idem_AssignmentExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
816 817 818 819 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 816 def idem_AssignmentExpression(o) # Always side effect false end |
#idem_BinaryExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
807 808 809 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 807 def idem_BinaryExpression(o) true end |
#idem_BlockExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
839 840 841 842 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 839 def idem_BlockExpression(o) # productive if there is at least one productive expression ! o.statements.any? {|expr| !idem(expr) } end |
#idem_CaseExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Case expression is idem, if test, and all options are idem
867 868 869 870 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 867 def idem_CaseExpression(o) return false if !idem(o.test) ! o..any? {|opt| !idem(opt) } end |
#idem_CaseOption(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
An option is idem if values and the then_expression are idem
873 874 875 876 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 873 def idem_CaseOption(o) return false if o.values.any? { |value| !idem(value) } idem(o.then_expr) end |
#idem_ConcatenatedString(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true even though there may be interpolated expressions that have side effect. Report as idem anyway, as it is very bad design to evaluate an interpolated string for its side effect only.
847 848 849 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 847 def idem_ConcatenatedString(o) true end |
#idem_Factory(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
799 800 801 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 799 def idem_Factory(o) idem(o.current) end |
#idem_HeredocExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Heredoc is just a string, but may contain interpolated string (which may have side effects). This is still bad design and should be reported as idem.
853 854 855 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 853 def idem_HeredocExpression(o) true end |
#idem_IfExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
862 863 864 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 862 def idem_IfExpression(o) [o.test, o.then_expr, o.else_expr].all? {|e| idem(e) } end |
#idem_Literal(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
787 788 789 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 787 def idem_Literal(o) true end |
#idem_LiteralHash(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
795 796 797 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 795 def idem_LiteralHash(o) true end |
#idem_LiteralList(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
791 792 793 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 791 def idem_LiteralList(o) true end |
#idem_NilClass(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
783 784 785 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 783 def idem_NilClass(o) true end |
#idem_Nop(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
779 780 781 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 779 def idem_Nop(o) true end |
#idem_Object(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
–IDEM CHECK
775 776 777 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 775 def idem_Object(o) false end |
#idem_ParenthesizedExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allow (no-effect parentheses) to be used around a productive expression
827 828 829 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 827 def idem_ParenthesizedExpression(o) idem(o.expr) end |
#idem_RelationshipExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
811 812 813 814 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 811 def idem_RelationshipExpression(o) # Always side effect false end |
#idem_RenderExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
831 832 833 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 831 def idem_RenderExpression(o) false end |
#idem_RenderStringExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
835 836 837 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 835 def idem_RenderStringExpression(o) false end |
#idem_SelectorExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
May technically have side effects inside the Selector, but this is bad design - treat as idem
858 859 860 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 858 def idem_SelectorExpression(o) true end |
#idem_UnaryExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handles UnaryMinusExpression, NotExpression, VariableExpression
822 823 824 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 822 def idem_UnaryExpression(o) true end |
#internal_check_capture_last(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
401 402 403 404 405 406 407 408 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 401 def internal_check_capture_last(o) accepted_index = o.parameters.size() -1 o.parameters.each_with_index do |p, index| if p.captures_rest && index != accepted_index acceptor.accept(Issues::CAPTURES_REST_NOT_LAST, p, {:param_name => p.name}) end end end |
#internal_check_future_reserved_word(o, name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
424 425 426 427 428 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 424 def internal_check_future_reserved_word(o, name) if FUTURE_RESERVED_WORDS[name] acceptor.accept(Issues::FUTURE_RESERVED_WORD, o, {:word => name}) end end |
#internal_check_illegal_assignment(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
524 525 526 527 528 529 530 531 532 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 524 def internal_check_illegal_assignment(o) if o.is_a?(Model::AssignmentExpression) acceptor.accept(Issues::ILLEGAL_ASSIGNMENT_CONTEXT, o) else # recursively check all contents unless it's a lambda expression. A lambda may contain # local assignments o.eContents.each {|model| internal_check_illegal_assignment(model) } unless o.is_a?(Model::LambdaExpression) end end |
#internal_check_no_capture(o, container = o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
410 411 412 413 414 415 416 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 410 def internal_check_no_capture(o, container = o) o.parameters.each do |p| if p.captures_rest acceptor.accept(Issues::CAPTURES_REST_NOT_SUPPORTED, p, {:container => container, :param_name => p.name}) end end end |
#internal_check_no_idem_last(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
395 396 397 398 399 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 395 def internal_check_no_idem_last(o) if violator = ends_with_idem(o.body) acceptor.accept(Issues::IDEM_NOT_ALLOWED_LAST, violator, {:container => o}) unless resource_without_title?(violator) end end |
#internal_check_parameter_name_uniqueness(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
444 445 446 447 448 449 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 444 def internal_check_parameter_name_uniqueness(o) unique = Set.new o.parameters.each do |p| acceptor.accept(Issues::DUPLICATE_PARAMETER, p, {:param_name => p.name}) unless unique.add?(p.name) end end |
#internal_check_reserved_params(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
436 437 438 439 440 441 442 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 436 def internal_check_reserved_params(o) o.parameters.each do |p| if RESERVED_PARAMETERS[p.name] acceptor.accept(Issues::RESERVED_PARAMETER, p, {:container => o, :param_name => p.name}) end end end |
#internal_check_reserved_type_name(o, name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
418 419 420 421 422 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 418 def internal_check_reserved_type_name(o, name) if RESERVED_TYPE_NAMES[name] acceptor.accept(Issues::RESERVED_TYPE_NAME, o, {:name => name}) end end |
#internal_check_type_ref(o, r) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
386 387 388 389 390 391 392 393 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 386 def internal_check_type_ref(o, r) n = r.is_a?(Model::AccessExpression) ? r.left_expr : r if n.is_a? Model::QualifiedReference internal_check_future_reserved_word(r, n.value) else acceptor.accept(Issues::ILLEGAL_EXPRESSION, r, :feature => 'a type reference', :container => o) end end |
#query(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs check if this is valid as a query
59 60 61 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 59 def query(o) @@query_visitor.visit_this_0(self, o) end |
#query_BooleanExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Allows AND, OR, and checks if left/right are allowed in query.
700 701 702 703 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 700 def query_BooleanExpression(o) query o.left_expr query o.right_expr end |
#query_ComparisonExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Puppet AST only allows == and !=
695 696 697 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 695 def query_ComparisonExpression(o) acceptor.accept(Issues::ILLEGAL_QUERY_EXPRESSION, o) unless [:'==', :'!='].include? o.operator end |
#query_LiteralBoolean(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
717 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 717 def query_LiteralBoolean(o); end |
#query_LiteralNumber(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
713 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 713 def query_LiteralNumber(o); end |
#query_LiteralString(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
715 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 715 def query_LiteralString(o); end |
#query_Object(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Anything not explicitly allowed is flagged as error.
689 690 691 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 689 def query_Object(o) acceptor.accept(Issues::ILLEGAL_QUERY_EXPRESSION, o) end |
#query_ParenthesizedExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
705 706 707 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 705 def query_ParenthesizedExpression(o) query(o.expr) end |
#query_QualifiedName(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
711 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 711 def query_QualifiedName(o); end |
#query_VariableExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
709 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 709 def query_VariableExpression(o); end |
#relation(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs check if this is valid as a relationship side
64 65 66 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 64 def relation(o) @@relation_visitor.visit_this_0(self, o) end |
#relation_CollectExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
507 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 507 def relation_CollectExpression(o); end |
#relation_Object(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
503 504 505 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 503 def relation_Object(o) rvalue(o) end |
#relation_RelationshipExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
509 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 509 def relation_RelationshipExpression(o); end |
#resource_without_title?(o) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
215 216 217 218 219 220 221 222 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 215 def resource_without_title?(o) if o.instance_of?(Model::BlockExpression) statements = o.statements statements.length == 2 && statements[0].instance_of?(Model::QualifiedName) && statements[1].instance_of?(Model::LiteralHash) else false end end |
#rvalue(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs check if this is valid as a rvalue
69 70 71 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 69 def rvalue(o) @@rvalue_visitor.visit_this_0(self, o) end |
#rvalue_CollectExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
726 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 726 def rvalue_CollectExpression(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_Definition(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
728 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 728 def rvalue_Definition(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_Expression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
By default, all expressions are reported as being rvalues Implement specific rvalue checks for those that are not.
724 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 724 def rvalue_Expression(o); end |
#rvalue_NodeDefinition(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
730 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 730 def rvalue_NodeDefinition(o) ; acceptor.accept(Issues::NOT_RVALUE, o) ; end |
#rvalue_UnaryExpression(o) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
732 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 732 def rvalue_UnaryExpression(o) ; rvalue o.expr ; end |
#top(o, definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Performs check if this is valid as a container of a definition (class, define, node)
74 75 76 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 74 def top(o, definition) @@top_visitor.visit_this_1(self, o, definition) end |
#top_BlockExpression(o, definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 745 def top_BlockExpression(o, definition) if !o.eContainer.is_a?(Model::Program) && (definition.is_a?(Model::FunctionDefinition) || definition.is_a?(Model::TypeAlias) || definition.is_a?(Model::TypeDefinition)) # not ok. These can never be nested in a block acceptor.accept(Issues::NOT_ABSOLUTE_TOP_LEVEL, definition) else # ok, if this is a block representing the body of a class, or is top level top o.eContainer, definition end end |
#top_HostClassDefinition(o, definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
757 758 759 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 757 def top_HostClassDefinition(o, definition) # ok, stop scanning parents end |
#top_LambdaExpression(o, definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
769 770 771 772 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 769 def top_LambdaExpression(o, definition) # fail, stop scanning parents acceptor.accept(Issues::NOT_TOP_LEVEL, definition) end |
#top_NilClass(o, definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
—TOP CHECK
736 737 738 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 736 def top_NilClass(o, definition) # ok, reached the top, no more parents end |
#top_Object(o, definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
740 741 742 743 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 740 def top_Object(o, definition) # fail, reached a container that is not top level acceptor.accept(Issues::NOT_TOP_LEVEL, definition) end |
#top_Program(o, definition) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
761 762 763 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 761 def top_Program(o, definition) # ok end |
#validate(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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.
41 42 43 44 45 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 41 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Produces string part of something named, or nil if not a QualifiedName or QualifiedReference
882 883 884 885 886 887 888 889 890 891 |
# File 'lib/puppet/pops/validation/checker4_0.rb', line 882 def varname_to_s(o) case o when Model::QualifiedName o.value when Model::QualifiedReference o.value else nil end end |