qlang 0.0.27000000 → 0.0.27100000

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9e53219836ec42b6ef2edb577c24f402f97e49c
4
- data.tar.gz: 2cf73154711705aa6b29b1da703b06638f37c01b
3
+ metadata.gz: dcf745e14a6861e5e9fb6c4910d8df2ba4e5f3f9
4
+ data.tar.gz: 297ae46f6a7a43efc30ad3225c919a34ea251244
5
5
  SHA512:
6
- metadata.gz: 1b1a074dec18140414233546d87d3de94c5ac22524054be77cac955a47ec7ba1f05069a84c63dc88275f0eeb09b5e5c1ba61436aef9d18a34e93cc764077dca7
7
- data.tar.gz: f23ae787a6fdcdf7a70e992dfa8db9e51e5f08f24dfdaa9db86f1ef0b3899478afb5ec5818325d68bdb517e45b1f0258e42326c24dc5c607c6784e7e067db588
6
+ metadata.gz: 9ff8c82a7f9711d3a2af78e50821aa03399fd38859925edb683dfa4883a2551a7cf4cf4a45a8543bf22969d413abc7e564c4311683b64201642d339efc186e55
7
+ data.tar.gz: 1f1322071f77fa070ced62cc7581bd50315d7408f91bd59585316608d13c72f50defb81e1f10b29c9db338481815712ea21b5bad0685033a9827cb476b10a22f
data/bin/qlang CHANGED
@@ -2,7 +2,8 @@
2
2
  require 'qlang'
3
3
  include Qlang
4
4
 
5
- case ARGV.shift
5
+ # TODO: There are vanch of todo ..
6
+ case ARGV.first
6
7
  when '-i'
7
8
  loop do
8
9
  print 'Q:-> '
@@ -14,7 +15,7 @@ when '-i'
14
15
  puts e
15
16
  end
16
17
  end
17
- when '-c'
18
- compiler = Qlang::Exec::Compiler.new(ARGV)
19
- compiler.parse!
18
+ when '-R', '-Ruby'
19
+ exec = Qlang::Exec::Compiler.new(ARGV)
20
+ exec.output!
20
21
  end
data/core/Q/Lexer.hs ADDED
@@ -0,0 +1,9 @@
1
+ {- |
2
+ Module : Language.Q
3
+ Copyright : Kazuki Tanaka (a.k.a gogotanaka)
4
+ Licence : MIT
5
+
6
+ q-language.org.
7
+ -}
8
+
9
+ module Q.Lexer where
data/core/Q/Parser.hs ADDED
@@ -0,0 +1,9 @@
1
+ {- |
2
+ Module : Language.Q
3
+ Copyright : Kazuki Tanaka (a.k.a gogotanaka)
4
+ Licence : MIT
5
+
6
+ q-language.org.
7
+ -}
8
+
9
+ module Q.Parser where
data/core/Q.hs ADDED
@@ -0,0 +1,19 @@
1
+ {- |
2
+ Module : Language.Q
3
+ Copyright : Kazuki Tanaka (a.k.a gogotanaka)
4
+ Licence : MIT
5
+
6
+ q-language.org.
7
+ -}
8
+
9
+ module Q
10
+ ( module Q.Lexer
11
+ , module Q.Parser
12
+ , version
13
+ ) where
14
+
15
+
16
+ import Q.Lexer
17
+ import Q.Parser
18
+
19
+ import Data.Version
data/lib/qlang/exec.rb CHANGED
@@ -5,9 +5,11 @@ module Qlang
5
5
  @args = args
6
6
  end
7
7
 
8
- def parse!
9
- ch_compile_type(ARGV.shift)
10
- parse
8
+ def output!
9
+ ch_compile_type(@args.first)
10
+ parse_string = parse(@args[1])
11
+ write!(@args[2], parse_string)
12
+
11
13
  rescue Exception => e
12
14
  raise e if @options[:trace] || e.is_a?(SystemExit)
13
15
 
@@ -28,17 +30,21 @@ module Qlang
28
30
  when '-R'
