qlang 0.0.27182000 → 0.0.27182100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/README.md +17 -1
  4. data/Rakefile +16 -3
  5. data/bin/qlang +7 -1
  6. data/ext/qlang/QMatrix/q_matrix.c +0 -0
  7. data/ext/qlang/extconf.rb +3 -0
  8. data/ext/qlang/qlang.c +65 -0
  9. data/ext/qlang/qlang.h +6 -0
  10. data/{spec → legacy_rspec}/langs/Haskell/ex1_after.hs +0 -0
  11. data/{spec → legacy_rspec}/langs/Haskell/ex1_before.hs +0 -0
  12. data/{spec → legacy_rspec}/langs/Python/ex1_after.py +0 -0
  13. data/{spec → legacy_rspec}/langs/Python/ex1_before.py +0 -0
  14. data/{spec → legacy_rspec}/langs/R/ex1_after.R +0 -0
  15. data/{spec → legacy_rspec}/langs/R/ex1_before.R +0 -0
  16. data/{spec → legacy_rspec}/objects/list_spec.rb +0 -0
  17. data/{spec → legacy_rspec}/objects/matrix_spec.rb +0 -0
  18. data/{spec → legacy_rspec}/objects/vector_spec.rb +0 -0
  19. data/lib/qlang.rb +21 -18
  20. data/lib/qlang/api/func_api.rb +1 -1
  21. data/lib/qlang/api/integral_api.rb +1 -1
  22. data/lib/qlang/api/list_api.rb +1 -1
  23. data/lib/qlang/api/matrix_api.rb +1 -1
  24. data/lib/qlang/api/vector_api.rb +1 -1
  25. data/lib/qlang/iq.rb +5 -2
  26. data/lib/qlang/lexer.rb +2 -2
  27. data/lib/qlang/lexer/base.rb +31 -14
  28. data/lib/qlang/lexer/formula_lexer.rb +20 -0
  29. data/lib/qlang/lexer/main_lexer.rb +25 -0
  30. data/lib/qlang/lexer/tokens.rb +27 -15
  31. data/lib/qlang/parser.rb +29 -41
  32. data/lib/qlang/parser/formula_parser.rb +25 -25
  33. data/lib/qlang/parser/func_parser.rb +2 -2
  34. data/lib/qlang/parser/integral_parser.rb +2 -2
  35. data/lib/qlang/parser/matrix_parser.rb +3 -3
  36. data/lib/qlang/parser/vector_parser.rb +4 -4
  37. data/lib/qlang/version.rb +1 -1
  38. data/{q_lang.gemspec → qlang.gemspec} +4 -2
  39. data/test/internal/test_tokens.rb +36 -0
  40. data/test/interpreter/base.rb +17 -0
  41. data/test/interpreter/test_differential.rb +44 -0
  42. data/test/interpreter/test_function.rb +45 -0
  43. data/test/interpreter/test_general.rb +13 -0
  44. data/test/interpreter/test_integral.rb +39 -0
  45. data/test/interpreter/test_matrix.rb +71 -0
  46. data/test/interpreter/test_vector.rb +29 -0
  47. data/test/langs/test_r.rb +33 -0
  48. data/test/langs/test_ruby.rb +10 -0
  49. data/{spec/spec_helper.rb → test/minitest_helper.rb} +4 -4
  50. data/test/q_matrix/test_q_matrix.rb +13 -0
  51. data/test/test_qlang.rb +25 -0
  52. metadata +65 -43
  53. data/.rspec +0 -2
  54. data/lib/qlang/lexer/cont_lexer.rb +0 -20
  55. data/lib/qlang/lexer/func_lexer.rb +0 -13
  56. data/lib/qlang/lexer/wrap_lexer.rb +0 -25
  57. data/spec/iq_spec.rb +0 -141
  58. data/spec/lexer/regular_expressions_spec.rb +0 -45
  59. data/spec/objects/function_spec.rb +0 -33
  60. data/spec/objects/integral_spec.rb +0 -21
  61. data/spec/q_lang_spec.rb +0 -47
