kalc 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78824d628e330b0cea023998c7d855eb7ea61059
4
+ data.tar.gz: 12eceba2e9e1495b692b725902f859373fc6fd10
5
+ SHA512:
6
+ metadata.gz: 40aead2c8de8ea0094ff49bcc49fdd6655b44de4c12d4f5564685821b4e06061d4480947c1b0937a5f62c6304ccae47d7decd7d4ff1c3f632cb4c2af63b9ba93
7
+ data.tar.gz: 2c61afc8a347df7dde81435165339ac0e56d221aa79fb2fd755a915b3d9c55582899248361b9ec9549e87b301bb2547053c1b37842d017112b31ed46f5bdbf65
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kalc (0.9.0)
4
+ kalc (0.9.1)
5
5
  parslet (~> 1.5)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
10
  blankslate (2.1.2.4)
11
- diff-lcs (1.2.4)
11
+ diff-lcs (1.2.5)
12
12
  parslet (1.5.0)
13
13
  blankslate (~> 2.0)
14
- rake (10.1.0)
14
+ rake (10.1.1)
15
15
  rspec (2.14.1)
16
16
  rspec-core (~> 2.14.0)
17
17
  rspec-expectations (~> 2.14.0)
18
18
  rspec-mocks (~> 2.14.0)
19
- rspec-core (2.14.5)
20
- rspec-expectations (2.14.2)
19
+ rspec-core (2.14.7)
20
+ rspec-expectations (2.14.4)
21
21
  diff-lcs (>= 1.1.3, < 2.0)
22
- rspec-mocks (2.14.3)
22
+ rspec-mocks (2.14.4)
23
23
 
24
24
  PLATFORMS
25
25
  java
@@ -11,7 +11,6 @@ require 'kalc/repl'
11
11
 
12
12
  module Kalc
13
13
  class Runner
14
-
15
14
  attr_accessor :grammar
16
15
  attr_accessor :transform
17
16
  attr_accessor :interpreter
@@ -39,6 +38,7 @@ module Kalc
39
38
  end
40
39
 
41
40
  private
41
+
42
42
  def load_environment
43
43
  @log.debug 'Loading grammar' if @debug
44
44
  @grammar = Kalc::Grammar.new
@@ -51,4 +51,3 @@ module Kalc
51
51
  end
52
52
  end
53
53
  end
54
-
@@ -1,6 +1,5 @@
1
1
  module Kalc
2
2
  module Ast
3
-
4
3
  class Commands
5
4
  attr_reader :commands
6
5
 
@@ -129,7 +128,6 @@ module Kalc
129
128
  a.eval(context)
130
129
  }
131
130
  end
132
-
133
131
  end
134
132
 
135
133
  class Arithmetic
@@ -145,40 +143,40 @@ module Kalc
145
143
 
146
144
  def eval(context)
147
145
  case @operator.to_s.strip
148
- when '&&'
149
- @left && @right
150
- when 'and'
151
- @left && @right
152
- when '||'
153
- @left || @right
154
- when 'or'
155
- @left || @right
156
- when '<='
157
- @left <= @right
158
- when '>='
159
- @left >= @right
160
- when '='
161
- @left == @right
162
- when '=='
163
- @left == @right
164
- when '!='
165
- @left != @right
166
- when '-'
167
- @left - @right
168
- when '+'
169
- @left + @right
170
- when '^'
171
- @left ** @right
172
- when '*'
173
- @left * @right
174
- when '/'
175
- @left / @right
176
- when '%'
177
- @left % @right
178
- when '<'
179
- @left < @right
180
- when '>'
181
- @left > @right
146
+ when '&&'
147
+ @left && @right
148
+ when 'and'
149
+ @left && @right
150
+ when '||'
151
+ @left || @right
152
+ when 'or'
153
+ @left || @right
154
+ when '<='
155
+ @left <= @right
156
+ when '>='
157
+ @left >= @right
158
+ when '='
159
+ @left == @right
160
+ when '=='
161
+ @left == @right
162
+ when '!='
163
+ @left != @right
164
+ when '-'
165
+ @left - @right
166
+ when '+'
167
+ @left + @right
168
+ when '^'
169
+ @left**@right
170
+ when '*'
171
+ @left * @right
172
+ when '/'
173
+ @left / @right
174
+ when '%'
175
+ @left % @right
176
+ when '<'
177
+ @left < @right
178
+ when '>'
179
+ @left > @right
182
180
  end