29
31
  Qlang.to_r
30
32
  else
31
- print 'Q support Ruby and R now.'
33
+ print 'Q support only Ruby and R now.'
32
34
  end
33
35
  end
34
36
 
35
- def parse
36
- raise '#{@args[0]} is unsupported option' unless @args[0] == '-q'
37
- filename = @args[1]
38
- file = open_file(filename)
39
- string = read_file(file)
40
- print(Kconv.tosjis(Qlang.compile(string)), '\n')
37
+ def parse(file_path)
38
+ file = open_file(file_path)
39
+ input_string = read_file(file)
41
40
  file.close
41
+ Kconv.tosjis(Qlang.compile(input_string))
42
+ end
43
+
44
+ def write!(output_path, string)
45
+ open(output_path, 'w') do |f|
46
+ f.puts string
47
+ end
42
48
  end
43
49
 
44
50
  def open_file(filename, flag = 'r')
@@ -32,7 +32,7 @@ module Qlang
32
32
  # THIRD TOKEN
33
33
  class ::String
34
34
  def func_call
35
- "#{FUNCV}#{LPRN}#{ANYSP}#{self}*#{ANYSP}#{RPRN}"
35
+ "#{FUNCV}#{LPRN}#{ANYSP}#{self}#{ANYSP}#{RPRN}"
36
36
  end
37
37
  end
38
38
  FUNCCN = NUMS_BY_CMA.func_call
data/lib/qlang/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qlang
2
- VERSION = "0.0.27000000"
2
+ VERSION = "0.0.27100000"
3
3
  end
