qlang 0.0.27182123 → 0.0.27182124
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Guardfile +33 -0
- data/README.md +25 -26
- data/Rakefile +8 -8
- data/ext/qlang/extconf.rb +2 -2
- data/legacy_rspec/objects/list_spec.rb +2 -2
- data/legacy_rspec/objects/matrix_spec.rb +7 -7
- data/legacy_rspec/objects/vector_spec.rb +5 -5
- data/lib/qlang/api/func_api.rb +0 -1
- data/lib/qlang/api/integral_api.rb +0 -1
- data/lib/qlang/api/limit_api.rb +1 -1
- data/lib/qlang/api/list_api.rb +0 -1
- data/lib/qlang/api/sigma_api.rb +1 -1
- data/lib/qlang/exec.rb +31 -31
- data/lib/qlang/iq.rb +0 -1
- data/lib/qlang/lexer/base.rb +17 -17
- data/lib/qlang/lexer/main_lexer.rb +4 -0
- data/lib/qlang/lexer/tokens.rb +3 -5
- data/lib/qlang/meta_info.rb +6 -6
- data/lib/qlang/parser.rb +22 -21
- data/lib/qlang/parser/list_parser.rb +1 -1
- data/lib/qlang/parser/matrix_parser.rb +1 -1
- data/lib/qlang/version.rb +1 -1
- data/qlang.gemspec +6 -6
- data/test/internal/test_tokens.rb +0 -1
- data/test/interpreter/test_differential.rb +0 -1
- data/test/interpreter/test_function.rb +0 -1
- data/test/interpreter/test_general.rb +0 -1
- data/test/interpreter/test_integral.rb +0 -1
- data/test/interpreter/test_limit.rb +4 -5
- data/test/interpreter/test_matrix.rb +0 -1
- data/test/interpreter/test_sigma.rb +2 -1
- data/test/interpreter/test_vector.rb +0 -1
- data/test/langs/test_r.rb +0 -1
- data/test/langs/test_ruby.rb +0 -1
- data/test/q_matrix/test_q_matrix.rb +1 -1
- data/test/test_qlang.rb +0 -1
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTIxMDJhZjBiZGFkMDJlMjQ2YzQ0MDY4M2Y3ZTIwNGEwOGY3ZWM3Nw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTM4YWY3NTIyODllYTJmNTVhNjc2NjUzZTViODEzMzcxOWU0N2QxOA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDI0ZWE1ZTk4Yjk2MTc1NjU3Y2RjYmUwY2YxMjg4MTZiMDk2NzVkZGE2ZWUz
|
10
|
+
YjczMWI4OTZjM2FlM2QwNTUxZTAzNWEyMTc2ZDJmMjAyM2Q5ZTljNGQ0YjQ1
|
11
|
+
ZWU0NWQ4MDFiZTQ0NzkwMzlkY2RmMDU1YmQ4OThlNDIxNzkxYmQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGNiZmMyOGI4YTg5M2Y5MWQxOGQ5ZTZhZmZmZWQzYzc0YzljZjc2NDkwMzVj
|
14
|
+
YzM2YzVjNDZjYzBmMDUwYWZlNmMzYWIwYTJkODgzN2Q5Mjk3MjllNmJmMGM0
|
15
|
+
MzM3NDg1MThlMTY4NGY0YmVlNDlhMDk3OGFmZjRmMTJiZjM2NGY=
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
5
|
+
# rspec may be run, below are examples of the most common uses.
|
6
|
+
# * bundler: 'bundle exec rspec'
|
7
|
+
# * bundler binstubs: 'bin/rspec'
|
8
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
9
|
+
# installed the spring binstubs per the docs)
|
10
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
11
|
+
# * 'just' rspec: 'rspec'
|
12
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
|
17
|
+
# Rails example
|
18
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
19
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
20
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
21
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
22
|
+
watch('config/routes.rb') { "spec/routing" }
|
23
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
24
|
+
watch('spec/rails_helper.rb') { "spec" }
|
25
|
+
|
26
|
+
# Capybara features specs
|
27
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
28
|
+
|
29
|
+
# Turnip features and steps
|
30
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
31
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
32
|
+
end
|
33
|
+
|
data/README.md
CHANGED
@@ -2,27 +2,27 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/qlang.svg)](http://badge.fury.io/rb/qlang) [![Build Status](https://travis-ci.org/gogotanaka/Q.svg?branch=master)](https://travis-ci.org/gogotanaka/Q) [![Coverage Status](https://coveralls.io/repos/gogotanaka/Q/badge.png?branch=master)](https://coveralls.io/r/gogotanaka/Q?branch=master) [![Code Climate](https://codeclimate.com/github/gogotanaka/Q/badges/gpa.svg)](https://codeclimate.com/github/gogotanaka/Q) [![Dependency Status](https://gemnasium.com/gogotanaka/Q.svg)](https://gemnasium.com/gogotanaka/Q)
|
4
4
|
|
5
|
-
## Do you know one
|
5
|
+
## Do you know the one best language in this world?
|
6
6
|
|
7
|
-
#### I
|
7
|
+
#### I believe mathematics is absolutely that one.
|
8
8
|
|
9
|
-
## How can we deal
|
9
|
+
## How can we deal something as great as mathematics in a discrete world?
|
10
10
|
|
11
|
-
#### Q-language
|
11
|
+
#### Q-language is the answer.
|
12
12
|
|
13
|
-
Q
|
13
|
+
Q lets you have a sense of mathematics using a keyboard, the same as you would with a pen.
|
14
14
|
|
15
15
|
```
|
16
|
-
+---
|
17
|
-
| Ruby
|
18
|
-
| TeX
|
19
|
-
|
|
20
|
-
|
16
|
+
+---Discrete world---+ +------Mathematics-------+
|
17
|
+
| Ruby | | axiom |
|
18
|
+
| TeX |<------ Q ------>| Uncountable noun |
|
19
|
+
| Python | | real number topology |
|
20
|
+
+--------------------+ +------------------------+
|
21
21
|
```
|
22
22
|
|
23
23
|
## Demo
|
24
24
|
|
25
|
-
|
25
|
+
The code below is input and output for the q-lang interpreter
|
26
26
|
|
27
27
|
(you can try it by `qlang -i`)
|
28
28
|
|
@@ -37,7 +37,7 @@ d/dx(cos(x))
|
|
37
37
|
d/dx log(x)
|
38
38
|
=> ( 1 / x )
|
39
39
|
|
40
|
-
d/dy xy
|
40
|
+
d/dy xy
|
41
41
|
=> ( x )
|
42
42
|
|
43
43
|
d/dx e^x
|
@@ -53,7 +53,7 @@ S(log(x)dx)[0..1]
|
|
53
53
|
S(sin(x)dx)[0..pi]
|
54
54
|
=> 2.0
|
55
55
|
|
56
|
-
S(cos(x)dx)[0..pi]
|
56
|
+
S(cos(x)dx)[0..pi]
|
57
57
|
=> 0.0
|
58
58
|
```
|
59
59
|
|
@@ -96,21 +96,25 @@ f(1, 2)
|
|
96
96
|
|
97
97
|
## How to use
|
98
98
|
|
99
|
-
Install qlang
|
99
|
+
Install qlang gem.
|
100
100
|
|
101
101
|
$ gem install qlang
|
102
|
-
|
103
|
-
|
102
|
+
|
103
|
+
## Interpreter
|
104
|
+
|
105
|
+
$ qlang -i
|
106
|
+
Q:->
|
107
|
+
|
104
108
|
## Use as native language
|
105
109
|
|
106
110
|
### Compile into R
|
107
111
|
|
108
112
|
$ qlang -r foo.q
|
109
|
-
|
113
|
+
|
110
114
|
### Compile into Ruby
|
111
115
|
|
112
116
|
$ qlang -rb foo.q
|
113
|
-
|
117
|
+
|
114
118
|
### Compile into Python
|
115
119
|
|
116
120
|
$ qlang -py foo.q
|
@@ -135,7 +139,7 @@ end
|
|
135
139
|
```
|
136
140
|
|
137
141
|
$ qlang -rb example.rb
|
138
|
-
|
142
|
+
|
139
143
|
|
140
144
|
```rb
|
141
145
|
class ExampleClass
|
@@ -149,12 +153,7 @@ class ExampleClass
|
|
149
153
|
end
|
150
154
|
```
|
151
155
|
|
152
|
-
## Interpreter
|
153
|
-
|
154
|
-
$ qlang -i
|
155
|
-
Q:->
|
156
|
-
|
157
156
|
## Contributing
|
158
157
|
|
159
|
-
|
160
|
-
You can become commiter, if you commit
|
158
|
+
Any PRs or issues are welcome.
|
159
|
+
You can become a commiter, even if you only commit once.
|
data/Rakefile
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
5
|
+
t.libs << 'test'
|
6
6
|
t.test_files = FileList['test/**/test_*.rb']
|
7
7
|
end
|
8
8
|
|
9
|
-
require
|
9
|
+
require 'rake/extensiontask'
|
10
10
|
|
11
|
-
Rake::ExtensionTask.new(
|
12
|
-
ext.lib_dir =
|
11
|
+
Rake::ExtensionTask.new('qlang') do |ext|
|
12
|
+
ext.lib_dir = 'lib/qlang'
|
13
13
|
end
|
14
14
|
|
15
15
|
task :compile_and_test do
|
16
|
-
Rake::Task[
|
17
|
-
Rake::Task[
|
16
|
+
Rake::Task['compile'].invoke
|
17
|
+
Rake::Task['test'].invoke
|
18
18
|
end
|
19
19
|
|
20
20
|
task default: :compile_and_test
|
data/ext/qlang/extconf.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
require
|
1
|
+
require 'mkmf'
|
2
2
|
|
3
|
-
create_makefile(
|
3
|
+
create_makefile('qlang/qlang')
|
@@ -12,13 +12,13 @@ describe Qlang do
|
|
12
12
|
expect(
|
13
13
|
Q.to_r.compile('{key1: 234234, key2: 387342 }')
|
14
14
|
).to eq(
|
15
|
-
|
15
|
+
'list(key1=234234, key2=387342)'
|
16
16
|
)
|
17
17
|
|
18
18
|
expect(
|
19
19
|
Q.to_r.compile('{key1:234234,key2:387342,key3:38733242}')
|
20
20
|
).to eq(
|
21
|
-
|
21
|
+
'list(key1=234234, key2=387342, key3=38733242)'
|
22
22
|
)
|
23
23
|
|
24
24
|
# expect(
|
@@ -7,25 +7,25 @@ describe Qlang do
|
|
7
7
|
expect(
|
8
8
|
Q.to_r.compile('(1 2 3; 4 5 6)')
|
9
9
|
).to eq(
|
10
|
-
|
10
|
+
'matrix(c(1, 2, 3, 4, 5, 6), 2, 3, byrow = TRUE)'
|
11
11
|
)
|
12
12
|
|
13
13
|
expect(
|
14
14
|
Q.to_r.compile('(1 2 3 ; 4 5 6)')
|
15
15
|
).to eq(
|
16
|
-
|
16
|
+
'matrix(c(1, 2, 3, 4, 5, 6), 2, 3, byrow = TRUE)'
|
17
17
|
)
|
18
18
|
|
19
19
|
expect(
|
20
20
|
Q.to_r.compile('(1 2 3 ; 4 5 6; 7 8 9)')
|
21
21
|
).to eq(
|
22
|
-
|
22
|
+
'matrix(c(1, 2, 3, 4, 5, 6, 7, 8, 9), 3, 3, byrow = TRUE)'
|
23
23
|
)
|
24
24
|
|
25
25
|
expect(
|
26
26
|
Q.to_r.compile('(1;2;3)')
|
27
27
|
).to eq(
|
28
|
-
|
28
|
+
'matrix(c(1, 2, 3), 3, 1, byrow = TRUE)'
|
29
29
|
)
|
30
30
|
end
|
31
31
|
end
|
@@ -35,19 +35,19 @@ describe Qlang do
|
|
35
35
|
expect(
|
36
36
|
Q.to_ruby.compile('(1 2 3; 4 5 6)')
|
37
37
|
).to eq(
|
38
|
-
|
38
|
+
'Matrix[[1, 2, 3], [4, 5, 6]]'
|
39
39
|
)
|
40
40
|
|
41
41
|
expect(
|
42
42
|
Q.to_ruby.compile('(1 2 3 ; 4 5 6; 7 8 9)')
|
43
43
|
).to eq(
|
44
|
-
|
44
|
+
'Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]'
|
45
45
|
)
|
46
46
|
|
47
47
|
expect(
|
48
48
|
Q.to_ruby.compile('(1;2;3)')
|
49
49
|
).to eq(
|
50
|
-
|
50
|
+
'Matrix[[1], [2], [3]]'
|
51
51
|
)
|
52
52
|
end
|
53
53
|
end
|
@@ -7,19 +7,19 @@ describe Qlang do
|
|
7
7
|
expect(
|
8
8
|
Q.to_r.compile('(1 2 3)')
|
9
9
|
).to eq(
|
10
|
-
|
10
|
+
'c(1, 2, 3)'
|
11
11
|
)
|
12
12
|
|
13
13
|
expect(
|
14
14
|
Q.to_r.compile('(1 2 3 4 5 6)')
|
15
15
|
).to eq(
|
16
|
-
|
16
|
+
'c(1, 2, 3, 4, 5, 6)'
|
17
17
|
)
|
18
18
|
|
19
19
|
expect(
|
20
20
|
Q.to_r.compile('(1 2 3 4 5 6)')
|
21
21
|
).to eq(
|
22
|
-
|
22
|
+
'c(1, 2, 3, 4, 5, 6)'
|
23
23
|
)
|
24
24
|
end
|
25
25
|
end
|
@@ -29,7 +29,7 @@ describe Qlang do
|
|
29
29
|
expect(
|
30
30
|
Q.to_ruby.compile('(1 2 3)')
|
31
31
|
).to eq(
|
32
|
-
|
32
|
+
'Vector[1, 2, 3]'
|
33
33
|
)
|
34
34
|
end
|
35
35
|
end
|
@@ -39,7 +39,7 @@ describe Qlang do
|
|
39
39
|
expect(
|
40
40
|
Q.to_python.compile('(1 2 3)')
|
41
41
|
).to eq(
|
42
|
-
|
42
|
+
'array([1, 2, 3])'
|
43
43
|
)
|
44
44
|
end
|
45
45
|
end
|
data/lib/qlang/api/func_api.rb
CHANGED
data/lib/qlang/api/limit_api.rb
CHANGED
data/lib/qlang/api/list_api.rb
CHANGED
data/lib/qlang/api/sigma_api.rb
CHANGED
data/lib/qlang/exec.rb
CHANGED
@@ -15,7 +15,7 @@ module Qlang
|
|
15
15
|
|
16
16
|
print "#{e.class}: " unless e.class == RuntimeError
|
17
17
|
puts "#{e.message}"
|
18
|
-
puts
|
18
|
+
puts ' Use --trace for backtrace.'
|
19
19
|
exit 1
|
20
20
|
ensure
|
21
21
|
exit 0
|
@@ -23,42 +23,42 @@ module Qlang
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
26
|
+
def ch_compile_type(lang)
|
27
|
+
case lang
|
28
|
+
when '-rb'
|
29
|
+
Qlang.to_ruby
|
30
|
+
when '-r'
|
31
|
+
Qlang.to_r
|
32
|
+
when '-py'
|
33
|
+
Qlang.to_python
|
34
|
+
else
|
35
|
+
print 'Q support only Ruby and R now.'
|
37
36
|
end
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
def parse(file_path)
|
40
|
+
file = open_file(file_path)
|
41
|
+
input_string = read_file(file)
|
42
|
+
file.close
|
43
|
+
input_string.gsub(/(.*)I love mathematics\.(.*)Q\.E\.D(.*)/m) {
|
44
|
+
"#{$1}#{Kconv.tosjis(Qlang.compile($2))}#{$3}"
|
45
|
+
}
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
48
|
+
def write!(output_path, string)
|
49
|
+
open(output_path, 'w') do |f|
|
50
|
+
f.puts string
|
52
51
|
end
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
def open_file(filename, flag = 'r')
|
55
|
+
return if filename.nil?
|
56
|
+
File.open(filename, flag)
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
def read_file(file)
|
60
|
+
file.read
|
61
|
+
end
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/lib/qlang/iq.rb
CHANGED
data/lib/qlang/lexer/base.rb
CHANGED
@@ -67,15 +67,15 @@ module Qlang
|
|
67
67
|
## POST(with side effect, without idempotence.)
|
68
68
|
def parsed!(parsed, target)
|
69
69
|
case target
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
when Range
|
71
|
+
parsed_between!((target.first.to_i)..(target.last.to_i), parsed)
|
72
|
+
else
|
73
|
+
parsed_at!(target.to_i, parsed)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
#squash!(range, token: :CONT)
|
78
|
-
def squash!(range, opts={token: :CONT})
|
77
|
+
# squash!(range, token: :CONT)
|
78
|
+
def squash!(range, opts = { token: :CONT })
|
79
79
|
token = opts[:token]
|
80
80
|
range = (range.first.to_i)..(range.last.to_i)
|
81
81
|
value = values[range].join
|
@@ -89,19 +89,19 @@ module Qlang
|
|
89
89
|
end
|
90
90
|
|
91
91
|
private
|
92
|
-
def parsed_at!(token_position, parsed)
|
93
|
-
@lexeds.delete_at(token_position)
|
94
|
-
@lexeds.insert(token_position, { token: :R, value: parsed })
|
95
|
-
end
|
96
92
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
@lexeds.insert(start_pos, { token: :R, value: parsed })
|
103
|
-
end
|
93
|
+
def parsed_at!(token_position, parsed)
|
94
|
+
@lexeds.delete_at(token_position)
|
95
|
+
@lexeds.insert(token_position, { token: :R, value: parsed })
|
96
|
+
end
|
104
97
|
|
98
|
+
def parsed_between!(token_range, parsed)
|
99
|
+
start_pos = token_range.first
|
100
|
+
token_range.count.times do
|
101
|
+
@lexeds.delete_at(start_pos)
|
102
|
+
end
|
103
|
+
@lexeds.insert(start_pos, { token: :R, value: parsed })
|
104
|
+
end
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
1
4
|
module Qlang
|
2
5
|
module Lexer
|
3
6
|
class MainLexer < Base
|
@@ -12,6 +15,7 @@ module Qlang
|
|
12
15
|
rule(/#{LPRN}(#{NUMS_BY_SP_BY_SCLN_OR_NELN})#{RPRN}/m) { :matrix }
|
13
16
|
|
14
17
|
rule(/∑#{LBRCT}(#{VAR})=(#{INT}),#{ANYSP}(#{INT})#{RBRCT} (#{FORMULA})/) { :sigma }
|
18
|
+
rule(/sigma#{LBRCT}(#{VAR})=(#{INT}),#{ANYSP}(#{INT})#{RBRCT} (#{FORMULA})/) { :sigma }
|
15
19
|
|
16
20
|
rule(/#{FUNCCN}/) { :FUNCCN }
|
17
21
|
|
data/lib/qlang/lexer/tokens.rb
CHANGED
@@ -19,15 +19,14 @@ module Qlang
|
|
19
19
|
|
20
20
|
# VARIABLE
|
21
21
|
VAR = /(?:[a-d]|[f-z])/
|
22
|
-
#VAR_MUL2 = /(?!pi)#{VAR}{2}/
|
22
|
+
# VAR_MUL2 = /(?!pi)#{VAR}{2}/
|
23
23
|
# #VAR_MUL3 = /(?!#{EMBEDDED_FUNC})#{VAR}{3}/
|
24
24
|
# # FIX:
|
25
|
-
#VAR_MUL = /(?!#{EMBEDDED_FUNC})#{VAR_MUL2}/
|
25
|
+
# VAR_MUL = /(?!#{EMBEDDED_FUNC})#{VAR_MUL2}/
|
26
26
|
|
27
27
|
# # TERM
|
28
28
|
# TERM = /(#{NUM}|#{VAR_MUL}|#{VAR_MUL})/
|
29
29
|
|
30
|
-
|
31
30
|
# OPE
|
32
31
|
PLS = /\+/
|
33
32
|
SUB = /-/
|
@@ -41,7 +40,6 @@ module Qlang
|
|
41
40
|
ANYSTR = /.+/
|
42
41
|
NONL = /[^\r\n]/
|
43
42
|
|
44
|
-
|
45
43
|
PRN = /(?:#{LPRN}|#{RPRN})/
|
46
44
|
|
47
45
|
LBRCS = /\{/
|
@@ -71,7 +69,7 @@ module Qlang
|
|
71
69
|
# TODO: what is better
|
72
70
|
class Util
|
73
71
|
def self.string_out(str, partition)
|
74
|
-
|
72
|
+
/#{ANYSP}#{str}(?:#{ANYSP}#{partition}#{ANYSP}#{str})*#{ANYSP}/
|
75
73
|
end
|
76
74
|
|
77
75
|
def self.func_call(args)
|
data/lib/qlang/meta_info.rb
CHANGED
@@ -12,12 +12,12 @@ class MetaInfo
|
|
12
12
|
# TODO: YAML.load_file("./lib/qlang/utils/langs.yml")['langs']
|
13
13
|
def langs_hash
|
14
14
|
{
|
15
|
-
r:
|
16
|
-
ruby:
|
17
|
-
python:
|
18
|
-
haskell:
|
19
|
-
scala:
|
20
|
-
js:
|
15
|
+
r: 'R',
|
16
|
+
ruby: 'Ruby',
|
17
|
+
python: 'Pyhton',
|
18
|
+
haskell: 'Haskell',
|
19
|
+
scala: 'Scala',
|
20
|
+
js: 'Javascript'
|
21
21
|
}
|
22
22
|
end
|
23
23
|
|
data/lib/qlang/parser.rb
CHANGED
@@ -25,25 +25,26 @@ module Qlang
|
|
25
25
|
when /:(vector)(\d+)/, /:(matrix)(\d+)/, /:(tmatrix)(\d+)/, /:(integral)(\d+)/, /:(def_func)(\d+)/, /:(differential)(\d+)/, /:(limit)(\d+)/, /:(sigma)(\d+)/
|
26
26
|
token_els = lexed.get_els($2)
|
27
27
|
|
28
|
-
parsed =
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
28
|
+
parsed =
|
29
|
+
case $1
|
30
|
+
when 'vector'
|
31
|
+
VectorParser.execute(token_els)
|
32
|
+
when 'matrix'
|
33
|
+
MatrixParser.execute(token_els)
|
34
|
+
when 'tmatrix'
|
35
|
+
MatrixParser.execute(token_els, trans: true)
|
36
|
+
when 'limit'
|
37
|
+
LimitParser.execute(token_els)
|
38
|
+
when 'integral'
|
39
|
+
IntegralParser.execute(token_els)
|
40
|
+
when 'def_func'
|
41
|
+
FuncParser.execute(token_els)
|
42
|
+
when 'sigma'
|
43
|
+
SigmaParser.execute(token_els)
|
44
|
+
when 'differential'
|
45
|
+
del_var, formula = token_els
|
46
|
+
"d/d#{del_var}(#{FormulaParser.execute(formula)})"
|
47
|
+
end
|
47
48
|
lexed.parsed!(parsed, $2)
|
48
49
|
|
49
50
|
when /:LPRN(\d+):CONT(\d+):RPRN(\d+)/
|
@@ -59,7 +60,8 @@ module Qlang
|
|
59
60
|
tokens_range = $1.to_i..$3.to_i
|
60
61
|
token_val = lexed.get_value($2)
|
61
62
|
|
62
|
-
cont =
|
63
|
+
cont =
|
64
|
+
case token_val
|
63
65
|
when /#{ONEHASH}(#{CMA}#{ONEHASH})*/
|
64
66
|
ListParser.execute(token_val)
|
65
67
|
else
|
@@ -95,6 +97,5 @@ module Qlang
|
|
95
97
|
end
|
96
98
|
end
|
97
99
|
end
|
98
|
-
|
99
100
|
end
|
100
101
|
end
|
@@ -3,7 +3,7 @@ module Qlang
|
|
3
3
|
module ListParser
|
4
4
|
include Base
|
5
5
|
def execute(lexed)
|
6
|
-
arys = lexed.split(/ *, */).map { |e| e.split(/ *: */).map{|e2|e2.delete(' ')} }
|
6
|
+
arys = lexed.split(/ *, */).map { |e| e.split(/ *: */).map { |e2| e2.delete(' ') } }
|
7
7
|
ListApi.execute(arys)
|
8
8
|
end
|
9
9
|
module_function :execute
|
@@ -2,7 +2,7 @@ module Qlang
|
|
2
2
|
module Parser
|
3
3
|
module MatrixParser
|
4
4
|
include Base
|
5
|
-
def execute(els, opts={trans: false})
|
5
|
+
def execute(els, opts = { trans: false })
|
6
6
|
trans = opts[:trans]
|
7
7
|
rows = els.first.split(/ *(?:;|\n) */).map(&:split_by_sp)
|
8
8
|
rows.all? { |row| row.count == rows.first.count }
|
data/lib/qlang/version.rb
CHANGED
data/qlang.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Qlang::VERSION
|
9
9
|
spec.authors = ['gogotanaka']
|
10
10
|
spec.email = ['mail@tanakakazuki.com']
|
11
|
-
spec.extensions = [
|
11
|
+
spec.extensions = ['ext/qlang/extconf.rb']
|
12
12
|
spec.summary = %q{Enjoy MATH!}
|
13
13
|
spec.description = %q{Enjoy MATH!}
|
14
14
|
spec.homepage = 'http://q-language.org/'
|
@@ -19,10 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_dependency
|
22
|
+
spec.add_dependency 'dydx', '~> 0.1.41421'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rake-compiler'
|
27
|
+
spec.add_development_dependency 'minitest'
|
28
28
|
end
|
@@ -2,7 +2,6 @@ require 'minitest_helper'
|
|
2
2
|
|
3
3
|
class TestLimit < TestInterpreterBase
|
4
4
|
def setup
|
5
|
-
|
6
5
|
end
|
7
6
|
|
8
7
|
def assert_iq_equal(output, input)
|
@@ -20,10 +19,10 @@ class TestLimit < TestInterpreterBase
|
|
20
19
|
'lim[x->10] x'
|
21
20
|
)
|
22
21
|
|
23
|
-
assert_iq_equal(
|
24
|
-
|
25
|
-
|
26
|
-
)
|
22
|
+
# assert_iq_equal(
|
23
|
+
# '2.7182682371744895',
|
24
|
+
# 'lim[x->oo] (1 + 1/x)^x'
|
25
|
+
# )
|
27
26
|
|
28
27
|
assert_iq_equal(
|
29
28
|
'oo',
|
data/test/langs/test_r.rb
CHANGED
data/test/langs/test_ruby.rb
CHANGED
data/test/test_qlang.rb
CHANGED
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.27182124
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dydx
|
@@ -28,56 +28,56 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
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
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake-compiler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '>='
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '>='
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Enjoy MATH!
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- .rubocop.yml
|
95
95
|
- .travis.yml
|
96
96
|
- Gemfile
|
97
|
+
- Guardfile
|
97
98
|
- LICENSE.txt
|
98
99
|
- README.md
|
99
100
|
- Rakefile
|
@@ -170,17 +171,17 @@ require_paths:
|
|
170
171
|
- lib
|
171
172
|
required_ruby_version: !ruby/object:Gem::Requirement
|
172
173
|
requirements:
|
173
|
-
- - '>='
|
174
|
+
- - ! '>='
|
174
175
|
- !ruby/object:Gem::Version
|
175
176
|
version: '0'
|
176
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
178
|
requirements:
|
178
|
-
- - '>='
|
179
|
+
- - ! '>='
|
179
180
|
- !ruby/object:Gem::Version
|
180
181
|
version: '0'
|
181
182
|
requirements: []
|
182
183
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.4.2
|
184
185
|
signing_key:
|
185
186
|
specification_version: 4
|
186
187
|
summary: Enjoy MATH!
|