@@ -0,0 +1,13 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestGeneral < TestInterpreterBase
4
+ def setup
5
+
6
+ end
7
+
8
+ def test_general
9
+ assert_iq_equal('2x', '2x')
10
+ assert_iq_equal('x + x', '2x')
11
+ assert_iq_equal('x * y', 'xy')
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestIntegral < TestInterpreterBase
4
+ def setup
5
+
6
+ end
7
+
8
+ def test_general
9
+ assert_iq_equal(
10
+ 'S( log(x)dx )[0..1]',
11
+ '-oo'
12
+ )
13
+
14
+ assert_iq_equal(
15
+ 'S( sin(x)dx )[0..pi]',
16
+ '2.0'
17
+ )
18
+
19
+ assert_iq_equal(
20
+ 'S( cos(x)dx )[0..pi]',
21
+ '0.0'
22
+ )
23
+
24
+ assert_iq_equal(
25
+ 'S( cos(x)dx )[0..pi]',
26
+ '0.0'
27
+ )
28
+
29
+ assert_iq_equal(
30
+ 'S(2pi dx)[0..1]',
31
+ '6.28318531'
32
+ )
33
+
34
+ assert_iq_equal(
35
+ 'S(xx dx)[0..1]',
36
+ '0.33333333'
37
+ )
38
+ end
39
+ end
@@ -0,0 +1,71 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestMatrix < TestInterpreterBase
4
+ def setup
5
+
6
+ end
7
+
8
+ def test_integer
9
+ assert_iq_equal(
10
+ '(1 2 3; 4 5 6)',
11
+ '(1 2 3; 4 5 6)'
12
+ )
13
+
14
+ assert_iq_equal(
15
+ '(1 2 3; 4 5 6) + (1 2 3; 4 5 6)',
16
+ '(2 4 6; 8 10 12)'
17
+ )
18
+
19
+ assert_iq_equal(
20
+ '(1 2 3; 4 5 6) - (2 4 1; 8 3 9)',
21
+ '(-1 -2 2; -4 2 -3)'
22
+ )
23
+
24
+ assert_iq_equal(
25
+ '(1 2; 3 4) * (1 2; 3 4)',
26
+ '(7 10; 15 22)'
27
+ )
28
+
29
+ assert_iq_equal(
30
+ '(1 2; 3 4) ** 2',
31
+ '(7 10; 15 22)'
32
+ )
33
+
34
+ assert_iq_equal(
35
+ '(1 2; 3 4) ** 2',
36
+ '(7 10; 15 22)'
37
+ )
38
+
39
+ assert_iq_equal(
40
+ '(1 2; 3 4) * (1 2)',
41
+ '(5 11)'
42
+ )
43
+
44
+ assert_iq_equal(
45
+ '(1 2 3; 4 5 6)t',
46
+ '(1 4; 2 5; 3 6)'
47
+ )
48
+
49
+ assert_iq_equal(
50
+ '(1 2 3
51
+ 4 5 6) +
52
+ (1 2 3
53
+ 4 5 6)',
54
+ '(2 4 6; 8 10 12)'
55
+ )
56
+ end
57
+
58
+ def test_float
59
+ assert_iq_equal(
60
+ '(1.0 2.0 3
61
+ 4.2 5.3 6)t',
62
+ '(1.0 4.2; 2.0 5.3; 3 6)'
63
+ )
64
+
65
+ assert_iq_equal(
66
+ '(1.0 2.0 3
67
+ 4.2 5.3 6)t',
68
+ '(1.0 4.2; 2.0 5.3; 3 6)'
69
+ )
70
+ end
71
+ end
@@ -0,0 +1,29 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestVector < TestInterpreterBase
4
+ def setup
5
+
6
+ end
7
+
8
+ def test_integer
9
+ assert_iq_equal(
10
+ '(1 2 3)',
11
+ '(1 2 3)'
12
+ )
13
+
14
+ assert_iq_equal(
15
+ '(1 2 3) + (1 2 3)',
16
+ '(2 4 6)'
17
+ )
18
+
19
+ assert_iq_equal(
20
+ '(1 2 3 ) + ( 1 2 3 )',
21
+ '(2 4 6)'
22
+ )
23
+
24
+ assert_iq_equal(
25
+ '(1 2 3) - (1 2 3) - (1 2 3)',
26
+ '(-1 -2 -3)'
27
+ )
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestR < TestInterpreterBase
4
+ def setup
5
+
6
+ end
7
+
8
+ def assert_r_compl_eq(output, input)
9
+ assert_equal(output, Q.to_r.compile(input))
10
+ end
11
+
12
+ def test_function
13
+ assert_r_compl_eq(
14
+ "f <- function(x, y) x + y",
15
+ 'f(x, y) = x + y'
16
+ )
17
+
18
+ assert_r_compl_eq(
19
+ "g <- function(x) x ^ 2",
20
+ 'g(x) = x ^ 2'
21
+ )
22
+
23
+ assert_r_compl_eq(
24
+ "g <- function(x) x ^ (2 + 2)",
25
+ 'g(x) = x ^ (2 + 2)'
26
+ )
27
+
28
+ assert_r_compl_eq(
29
+ "h <- function(a, b, c) a ^ 2 + b ^ 2 + c ^ 2",
30
+ 'h(a, b, c) = a ^ 2 + b ^ 2 + c ^ 2'
31
+ )
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestRuby < TestInterpreterBase
4
+ def setup
5
+
6
+ end
7
+
8
+ def test_integer
9
+ end
10
+ end
@@ -1,8 +1,8 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'qlang'
3
- include Qlang
4
-
5
- require 'coveralls'
6
- Coveralls.wear!
7
3
 
