rubie 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9db5c2e1eddedc311a983830babab39f88ec7512
4
+ data.tar.gz: 025ad7bf3a051b3e5ee0310829069ccd345ac9d8
5
+ SHA512:
6
+ metadata.gz: '081bb3764b235a74c2ea493e75d04d2dd4d916606d172e29bc45dac35a38e6eceadee49d22f5fd2f347c4b339fee0257dc9ceac687412969e7aa357bf0996620'
7
+ data.tar.gz: a7657cd7eab27178d32a93dd0294b47af7c234b43360d91f3ceaa692e20976d120288dc641e94eecbab22dee64dab7ca5050eacfe78763eadca68c824eceec4a
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sasurai.usagi3@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rubie.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 宇山 拓夢
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Rubie
2
+ 彼女のいないRubyistのためのgem
3
+
4
+ ## Usage
5
+
6
+ Execute `gem install rubie` and `rubie`
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubie"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rubie ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubie'
3
+
4
+ Rubie::Interpreter.exec
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ module Rubie
2
+ class Interpreter
3
+ def self.exec
4
+ world = Object.new.__binding__
5
+
6
+ puts 'おはよう、今日も私と一緒に遊んでくれるんだねっ!嬉しい!'
7
+ while true
8
+ print 'rubie > '
9
+ command = gets
10
+ if command.nil?
11
+ puts "\nまたねー"
12
+ return '遊んでくれてありがとう'
13
+ end
14
+ parser = Rubie::Ripper.new(command)
15
+
16
+ begin
17
+ parser.parse
18
+ ret = eval(command, world)
19
+ puts parser.detail
20
+ puts "=> #{ret}"
21
+ rescue Rubie::ParseErrorException => e
22
+ puts "文法エラーみたい・・・ 「#{e.message}」だって"
23
+ rescue ArgumentError => e
24
+ puts '引数違うよー'
25
+ rescue NoMethodError => e
26
+ puts "#{e.receiver}に「#{e.name}」って名前のメソッドが定義されてないってー!"
27
+ rescue NameError => e
28
+ puts "#{e.receiver}に「#{e.name}」って名前の変数かメソッドが定義されてないってー!"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Rubie
2
+ class ParseErrorException < ::StandardError
3
+ attr_reader :message
4
+
5
+ def initialize(message)
6
+ @message = message
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,69 @@
1
+ require 'ripper'
2
+
3
+ module Rubie
4
+ class Ripper < ::Ripper
5
+ %i(compile_error on_parse_error warn warning).each do |name|
6
+ define_method name do |*args|
7
+ raise Rubie::ParseErrorException.new(args.join)
8
+ end
9
+ end
10
+
11
+ def initialize(command)
12
+ super(command)
13
+
14
+ @command = command
15
+ end
16
+
17
+ def detail
18
+ exp = Ripper.sexp(@command)
19
+ dig(exp)
20
+ end
21
+
22
+ private
23
+ def dig(exp)
24
+ puts exp.inspect
25
+ case exp[0]
26
+ when :program
27
+ "このプログラムは#{exp[1].map { |e| dig(e) }.join}いるんだね!"
28
+ when :assign
29
+ "#{dig(exp[1])}に#{dig(exp[2])}を代入して"
30
+ when :var_field
31
+ "変数#{dig(exp[1])}"
32
+ when :method_add_arg
33
+ "#{dig(exp[1])}#{dig(exp[2])}を引数として"
34
+ when :call
35
+ "#{dig(exp[1])}の#{dig(exp[3])}メソッドを呼んで"
36
+ when :binary
37
+ "#{dig(exp[1])}と#{dig(exp[3])}に対して#{get_binary_method(exp[2])}をして"
38
+ when :vcall
39
+ dig(exp[1])
40
+ when :arg_paren
41
+ dig(exp[1])
42
+ when :args_add_block
43
+ exp[1].map { |e| dig(e) }.join
44
+ when :@int
45
+ exp[1].to_s
46
+ when :@float
47
+ exp[1].to_s
48
+ when :@ident
49
+ exp[1].to_s
50
+ end
51
+ end
52
+
53
+ def get_binary_method(m)
54
+ puts m
55
+ case m
56
+ when :+
57
+ '加算'
58
+ when :-
59
+ '減算'
60
+ when :*
61
+ '乗算'
62
+ when :/
63
+ '除算'
64
+ when :%
65
+ '剰余の算出'
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Rubie
2
+ VERSION = "0.1.0"
3
+ end
data/lib/rubie.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'rubie/version'
2
+ require 'rubie/parse_error_exception'
3
+ require 'rubie/ripper'
4
+ require 'rubie/interpreter'
5
+
6
+ module Rubie
7
+ # Your code goes here...
8
+ end
data/rubie.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubie/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rubie'
8
+ spec.version = Rubie::VERSION
9
+ spec.authors = ['Takumu Uyama']
10
+ spec.email = ['sasurai.usagi3@gmail.com']
11
+
12
+ spec.summary = '彼女のいないRubyistのためのgem'
13
+ spec.description = '彼女のいないRubyiesのためのgem。対話式インタプリタです。'
14
+ spec.homepage = 'https://github.com/sasurai-usagi3/rubie'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.15'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'pry'
28
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takumu Uyama
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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
+ description: 彼女のいないRubyiesのためのgem。対話式インタプリタです。
70
+ email:
71
+ - sasurai.usagi3@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/rubie
86
+ - bin/setup
87
+ - lib/rubie.rb
88
+ - lib/rubie/interpreter.rb
89
+ - lib/rubie/parse_error_exception.rb
90
+ - lib/rubie/ripper.rb
91
+ - lib/rubie/version.rb
92
+ - rubie.gemspec
93
+ homepage: https://github.com/sasurai-usagi3/rubie
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.6.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: 彼女のいないRubyistのためのgem
117
+ test_files: []