@@ -0,0 +1,89 @@
1
+ if (base::getRversion() >= "2.15.1") {
2
+ utils::globalVariables(c("county.fips", "long", "lat", "group", "value", "label", "zipcode", "longitude", "latitude", "value"))
3
+ }
4
+
5
+ bind_df_to_zip_map = function(df)
6
+ {
7
+ stopifnot(c("region", "value") %in% colnames(df))
8
+ df = rename(df, replace=c("region" = "zip"))
9
+
10
+ data(zipcode, package="zipcode", envir=environment())
11
+ choropleth = merge(zipcode, df, all.x=F, all.y=T);
12
+
13
+ choropleth = choropleth[choropleth$longitude < -10, ]
14
+ }
15
+
16
+ print_zip_choropleth = function(choropleth.df, states, scaleName, theme, min, max)
17
+ {
18
+ stopifnot(states %in% state.abb)
19
+
20
+ a = (1 3 4)
21
+
22
+ state.df = subset_map("state", states)
23
+ colnames(state.df)[names(state.df) == "long"] = "longitude"
24
+ colnames(state.df)[names(state.df) == "lat"] = "latitude"
25
+ state.df = arrange(state.df, group, order);
26
+
27
+ if (is.numeric(choropleth.df$value))
28
+ {
29
+ ggplot(choropleth.df, aes(x=longitude, y=latitude, color=value)) +
30
+ geom_point() +
31
+ scale_color_continuous(scaleName, labels=comma) +
32
+ geom_polygon(data = state.df, color = "black", fill = NA, size = 0.2, aes(group=group)) +
33
+ theme;
34
+ } else {
35
+ stopifnot(length(unique(na.omit(choropleth.df$value))) <= 9)
36
+ ggplot(choropleth.df, aes(x=longitude, y=latitude, color=value)) +
37
+ geom_point() +
38
+ scale_colour_brewer(scaleName, labels=comma) +
39
+ geom_polygon(data = state.df, color = "black", fill = NA, size = 0.2, aes(group=group)) +
40
+ theme;
41
+ }
42
+ }
43
+
44
+ render_zip_choropleth = function(choropleth.df, title="", scaleName="", states=state.abb, renderAsInsets=TRUE)
45
+ {
46
+ choropleth.df = choropleth.df[choropleth.df$state %in% states, ]
47
+
48
+ min_val = 0
49
+ max_val = 0
50
+ if (is.numeric(choropleth.df$value))
51
+ {
52
+ min_val = min(choropleth.df$value)
53
+ max_val = max(choropleth.df$value)
54
+ }
55
+
56
+ if (length(states) == length(state.abb) &&
57
+ states == state.abb &&
58
+ renderAsInsets)
59
+ {
60
+ alaska.df = choropleth.df[choropleth.df$state=="AK",]
61
+ alaska.ggplot = print_zip_choropleth(alaska.df, "AK", "", theme_inset(), min_val, max_val)
62
+ alaska.grob = ggplotGrob(alaska.ggplot)
63
+
64
+ hawaii.df = choropleth.df[choropleth.df$state=="HI",]
65
+ hawaii.ggplot = print_zip_choropleth(hawaii.df, "HI", "", theme_inset(), min_val, max_val)
66
+ hawaii.grob = ggplotGrob(hawaii.ggplot)
67
+
68
+ choropleth.df = choropleth.df[!choropleth.df$state %in% c("AK", "HI"), ]
69
+ choropleth = print_zip_choropleth(choropleth.df, setdiff(state.abb, c("AK", "HI")), scaleName, theme_clean(), min_val, max_val) + ggtitle(title)
70
+
71
+ choropleth = choropleth +
72
+ annotation_custom(grobTree(hawaii.grob), xmin=-107.5, xmax=-102.5, ymin=25, ymax=27.5) +
73
+ annotation_custom(grobTree(alaska.grob), xmin=-125, xmax=-110, ymin=22.5, ymax=30)
74
+
75
+ } else {
76
+ choropleth = print_zip_choropleth(choropleth.df, states, scaleName, theme_clean(), min_val, max_val) + ggtitle(title)
77
+ }
78
+
79
+ choropleth
80
+ }
81
+
82
+ zip_choropleth_auto = function(df, num_buckets = 9, title = "", scaleName = "", states, renderAsInsets)
83
+ {
84
+ df = clip_df(df, "zip", states)
85
+ df = discretize_df(df, num_buckets)
86
+
87
+ choropleth.df = bind_df_to_zip_map(df)
88
+ render_zip_choropleth(choropleth.df, title, scaleName, states, renderAsInsets)
89
+ }
@@ -0,0 +1,89 @@
1
+ if (base::getRversion() >= "2.15.1") {
2
+ utils::globalVariables(c("county.fips", "long", "lat", "group", "value", "label", "zipcode", "longitude", "latitude", "value"))
3
+ }
4
+
5
+ bind_df_to_zip_map = function(df)
6
+ {
7
+ stopifnot(c("region", "value") %in% colnames(df))
8
+ df = rename(df, replace=c("region" = "zip"))
9
+
10
+ data(zipcode, package="zipcode", envir=environment())
11
+ choropleth = merge(zipcode, df, all.x=F, all.y=T);
12
+
13
+ choropleth = choropleth[choropleth$longitude < -10, ]
14
+ }
15
+
16
+ print_zip_choropleth = function(choropleth.df, states, scaleName, theme, min, max)
17
+ {
18
+ stopifnot(states %in% state.abb)
19
+
20
+ a = (1 3 4)
21
+
22
+ state.df = subset_map("state", states)
23
+ colnames(state.df)[names(state.df) == "long"] = "longitude"
24
+ colnames(state.df)[names(state.df) == "lat"] = "latitude"
25
+ state.df = arrange(state.df, group, order);
26
+
27
+ if (is.numeric(choropleth.df$value))
28
+ {
29
+ ggplot(choropleth.df, aes(x=longitude, y=latitude, color=value)) +
30
+ geom_point() +
31
+ scale_color_continuous(scaleName, labels=comma) +
32
+ geom_polygon(data = state.df, color = "black", fill = NA, size = 0.2, aes(group=group)) +
33
+ theme;
34
+ } else {
35
+ stopifnot(length(unique(na.omit(choropleth.df$value))) <= 9)
36
+ ggplot(choropleth.df, aes(x=longitude, y=latitude, color=value)) +
37
+ geom_point() +
38
+ scale_colour_brewer(scaleName, labels=comma) +
39
+ geom_polygon(data = state.df, color = "black", fill = NA, size = 0.2, aes(group=group)) +
40
+ theme;
41
+ }
42
+ }
43
+
44
+ render_zip_choropleth = function(choropleth.df, title="", scaleName="", states=state.abb, renderAsInsets=TRUE)
45
+ {
46
+ choropleth.df = choropleth.df[choropleth.df$state %in% states, ]
47
+
48
+ min_val = 0
49
+ max_val = 0
50
+ if (is.numeric(choropleth.df$value))
51
+ {
52
+ min_val = min(choropleth.df$value)
53
+ max_val = max(choropleth.df$value)
54
+ }
55
+
56
+ if (length(states) == length(state.abb) &&
57
+ states == state.abb &&
58
+ renderAsInsets)
59
+ {
60
+ alaska.df = choropleth.df[choropleth.df$state=="AK",]
61
+ alaska.ggplot = print_zip_choropleth(alaska.df, "AK", "", theme_inset(), min_val, max_val)
62
+ alaska.grob = ggplotGrob(alaska.ggplot)
63
+
64
+ hawaii.df = choropleth.df[choropleth.df$state=="HI",]
65
+ hawaii.ggplot = print_zip_choropleth(hawaii.df, "HI", "", theme_inset(), min_val, max_val)
66
+ hawaii.grob = ggplotGrob(hawaii.ggplot)
67
+
68
+ choropleth.df = choropleth.df[!choropleth.df$state %in% c("AK", "HI"), ]
69
+ choropleth = print_zip_choropleth(choropleth.df, setdiff(state.abb, c("AK", "HI")), scaleName, theme_clean(), min_val, max_val) + ggtitle(title)
70
+
71
+ choropleth = choropleth +
72
+ annotation_custom(grobTree(hawaii.grob), xmin=-107.5, xmax=-102.5, ymin=25, ymax=27.5) +
73
+ annotation_custom(grobTree(alaska.grob), xmin=-125, xmax=-110, ymin=22.5, ymax=30)
74
+
75
+ } else {
76
+ choropleth = print_zip_choropleth(choropleth.df, states, scaleName, theme_clean(), min_val, max_val) + ggtitle(title)
77
+ }
78
+
79
+ choropleth
80
+ }
81
+
82
+ zip_choropleth_auto = function(df, num_buckets = 9, title = "", scaleName = "", states, renderAsInsets)
83
+ {
84
+ df = clip_df(df, "zip", states)
85
+ df = discretize_df(df, num_buckets)
86
+
87
+ choropleth.df = bind_df_to_zip_map(df)
88
+ render_zip_choropleth(choropleth.df, title, scaleName, states, renderAsInsets)
89
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qlang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.27000000
4
+ version: 0.0.27100000
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
@@ -84,6 +84,9 @@ files:
84
84
  - README.md
85
85
  - Rakefile
86
86
  - bin/qlang
87
+ - core/Q.hs
88
+ - core/Q/Lexer.hs
89
+ - core/Q/Parser.hs
87
90
  - lib/qlang.rb
88
91
  - lib/qlang/api.rb
89
92
  - lib/qlang/api/func_api.rb
@@ -110,6 +113,8 @@ files:
110
113
  - lib/qlang/version.rb
111
114
  - q_lang.gemspec
112
115
  - spec/iq_spec.rb
116
+ - spec/langs/R/ex1_after.R
117
+ - spec/langs/R/ex1_before.R
113
118
  - spec/lexer/regular_expressions_spec.rb
114
119
  - spec/objects/function_spec.rb
115
120
  - spec/objects/integral_spec.rb
@@ -144,6 +149,8 @@ specification_version: 4
144
149
  summary: Enjoy MATH!
145
150
  test_files:
146
151
  - spec/iq_spec.rb
152
+ - spec/langs/R/ex1_after.R
153
+ - spec/langs/R/ex1_before.R
147
154
  - spec/lexer/regular_expressions_spec.rb
148
155
  - spec/objects/function_spec.rb
149
156
  - spec/objects/integral_spec.rb