Sha256: 0da8526c2b9b68304d9e31dd09aa3c6c87dfea718132c4aa0bee46b48ed6c8eb

Contents?: true

Size: 1.31 KB

Versions: 93

Compression:

Stored size: 1.31 KB

Contents

require_relative '../ast_filter'

module BELParser
  module Expression
    # Filter will enumerate {BELParser::Parsers::AST::Node AST nodes} that make
    # up BEL expressions. It selects the relevant nodes
    # from an {BELParser::Parsers::AST::Node AST node} enumerator.
    class Filter
      # Represents BEL expression node types.
      TYPES = [
        :simple_statement,
        :observed_term,
        :nested_statement,
        :term,
        :parameter
      ]

      def initialize(ast_enum)
        @ast_filter = BELParser::ASTFilter.new(ast_enum, *TYPES)
      end

      def each(&block)
        if block_given?
          @ast_filter.each(&block)
        else
          enum_for(:each)
        end
      end
    end

    def self.filter
      BELParser::ASTFilter.new(nil, *Filter::TYPES)
    end

    def self.parameter_filter
      BELParser::ASTFilter.new(
        nil,
        BELParser::Parsers::AST::Parameter.ast_type)
    end

    def self.term_filter
      BELParser::ASTFilter.new(
        nil,
        BELParser::Parsers::AST::Term.ast_type)
    end

    def self.statement_filter
      BELParser::ASTFilter.new(
        nil,
        BELParser::Parsers::AST::SimpleStatement.ast_type,
        BELParser::Parsers::AST::ObservedTerm.ast_type,
        BELParser::Parsers::AST::NestedStatement.ast_type)
    end
  end
end

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
bel_parser-1.1.6-java lib/bel_parser/expression/filter.rb
bel_parser-1.1.6 lib/bel_parser/expression/filter.rb
bel_parser-1.1.5 lib/bel_parser/expression/filter.rb
bel_parser-1.1.4-java lib/bel_parser/expression/filter.rb
bel_parser-1.1.4 lib/bel_parser/expression/filter.rb
bel_parser-1.1.3-java lib/bel_parser/expression/filter.rb
bel_parser-1.1.3 lib/bel_parser/expression/filter.rb
bel_parser-1.1.2-java lib/bel_parser/expression/filter.rb
bel_parser-1.1.2 lib/bel_parser/expression/filter.rb
bel_parser-1.1.1-java lib/bel_parser/expression/filter.rb
bel_parser-1.1.1 lib/bel_parser/expression/filter.rb
bel_parser-1.0.8-java lib/bel_parser/expression/filter.rb
bel_parser-1.0.8 lib/bel_parser/expression/filter.rb
bel_parser-1.0.7-java lib/bel_parser/expression/filter.rb
bel_parser-1.0.7 lib/bel_parser/expression/filter.rb
bel_parser-1.0.6-java lib/bel_parser/expression/filter.rb
bel_parser-1.0.6 lib/bel_parser/expression/filter.rb
bel_parser-1.0.5-java lib/bel_parser/expression/filter.rb
bel_parser-1.0.5 lib/bel_parser/expression/filter.rb
bel_parser-1.0.4-java lib/bel_parser/expression/filter.rb