qlang 0.0.27182000 → 0.0.27182100
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +17 -1
- data/Rakefile +16 -3
- data/bin/qlang +7 -1
- data/ext/qlang/QMatrix/q_matrix.c +0 -0
- data/ext/qlang/extconf.rb +3 -0
- data/ext/qlang/qlang.c +65 -0
- data/ext/qlang/qlang.h +6 -0
- data/{spec → legacy_rspec}/langs/Haskell/ex1_after.hs +0 -0
- data/{spec → legacy_rspec}/langs/Haskell/ex1_before.hs +0 -0
- data/{spec → legacy_rspec}/langs/Python/ex1_after.py +0 -0
- data/{spec → legacy_rspec}/langs/Python/ex1_before.py +0 -0
- data/{spec → legacy_rspec}/langs/R/ex1_after.R +0 -0
- data/{spec → legacy_rspec}/langs/R/ex1_before.R +0 -0
- data/{spec → legacy_rspec}/objects/list_spec.rb +0 -0
- data/{spec → legacy_rspec}/objects/matrix_spec.rb +0 -0
- data/{spec → legacy_rspec}/objects/vector_spec.rb +0 -0
- data/lib/qlang.rb +21 -18
- data/lib/qlang/api/func_api.rb +1 -1
- data/lib/qlang/api/integral_api.rb +1 -1
- data/lib/qlang/api/list_api.rb +1 -1
- data/lib/qlang/api/matrix_api.rb +1 -1
- data/lib/qlang/api/vector_api.rb +1 -1
- data/lib/qlang/iq.rb +5 -2
- data/lib/qlang/lexer.rb +2 -2
- data/lib/qlang/lexer/base.rb +31 -14
- data/lib/qlang/lexer/formula_lexer.rb +20 -0
- data/lib/qlang/lexer/main_lexer.rb +25 -0
- data/lib/qlang/lexer/tokens.rb +27 -15
- data/lib/qlang/parser.rb +29 -41
- data/lib/qlang/parser/formula_parser.rb +25 -25
- data/lib/qlang/parser/func_parser.rb +2 -2
- data/lib/qlang/parser/integral_parser.rb +2 -2
- data/lib/qlang/parser/matrix_parser.rb +3 -3
- data/lib/qlang/parser/vector_parser.rb +4 -4
- data/lib/qlang/version.rb +1 -1
- data/{q_lang.gemspec → qlang.gemspec} +4 -2
- data/test/internal/test_tokens.rb +36 -0
- data/test/interpreter/base.rb +17 -0
- data/test/interpreter/test_differential.rb +44 -0
- data/test/interpreter/test_function.rb +45 -0
- data/test/interpreter/test_general.rb +13 -0
- data/test/interpreter/test_integral.rb +39 -0
- data/test/interpreter/test_matrix.rb +71 -0
- data/test/interpreter/test_vector.rb +29 -0
- data/test/langs/test_r.rb +33 -0
- data/test/langs/test_ruby.rb +10 -0
- data/{spec/spec_helper.rb → test/minitest_helper.rb} +4 -4
- data/test/q_matrix/test_q_matrix.rb +13 -0
- data/test/test_qlang.rb +25 -0
- metadata +65 -43
- data/.rspec +0 -2
- data/lib/qlang/lexer/cont_lexer.rb +0 -20
- data/lib/qlang/lexer/func_lexer.rb +0 -13
- data/lib/qlang/lexer/wrap_lexer.rb +0 -25
- data/spec/iq_spec.rb +0 -141
- data/spec/lexer/regular_expressions_spec.rb +0 -45
- data/spec/objects/function_spec.rb +0 -33
- data/spec/objects/integral_spec.rb +0 -21
- data/spec/q_lang_spec.rb +0 -47
@@ -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
|
data/test/test_qlang.rb
ADDED
@@ -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.
|
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-
|
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: '
|
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: '
|
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:
|
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/
|
102
|
-
- lib/qlang/lexer/
|
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
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
120
|
-
-
|
121
|
-
-
|
122
|
-
-
|
123
|
-
-
|
124
|
-
-
|
125
|
-
-
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
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
|
-
-
|
158
|
-
-
|
159
|
-
-
|
160
|
-
-
|
161
|
-
-
|
162
|
-
-
|
163
|
-
-
|
164
|
-
-
|
165
|
-
-
|
166
|
-
-
|
167
|
-
-
|
168
|
-
-
|
169
|
-
-
|
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,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
|