Sha256: e70dc6b7b04b749d3e277eb60b9dd5c7ab435e5bb94e80887534ded444095298

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

#! /usr/bin/env ruby
#
#	ActiveFacts: Interactive CQL command-line. Incomplete; only parses CQL and shows the parse trees
#
# Copyright (c) 2009 Clifford Heath. Read the LICENSE file.
#

require 'activefacts'
require 'activefacts/cql/parser'
require 'readline'

if ENV['DEBUG']
  begin
    require 'ruby-debug'
    debugger if debug :exception
  rescue LoadError
    # Ok, no debugger, tough luck.
  end
end
true # Ok, got the stack set up, continue to the fault

puts "This is a stub for the CQL interactive commandline. At the moment it only parses CQL and shows the parse trees."

parser = ActiveFacts::CQL::Parser.new
parser.root = :definition
statement = nil
while line = Readline::readline(statement ? "CQL+ " : "CQL? ", [])
  statement = statement ? statement + "\n"+line : line
  if line =~ %r{\A/}
    # meta-commands start with /
    case (words = line.split).shift
    when "/root"
      parser.root = words[0] && words[0].to_sym || :definition
      puts "ok"
    else
      puts "Unknown metacommand #{line}, did you mean /root <rule>?"
    end
    statement = nil
  elsif parser.root != :definition or
      line.gsub(/(['"])([^\1\\]|\\.)*\1/,'') =~ /;/
    # After stripping string literals the line contains a ';', it's the last line of the command:
    begin
      result = parser.parse(statement)
      if result
        begin
          p result.value
        rescue => e
          puts e.to_s+":"
	  puts e.backtrace*"\n\t" if ENV["DEBUG"] =~ /exception/
          p result  # In case the root is changed and there's no value()
        end
        #p parser.definition(result)
      else
        p parser.failure_reason
      end
    rescue => e
      puts e
      puts "\t"+e.backtrace*"\n\t"
    end
    statement = nil
  end
end
puts

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activefacts-0.8.6 bin/cql
activefacts-0.8.5 bin/cql