code-ruby 0.15.15 → 0.15.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 381b6da2c705fe3f7f21f03ed74bb43029e0a93348b16372c7313c8f9998d90d
4
- data.tar.gz: 3c37e2ce62f94eadb7575a53b6bb60ac61e1b1804eafba3bd90f792d7271523e
3
+ metadata.gz: 441325308911e5cba82286bbc9a4be1d33c03b25210dbaeb818bf78c97ce12e4
4
+ data.tar.gz: 3b56769984fc4ffa5a1e9a036bfbac8393462dc1e22033804627764aa3b7aabf
5
5
  SHA512:
6
- metadata.gz: b23a3ac309cbab033d5212d9f79fdd7a8afc654ee586915459641db7b13b8bd6bd5dfc3b3f373379718b5c6185612d920ccd322572dfb8edbce30606473a7d66
7
- data.tar.gz: 29cee7ad7781d50a3682611385a4fa8236d935fc6f26474019834e70f9e8f8518b065213a5fca1af8eb2cd41c4a766e7566d3621de7129f03bd69e92a99a93af
6
+ metadata.gz: c8d1677af87363f60d2a2321af4539b8912f6c36f3185b7c8bc142ec2470853ea6f5884df3712903ae45cef4da168603620b7f1c9398b99fcd091c90d6a92a82
7
+ data.tar.gz: 1ab4328234974b7bd6501af777b5be1e6f76d8398927dd21fc6dfd18d210b19791462793973e7ec3b11dce4941733c9dc60fd0d353da2a59dbca17d5c8a40dac
data/Gemfile.lock CHANGED
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (0.15.15)
4
+ code-ruby (0.15.16)
5
5
  activesupport
6
6
  bigdecimal
7
7
  did-you-mean
8
+ dorian-arguments
8
9
  json
9
10
  language-ruby
10
11
  zeitwerk
@@ -34,11 +35,16 @@ GEM
34
35
  did-you-mean (0.1.1)
35
36
  levenshtein (>= 0.2.0)
36
37
  diff-lcs (1.5.1)
38
+ dorian-arguments (0.3.0)
39
+ activesupport
40
+ bigdecimal
41
+ dorian-to_struct
42
+ dorian-to_struct (0.5.0)
37
43
  drb (2.2.1)
38
44
  i18n (1.14.5)
39
45
  concurrent-ruby (~> 1.0)
40
46
  json (2.7.2)
41
- language-ruby (0.9.0)
47
+ language-ruby (0.9.2)
42
48
  zeitwerk
43
49
  language_server-protocol (3.17.0.3)
44
50
  levenshtein (0.2.2)
@@ -61,7 +67,7 @@ GEM
61
67
  rspec-mocks (~> 3.13.0)
62
68
  rspec-core (3.13.0)
63
69
  rspec-support (~> 3.13.0)
64
- rspec-expectations (3.13.1)
70
+ rspec-expectations (3.13.2)
65
71
  diff-lcs (>= 1.2.0, < 2.0)
66
72
  rspec-support (~> 3.13.0)
67
73
  rspec-mocks (3.13.1)
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.15.16
data/bin/code CHANGED
@@ -1,108 +1,71 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "optparse"
5
4
  require_relative "../lib/code-ruby"