4
+ require 'minitest/autorun'
5
+ require 'pp'
8
6
  require 'pry'
7
+
8
+ require 'interpreter/base'
@@ -0,0 +1,13 @@
1
+ require 'minitest_helper'
2
+ require 'qlang/qlang'
3
+
4
+ class TestQMatrix < TestInterpreterBase
5
+ def setup
6
+ end
7
+
8
+ def test_main
9
+ #assert_equal(50.0, QMatrix.new.func(10))
10
+
11
+ assert_equal(8.0, QMatrix.new.execute(0, 2, 100))
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestQlang < MiniTest::Unit::TestCase
4
+ def setup
5
+
6
+ end
7
+
8
+ def assert_to_ruby(input, output)
9
+ assert_equal(Q.to_ruby.compile(input), output)
10
+ end
11
+
12
+ def test_basis
13
+ refute_nil ::Qlang::VERSION
14
+ assert_equal(Qlang, Q)
15
+ end
16
+
17
+ def test_demo_code
18
+ assert_to_ruby('d/dx(sin(x))', 'd/dx(sin(x))')
19
+ assert_to_ruby('d/dx(log(x))', 'd/dx(log(x))')
20
+ assert_to_ruby('f(x, y) = x + y', 'f(x, y) <= x + y')
21
+ assert_equal(Matrix[[1, 2, 3], [4, 5, 6]].to_q, '(1 2 3; 4 5 6)')
22
+ assert_equal(Vector[1, 2, 3].to_q, '(1 2 3)')
23
+ end
24
+ end
25
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qlang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27182000
4
+ version: 0.0.27182100
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2014-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dydx
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.6'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.6'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,21 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
@@ -71,12 +85,12 @@ email:
71
85
  - mail@tanakakazuki.com
72
86
  executables:
73
87
  - qlang
74
- extensions: []
88
+ extensions:
89
+ - ext/qlang/extconf.rb
75
90
  extra_rdoc_files: []
76
91
  files:
77
92
  - ".coveralls.yml"
78
93
  - ".gitignore"
79
- - ".rspec"
80
94
  - ".rubocop.yml"
81
95
  - ".travis.yml"
82
96
  - Gemfile
@@ -87,6 +101,19 @@ files:
87
101
  - core/Q.hs
88
102
  - core/Q/Lexer.hs
89
103
  - core/Q/Parser.hs
104
+ - ext/qlang/QMatrix/q_matrix.c
105
+ - ext/qlang/extconf.rb
106
+ - ext/qlang/qlang.c
107
+ - ext/qlang/qlang.h
108
+ - legacy_rspec/langs/Haskell/ex1_after.hs
109
+ - legacy_rspec/langs/Haskell/ex1_before.hs
110
+ - legacy_rspec/langs/Python/ex1_after.py
111
+ - legacy_rspec/langs/Python/ex1_before.py
112
+ - legacy_rspec/langs/R/ex1_after.R
113
+ - legacy_rspec/langs/R/ex1_before.R
114
+ - legacy_rspec/objects/list_spec.rb
115
+ - legacy_rspec/objects/matrix_spec.rb
116
+ - legacy_rspec/objects/vector_spec.rb
90
117
  - lib/qlang.rb
91
118
  - lib/qlang/api.rb
92
119
  - lib/qlang/api/func_api.rb
@@ -98,10 +125,9 @@ files:
98
125
  - lib/qlang/iq.rb
99
126
  - lib/qlang/lexer.rb
100
127
  - lib/qlang/lexer/base.rb