183
181
  end
184
182
  end
@@ -1,6 +1,5 @@
1
1
  module Kalc
2
2
  class Environment
3
-
4
3
  attr_reader :functions
5
4
  attr_reader :variables
6
5
 
@@ -12,7 +11,7 @@ module Kalc
12
11
  end
13
12
 
14
13
  def add_function(name, value)
15
- @functions.update({name.to_s.strip => value})
14
+ @functions.update({ name.to_s.strip => value })
16
15
  end
17
16
 
18
17
  def get_function(name)
@@ -26,7 +25,7 @@ module Kalc
26
25
  end
27
26
 
28
27
  def add_variable(name, value)
29
- @variables.update({name.to_s.strip => value})
28
+ @variables.update({ name.to_s.strip => value })
30
29
  value
31
30
  end
32
31
 
@@ -1,11 +1,10 @@
1
1
  # Started with https://github.com/postmodern/cparser code
2
2
  # which is based on http://www.lysator.liu.se/c/ANSI-C-grammar-y.html
3
3
  # and worked from there
4
- #
4
+ #
5
5
  # The second link really helped when it came to functions
6
6
 
7
7
  class Kalc::Grammar < Parslet::Parser
8
-
9
8
  rule(:new_line) { match('[\n\r]').repeat(1) }
10
9
 
11
10
  rule(:space) { match('[ \t\v\n\f]') }
@@ -36,7 +35,7 @@ class Kalc::Grammar < Parslet::Parser
36
35
  :colon => ':',
37
36
  :question_mark => '?'
38
37
 
39
- def self.operators(operators={})
38
+ def self.operators(operators = {})
40
39
  trailing_chars = Hash.new { |hash, symbol| hash[symbol] = [] }
41
40
 
42
41
  operators.each_value do |symbol|
@@ -290,4 +289,3 @@ class Kalc::Grammar < Parslet::Parser
290
289
 
291
290
  root :lines
292
291
  end
293
-
@@ -4,7 +4,6 @@ require 'pp'
4
4
 
5
5
  module Kalc
6
6
  class Interpreter
7
-
8
7
  attr_accessor :env
9
8
 
10
9
  def initialize
@@ -111,10 +110,11 @@ module Kalc
111
110
  # Strings
112
111
  string_funs =
113
112
  %w(chomp chop chr clear count
114
- downcase
115
- hex
116
- inspect intern
117
- to_sym length size lstrip succ next oct ord reverse rstrip strip swapcase to_c to_f to_i to_r upcase)
113
+ downcase
114
+ hex
115
+ inspect intern
116
+ to_sym length size lstrip succ next oct ord reverse rstrip strip
117
+ swapcase to_c to_f to_i to_r upcase)
118
118
 
119
119
  string_funs.each do |str_fun|
