Sha256: 8e05aa55dd89d61aedb3150423cbf7d297b2bf294b8de6fcf3b19833b07b54e1

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

#       Compile a CQL file into an ActiveFacts vocabulary.
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#
require 'activefacts/vocabulary'
require 'activefacts/cql/parser'
require 'activefacts/cql/compiler'

module ActiveFacts
  module Input #:nodoc:
    # Compile CQL to an ActiveFacts vocabulary.
    # Invoke as
    #   afgen --<generator> <file>.cql
    class CQL
      # Read the specified file
      def self.readfile(filename)
	if File.basename(filename, '.cql') == "-"
	  read(STDIN, "<standard input>")
	else
	  File.open(filename) {|file|
	    read(file, filename)
	  }
	end
      rescue => e
        # Augment the exception message, but preserve the backtrace
        ne = StandardError.new("In #{filename} #{e.message.strip}")
        ne.set_backtrace(e.backtrace)
        raise ne
      end

      # Read the specified input stream
      def self.read(file, filename = "stdin")
        readstring(file.read, filename)
      end 

      # Read the specified input string
      def self.readstring(str, filename = "string")
        compiler = ActiveFacts::CQL::Compiler.new(filename)
        compiler.compile(str)
      end 
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
activefacts-1.6.0 lib/activefacts/input/cql.rb
activefacts-1.5.3 lib/activefacts/input/cql.rb
activefacts-1.5.2 lib/activefacts/input/cql.rb
activefacts-1.5.1 lib/activefacts/input/cql.rb
activefacts-1.5.0 lib/activefacts/input/cql.rb
activefacts-1.3.0 lib/activefacts/input/cql.rb