6
-
7
- options = {
8
- timeout: 0,
9
- profile: false,
10
- profiler: "text",
11
- input: "",
12
- parse: false
13
- }
14
-
15
- argv =
16
- OptionParser
17
- .new do |opts|
18
- opts.banner = "Usage: code INPUT\n\n"
19
-
20
- opts.on("-v", "--version", "Version of Code") do |_input|
21
- puts Code::Version
22
- exit
23
- end
24
-
25
- opts.on(
26
- "-i INPUT",
27
- "--input INPUT",
28
- "Input in the Code language (String or File)"
29
- ) do |input|
30
- input = File.read(input) if File.exist?(input)
31
-
32
- options[:input] = input
33
- end
34
-
35
- opts.on("-p", "--parse", "Parser tree for input") do |parse|
36
- options[:parse] = parse
37
- end
38
-
39
- opts.on(
40
- "-t TIMEOUT",
41
- "--timeout TIMEOUT",
42
- "Set timeout in seconds"
43
- ) { |timeout| options[:timeout] = timeout.to_f }
44
-
45
- opts.on(
46
- "-z TIME_ZONE",
47
- "--time-zone TIME_ZONE",
48
- "Set time zone"
49
- ) { |time_zone| Time.zone = time_zone }
50
-
51
- opts.on("--profile", "Profile Ruby code") do |_timeout|
52
- require "ruby-prof"
53
- options[:profile] = true
54
- end
55
-
56
- opts.on(
57
- "--profiler TYPE",
58
- "Profiler output type (text (default) or html)"
59
- ) do |profiler|
60
- require "ruby-prof"
61
- options[:profile] = true
62
- options[:profiler] = profiler
63
- end
64
- end
65
- .parse!
66
-
67
- if options[:input].empty?
68
- options[:input] = argv.join(" ")
69
- options[:input] = File.read(options[:input]) if File.exist?(options[:input])
70
- end
71
-
72
- abort <<~HELP if options[:input].empty?
73
- Usage: code INPUT
74
-
75
- -v, --version Version of Code
76
- -i, --input INPUT Input in the Code language (String or File)
77
- -p, --parse Parser tree for input
78
- -t, --timeout TIMEOUT Set timeout in seconds
79
- --profile Profile Ruby code
80
- --profiler TYPE Profiler output type (text (default) or html)
81
- HELP
82
-
83
- RubyProf.start if options[:profile]
84
-
85
- if options[:parse]
86
- pp Code::Parser.parse(options[:input]).to_raw
5
+ require "dorian/arguments"
6
+
7
+ parsed =
8
+ Dorian::Arguments.parse(
9
+ input: {
10
+ type: :string,
11
+ alias: :i
12
+ },
13
+ parse: {
14
+ type: :boolean,
15
+ alias: :p
16
+ },
17
+ profile: :boolean,
18
+ profiler: :string,
19
+ timeout: {
20
+ type: :integer,
21
+ alias: :t
22
+ },
23
+ version: {
24
+ type: :boolean,
25
+ alias: :v
26
+ },
27
+ help: {
28
+ type: :boolean,
29
+ alias: :h
30
+ }
31
+ )
32
+
33
+ abort Code::Version.to_s if parsed.options.version
34
+ abort parsed.help if parsed.options.help
35
+
36
+ input = parsed.options.input.to_s
37
+ input = File.read(input) if File.exist?(input)
38
+ input += parsed.arguments.join(" ")
39
+ input += parsed.files.map { |file| File.read(file) }.join
40
+
41
+ abort parsed.help if input.empty?
42
+
43
+ profile = parsed.options.profile || parsed.options.profiler
44
+ require "ruby-prof" if profile
45
+
46
+ RubyProf.start if profile
47
+
48
+ if parsed.options.parse
49
+ pp Code::Parser.parse(input).to_raw
87
50
  else
88
- print Code.evaluate(
89
- options[:input],
90
- output: $stdout,
91
- error: $stderr,
92
- timeout: options[:timeout]
93
- )
51
+ print(
52
+ Code.evaluate(
53
+ input,
54
+ output: $stdout,
55
+ error: $stderr,
56
+ timeout: parsed.options.timeout
57
+ )
58
+ )
94
59
  end
95
60
 
96
- if options[:profile]
61
+ if profile
97
62
  result = RubyProf.stop
98
63
 
99
- if options[:profiler] == "text"
100
- printer = RubyProf::FlatPrinter.new(result)
101
- printer.print($stdout)
102
- elsif options[:profiler] == "html"
64
+ if parsed.options.profiler == "html"
103
65
  printer = RubyProf::GraphHtmlPrinter.new(result)
104
66
  printer.print($stdout)
105
67
  else
106
- abort "#{options[:profiler]} not recognized"
68
+ printer = RubyProf::FlatPrinter.new(result)
69
+ printer.print($stdout)
107
70
  end
108
71
  end
data/code-ruby.gemspec CHANGED
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "English"
4
- require_relative "lib/code/version"
5
-
6
3
  Gem::Specification.new do |s|
7
4
  s.name = "code-ruby"
8
- s.version = ::Code::Version
5
+ s.version = File.read("VERSION").strip
9
6
  s.summary = "a programming language for the internet"
10
7
  s.description = s.summary
11
8
  s.authors = ["Dorian Marié"]
@@ -22,4 +19,5 @@ Gem::Specification.new do |s|
22
19
  s.add_dependency "json"
23
20
  s.add_dependency "language-ruby"
24
21
  s.add_dependency "zeitwerk"
22
+ s.add_dependency "dorian-arguments"
25
23
  end
data/lib/code/version.rb CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  require_relative "../code"
4
4
 
5
- Code::Version = Gem::Version.new("0.15.15")
5
+ Code::Version =
6
+ Gem::Version.new(File.read(File.expand_path("../../../VERSION", __FILE__)))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.15
4
+ version: 0.15.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-18 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dorian-arguments
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: a programming language for the internet
98
112
  email: dorian@dorianmarie.fr
99
113
  executables:
@@ -114,6 +128,7 @@ files:
114
128
  - LICENSE
115
129
  - README.md
116
130
  - Rakefile
131
+ - VERSION
117
132
  - bin/bundle-audit
118
133
  - bin/bundler-audit
119
134
  - bin/code