101
- - lib/qlang/lexer/cont_lexer.rb
102
- - lib/qlang/lexer/func_lexer.rb
128
+ - lib/qlang/lexer/formula_lexer.rb
129
+ - lib/qlang/lexer/main_lexer.rb
103
130
  - lib/qlang/lexer/tokens.rb
104
- - lib/qlang/lexer/wrap_lexer.rb
105
131
  - lib/qlang/parser.rb
106
132
  - lib/qlang/parser/base.rb
107
133
  - lib/qlang/parser/formula_parser.rb
@@ -113,22 +139,20 @@ files:
113
139
  - lib/qlang/utils/langs.yml
114
140
  - lib/qlang/utils/ruby_ext.rb
115
141
  - lib/qlang/version.rb
116
- - q_lang.gemspec
117
- - spec/iq_spec.rb
118
- - spec/langs/Haskell/ex1_after.hs
119
- - spec/langs/Haskell/ex1_before.hs
120
- - spec/langs/Python/ex1_after.py
121
- - spec/langs/Python/ex1_before.py
122
- - spec/langs/R/ex1_after.R
123
- - spec/langs/R/ex1_before.R
124
- - spec/lexer/regular_expressions_spec.rb
125
- - spec/objects/function_spec.rb
126
- - spec/objects/integral_spec.rb
127
- - spec/objects/list_spec.rb
128
- - spec/objects/matrix_spec.rb
129
- - spec/objects/vector_spec.rb
130
- - spec/q_lang_spec.rb
131
- - spec/spec_helper.rb
142
+ - qlang.gemspec
143
+ - test/internal/test_tokens.rb
144
+ - test/interpreter/base.rb
145
+ - test/interpreter/test_differential.rb
146
+ - test/interpreter/test_function.rb
147
+ - test/interpreter/test_general.rb
148
+ - test/interpreter/test_integral.rb
149
+ - test/interpreter/test_matrix.rb
150
+ - test/interpreter/test_vector.rb
151
+ - test/langs/test_r.rb
152
+ - test/langs/test_ruby.rb
153
+ - test/minitest_helper.rb
154
+ - test/q_matrix/test_q_matrix.rb
155
+ - test/test_qlang.rb
132
156
  homepage: http://q-language.org/
133
157
  licenses:
134
158
  - MIT
@@ -154,18 +178,16 @@ signing_key:
154
178
  specification_version: 4
155
179
  summary: Enjoy MATH!
156
180
  test_files:
157
- - spec/iq_spec.rb
158
- - spec/langs/Haskell/ex1_after.hs
159
- - spec/langs/Haskell/ex1_before.hs
160
- - spec/langs/Python/ex1_after.py
161
- - spec/langs/Python/ex1_before.py
162
- - spec/langs/R/ex1_after.R
163
- - spec/langs/R/ex1_before.R
164
- - spec/lexer/regular_expressions_spec.rb
165
- - spec/objects/function_spec.rb
166
- - spec/objects/integral_spec.rb
167
- - spec/objects/list_spec.rb
168
- - spec/objects/matrix_spec.rb
169
- - spec/objects/vector_spec.rb
170
- - spec/q_lang_spec.rb
171
- - spec/spec_helper.rb
181
+ - test/internal/test_tokens.rb
182
+ - test/interpreter/base.rb
183
+ - test/interpreter/test_differential.rb
184
+ - test/interpreter/test_function.rb
185
+ - test/interpreter/test_general.rb
186
+ - test/interpreter/test_integral.rb
187
+ - test/interpreter/test_matrix.rb
188
+ - test/interpreter/test_vector.rb
189
+ - test/langs/test_r.rb
190
+ - test/langs/test_ruby.rb
191
+ - test/minitest_helper.rb
192
+ - test/q_matrix/test_q_matrix.rb
193
+ - test/test_qlang.rb
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
@@ -1,20 +0,0 @@
1
- module Qlang
2
- module Lexer
3
- class ContLexer < Base
4
- rule(/:%\|.+\|%:/) { :R }
5
- rule(/('|")\w+('|")/) { :STR }
6
- rule(/[0-9]+/) { :NUM }
7
- rule(/\:/) { :CLN }
8
- rule(/\;/) { :SCLN }
9
- rule(/\,/) { :CMA }
10
-
11
- rule(/[ \t\f]/)
12
-
13
- rule(/\r\n/) { :NLIN }
14
-
15
- rule(/\w+/) { :SYM }
16
-
17
- rule(/.+/) { :OTHER }
18
- end
19
- end
20
- end