120
120
  env.add_function(str_fun.upcase.to_sym, lambda { |cxt, val|
@@ -5,13 +5,11 @@ require 'parslet/convenience'
5
5
 
6
6
  module Kalc
7
7
  class Repl
8
-
9
8
  def load_env
10
9
  @kalc = Kalc::Runner.new(true)
11
10
  end
12
11
 
13
12
  def run
14
-
15
13
  puts heading
16
14
 
17
15
  # Load Kalc with debug
@@ -30,18 +28,18 @@ module Kalc
30
28
  while input = Readline.readline("kalc-#{Kalc::VERSION} > ", true)
31
29
  begin
32
30
  case
33
- when (input == 'quit' || input == 'exit')
34
- break
35
- when input == 'functions'
36
- puts @kalc.interpreter.env.functions.map { |f| f.first }.join(', ')
37
- when input == 'variables'
38
- puts @kalc.interpreter.env.variables.map { |v| "#{v[0]} = #{v[1]}" }.join("\n\r")
39
- when input == 'reload'
40
- load_env
41
- when input == 'ast'
42
- pp @kalc.ast
43
- when input != ''
44
- puts @kalc.run(input)
31
+ when (input == 'quit' || input == 'exit')
32
+ break
33
+ when input == 'functions'
34
+ puts @kalc.interpreter.env.functions.map { |f| f.first }.join(', ')
35
+ when input == 'variables'
36
+ puts @kalc.interpreter.env.variables.map { |v| "#{v[0]} = #{v[1]}" }.join("\n\r")
37
+ when input == 'reload'
38
+ load_env
39
+ when input == 'ast'
40
+ pp @kalc.ast
41
+ when input != ''
42
+ puts @kalc.run(input)
45
43
  end
46
44
  rescue Parslet::ParseFailed => e
47
45
  puts e, g.root.error_tree
@@ -58,12 +56,11 @@ module Kalc
58
56
 
59
57
  def heading
60
58
  %q{
61
- This is Kalc, a small line-based language.
62
- More information about Kalc can be found at https://github.com/mrcsparker/kalc.
59
+ This is Kalc, a small line-based language.
60
+ More information about Kalc can be found at https://github.com/mrcsparker/kalc.
63
61
 
64
- Kalc is free software, provided as is, with no warranty.
62
+ Kalc is free software, provided as is, with no warranty.
65
63
  }
66
64
  end
67
-
68
65
  end
69
66
  end
@@ -1,3 +1,3 @@
1
1
  module Kalc
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
metadata CHANGED
@@ -1,64 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kalc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
5
- prerelease:
4
+ version: 0.9.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Parker
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-21 00:00:00.000000000 Z
11
+ date: 2014-01-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- version_requirements: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - '>='
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- none: false
22
15
  requirement: !ruby/object:Gem::Requirement
23
16
  requirements:
24
- - - '>='
17
+ - - ">="
25
18
  - !ruby/object:Gem::Version
26
19
  version: '0'
27
- none: false
28
- prerelease: false
29
20
  type: :development
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
21
+ prerelease: false
32
22
  version_requirements: !ruby/object:Gem::Requirement
33
23
  requirements:
34
- - - '>='
24
+ - - ">="
35
25
  - !ruby/object:Gem::Version
36
26
  version: '0'
37
- none: false
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
38
29
  requirement: !ruby/object:Gem::Requirement
39
30
  requirements:
40
- - - '>='
31
+ - - ">="
41
32
  - !ruby/object:Gem::Version
42
33
  version: '0'
43
- none: false
44
- prerelease: false
45
34
  type: :development
46
- - !ruby/object:Gem::Dependency
47
- name: parslet
35
+ prerelease: false
48
36
  version_requirements: !ruby/object:Gem::Requirement
49
37
  requirements:
50
- - - ~>
38
+ - - ">="
51
39
  - !ruby/object:Gem::Version
52
- version: '1.5'
53
- none: false
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parslet
54
43
  requirement: !ruby/object:Gem::Requirement
55
44
  requirements:
56
- - - ~>
45
+ - - "~>"
57
46
  - !ruby/object:Gem::Version
58
47
  version: '1.5'
59
- none: false
60
- prerelease: false
61
48
  type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
62
55
  description: Calculation language slightly based on Excel's formula language.
63
56
  email:
64
57
  - mrcsparker@gmail.com
@@ -93,33 +86,26 @@ files:
93
86
  - spec/stdlib_spec.rb
94
87
  homepage: https://github.com/mrcsparker/kalc
95
88
  licenses: []
96
- post_install_message:
89
+ metadata: {}
90
+ post_install_message:
97
91
  rdoc_options: []
98
92
  require_paths:
99
93
  - lib
100
94
  required_ruby_version: !ruby/object:Gem::Requirement
101
95
  requirements:
102
- - - '>='
96
+ - - ">="
103
97
  - !ruby/object:Gem::Version
104
- segments:
105
- - 0
106
98
  version: '0'
107
- hash: 2
108
- none: false
109
99
  required_rubygems_version: !ruby/object:Gem::Requirement
110
100
  requirements:
111
- - - '>='
101
+ - - ">="
112
102
  - !ruby/object:Gem::Version
113
- segments:
114
- - 0
115
103
  version: '0'
116
- hash: 2
117
- none: false
118
104
  requirements: []
119
105
  rubyforge_project: kalc
120
- rubygems_version: 1.8.24
121
- signing_key:
122
- specification_version: 3
106
+ rubygems_version: 2.2.0
107
+ signing_key:
108
+ specification_version: 4
123
109
  summary: Small calculation language.
124
110
  test_files:
125
111
  - spec/grammar_spec.rb