class BELParser::Language::Semantics::DeeplyNestedStatement
DeeplyNestedStatement
implements a {SemanticsFunction} that maps a {BELParser::Parsers::AST::NestedStatement} to {SemanticsWarning} if the number of nested statements exceeds {DeeplyNestedStatement::NESTING_THRESHOLD}.
@see DeeplyNestedStatement::NESTING_THRESHOLD
Constants
- NESTING_THRESHOLD
Represents how many nested statments must be exceeded before a {SemanticsWarning} results.
Public Class Methods
count_nested_statements(node)
click to toggle source
# File lib/bel_parser/language/semantics/deeply_nested_statement.rb, line 32 def self.count_nested_statements(node) node .traverse .select { |n| n.is_a?(BELParser::Parsers::AST::Object) } .reduce(0) do |sum, object| sum += 1 if object.statement? sum end end
map(node, spec, _namespaces, will_match_partial = false)
click to toggle source
# File lib/bel_parser/language/semantics/deeply_nested_statement.rb, line 21 def self.map(node, spec, _namespaces, will_match_partial = false) return nil unless node.is_a?(BELParser::Parsers::AST::NestedStatement) nested_number = count_nested_statements(node) DeeplyNestedStatementWarning.new( node, spec, NESTING_THRESHOLD, nested_number) if nested_number > NESTING_THRESHOLD end