theta 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -21,4 +21,19 @@ After installation, simply type theta to get to the interactive interpreter prom
21
21
 
22
22
  To exit, simply type 'exit' at the prompt.
23
23
 
24
- It's a little low on features currently, but I'll be adding more eventually!
24
+ Or, you can use the -f command line parameter to evaluate a file.
25
+
26
+ % theta -f test.scm
27
+
28
+ Alternately, you can use the -c parameter and pass in code directly.
29
+
30
+ % theta -c "(+ 3 2)"
31
+
32
+ And finally, you can use Theta inside your own Ruby programs, if that sounds like something you'd do.
33
+
34
+ require 'rubygems'
35
+ require 'theta'
36
+
37
+ t = Theta::Interpreter.new
38
+ t.run "(define n 15)"
39
+ puts t.run "(+ 10 n)"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/bin/theta CHANGED
@@ -1,12 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
-
2
+ require 'optparse'
3
3
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "theta.rb"))
4
4
 
5
+ options = { :mode => :repl }
6
+ op = OptionParser.new do |x|
7
+ x.banner = "theta <options>"
8
+ x.separator "\nUsing no options will start the interactive interpreter."
9
+ x.on("-f <file_path>", String, "Open a given file") do |f|
10
+ options[:mode] = :file
11
+ options[:file] = f
12
+ end
13
+ x.on("-c <code>", String, "Perform the given code") do |c|
14
+ options[:mode] = :code
15
+ options[:code] = c
16
+ end
17
+ x.on("-h", "Show this message") do
18
+ puts op
19
+ exit
20
+ end
21
+ end
22
+ begin
23
+ op.parse!(ARGV)
24
+ rescue
25
+ puts "Could not parse command line arguments."
26
+ exit
27
+ end
28
+
5
29
  theta = Theta::Base.new
6
- # if a file was passed in, run it
7
- # otherwise, enter the repl
8
- if ARGV.length > 0
9
- theta.run(ARGV[1])
10
- else
30
+ case options[:mode]
31
+ when :repl
32
+ puts "Starting interactive interpreter..."
11
33
  theta.repl
34
+ when :file
35
+ puts "Running file..."
36
+ theta.load_file(options[:file])
37
+ when :code
38
+ puts "Interpreting code..."
39
+ theta.run(options[:code])
12
40
  end
@@ -1,3 +1,6 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "environment.rb"))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "parser.rb"))
3
+
1
4
  module Theta
2
5
  # interpret scheme code
3
6
  class Interpreter
data/lib/theta.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require File.expand_path(File.join(File.dirname(__FILE__), "theta", "interpreter.rb"))
2
- require File.expand_path(File.join(File.dirname(__FILE__), "theta", "environment.rb"))
3
- require File.expand_path(File.join(File.dirname(__FILE__), "theta", "parser.rb"))
4
2
 
5
3
  module Theta
6
4
  # runs the interpreter
@@ -10,30 +8,48 @@ module Theta
10
8
  @interpreter = Interpreter.new
11
9
  end
12
10
 
13
- # run a preexisting program
14
- def run(fileName)
15
- program = File.open(fileName) { |f| f.read }
11
+ # load and run the given file
12
+ def load_file(file_path)
13
+ program = File.open(file_path) { |f| f.read }
14
+ run program
15
+ end
16
+
17
+ # run given code
18
+ def run(program)
16
19
  puts @interpreter.run(program)
17
20
  end
18
21
 
19
22
  # start an interactive interpreter
20
23
  def repl
24
+ puts "For interpreter commands, type 'help'"
21
25
  while true
22
26
  print "theta> "
23
- input = ""
24
- input << gets.strip
25
- if input == "exit"
27
+ input = gets.chomp
28
+ case input
29
+ #when "clear"
30
+ # puts "Resetting environment..."
31
+ # @interpreter = Interpreter.new
32
+ when "exit", 24.chr
26
33
  puts "Exiting..."
27
34
  return
28
- end
29
- if input.empty?
30
- next
31
- end
32
- value = @interpreter.run(input)
33
- unless value.nil?
34
- puts @interpreter.make_readable(value)
35
+ when "help"
36
+ repl_help
37
+ else
38
+ begin
39
+ value = @interpreter.run(input)
40
+ rescue SyntaxError
41
+ end
42
+ unless value.nil?
43
+ puts @interpreter.make_readable(value)
44
+ end
35
45
  end
36
46
  end
37
47
  end
48
+
49
+ def repl_help
50
+ #puts "'clear' resets the environment"
51
+ puts "'exit' or Ctrl-X will exit the interpreter"
52
+ puts "'help' will display this message"
53
+ end
38
54
  end
39
55
  end
data/theta.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{theta}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris O'Neal"]
12
- s.date = %q{2011-03-29}
12
+ s.date = %q{2011-06-10}
13
13
  s.description = %q{Theta was created as a learning project based off of lis.py and flea}
14
14
  s.email = %q{ctoneal@gmail.com}
15
15
  s.executables = ["theta", "theta"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: theta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-03-29 00:00:00.000000000 -05:00
12
+ date: 2011-06-10 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: shoulda
17
- requirement: &9485220 !ruby/object:Gem::Requirement
17
+ requirement: &7339260 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *9485220
25
+ version_requirements: *7339260
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: bundler
28
- requirement: &9484644 !ruby/object:Gem::Requirement
28
+ requirement: &7338048 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *9484644
36
+ version_requirements: *7338048
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: jeweler
39
- requirement: &9483744 !ruby/object:Gem::Requirement
39
+ requirement: &7336620 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.5.2
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *9483744
47
+ version_requirements: *7336620
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rcov
50
- requirement: &9483072 !ruby/object:Gem::Requirement
50
+ requirement: &7334976 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *9483072
58
+ version_requirements: *7334976
59
59
  description: Theta was created as a learning project based off of lis.py and flea
60
60
  email: ctoneal@gmail.com
61
61
  executables:
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: -933902079
111
+ hash: 260486451
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements: