Class: BELParser::Language::Semantics::DeeplyNestedStatement
- Inherits:
-
Object
- Object
- BELParser::Language::Semantics::DeeplyNestedStatement
- Includes:
- SemanticsFunction
- Defined in:
- lib/bel_parser/language/semantics/deeply_nested_statement.rb
Overview
DeeplyNestedStatement implements a SemanticsFunction that maps a Parsers::AST::NestedStatement to SemanticsWarning if the number of nested statements exceeds NESTING_THRESHOLD.
Constant Summary collapse
- NESTING_THRESHOLD =
Represents how many nested statments must be exceeded before a SemanticsWarning results.
1
Class Method Summary collapse
Class Method Details
.count_nested_statements(node) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bel_parser/language/semantics/deeply_nested_statement.rb', line 21 def self.map(node, spec, _namespaces) 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 |