Sha256: ccdb8cfd7b17491f0c3237791d595ed98e9ecf3c759a82ffab746fc387a10bbf

Contents?: true

Size: 1.2 KB

Versions: 11

Compression:

Stored size: 1.2 KB

Contents

require 'bel_parser/parsers/ast/node'

module BELParser
  module Language
    module Syntax
      # InvalidFunction represents a syntax error with invalid function name
      # according to a BEL specification.
      class InvalidFunction
        include SyntaxFunction

        private_class_method :new

        def self.map(func_node, spec, _namespaces)
          return nil unless func_node.is_a?(BELParser::Parsers::AST::Function)

          function_name =
            if func_node.identifier
              func_node.identifier.string_literal
            else
              ''
            end
          unless spec.function(function_name.to_sym)
            InvalidFunctionSyntaxError.new(func_node, spec, function_name)
          end
        end
      end

      # InvalidFunctionSyntaxError indicates a function name was invalid.
      class InvalidFunctionSyntaxError < SyntaxError
        # Gets the invalid function literal.
        attr_reader :invalid_function

        def initialize(function, spec, invalid_function)
          super(function, spec)
          @invalid_function = invalid_function
        end

        def msg
          %(Invalid function "#{invalid_function}".)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bel_parser-1.1.6-java lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.6 lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.5 lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.4-java lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.4 lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.3-java lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.3 lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.2-java lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.2 lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.1-java lib/bel_parser/language/syntax/invalid_function.rb
bel_parser-1.1.1 lib/bel_parser/language/syntax/invalid_function.rb