Sha256: 3a22c5816d03e08ee30de3678af2628693832191e720171618821eca3ef9b5d6

Contents?: true

Size: 1.09 KB

Versions: 19

Compression:

Stored size: 1.09 KB

Contents

module Finitio
  module Syntax
    module Node

      def resolve_ruby_const(name)
        name.split('::').inject(::Kernel){|mod,const|
          mod.const_get(const)
        }
      end

      def metadata
        m = captures[:metadata].first
        m && m.value
      end

      def unique_names!(cs, kind = "constraint")
        names = {}
        cs.map(&:name).compact.each do |n|
          names.merge!(n => true) do |k,_,_|
            raise Error, "Duplicate #{kind} name `#{k}`"
          end
        end
        cs
      end

      def self.included(by)
        by.extend(ClassHelpers)
      end

      module ClassHelpers

        def capture(*names)
          names.each do |name|
            define_method(name) do
              captures[name].first
            end
          end
        end

        def capture_str(*names)
          names.each do |name|
            define_method(name) do
              x = captures[name].first
              x && x.to_s
            end
          end
        end

      end # module ClassHelpers

    end # module Node
  end # module Syntax
end # module AstNode

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
finitio-0.12.0 lib/finitio/syntax/node.rb
finitio-0.11.4 lib/finitio/syntax/node.rb
finitio-0.11.3 lib/finitio/syntax/node.rb
finitio-0.11.2 lib/finitio/syntax/node.rb
finitio-0.11.1 lib/finitio/syntax/node.rb
finitio-0.10.0 lib/finitio/syntax/node.rb
finitio-0.9.1 lib/finitio/syntax/node.rb
finitio-0.9.0 lib/finitio/syntax/node.rb
finitio-0.8.0 lib/finitio/syntax/node.rb
finitio-0.7.0 lib/finitio/syntax/node.rb
finitio-0.7.0.pre.rc4 lib/finitio/syntax/node.rb
finitio-0.7.0.pre.rc3 lib/finitio/syntax/node.rb
finitio-0.7.0.pre.rc2 lib/finitio/syntax/node.rb
finitio-0.7.0.pre.rc1 lib/finitio/syntax/node.rb
finitio-0.6.1 lib/finitio/syntax/node.rb
finitio-0.6.0 lib/finitio/syntax/node.rb
finitio-0.5.2 lib/finitio/syntax/node.rb
finitio-0.5.1 lib/finitio/syntax/node.rb
finitio-0.5.0 lib/finitio/syntax/node.rb