koto 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 35f8638e8720898b69f308522cb589e37fe193cf29d7e2213ad57db496be35f0
4
+ data.tar.gz: bbf079b7f834fd6cc2893d7c20bfaa5797368f39f5caeb777de30346b2d6e8fd
5
+ SHA512:
6
+ metadata.gz: 102158ef6a82bb39e36a9ee2297e2fa09900ea620782e337baacadb78ff03569f1d787b1329d777640ff3d76b854ee291ec1e9386535a14d443b444ed2db10c7
7
+ data.tar.gz: 050b1c6608e82feb2030935bc8568c8a3f342ca81af36c822289a98a8c3bfc8e466a9a96fd2f1a00ab8e954cf5121e6ed763d967f5b5ea9f1d55f76e5567aecb
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.2
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.3
17
+ bundle install
18
+ bundle exec rake
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in koto.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ koto (0.1.0)
5
+ parser (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.1)
11
+ minitest (5.14.2)
12
+ parser (3.0.0.0)
13
+ ast (~> 2.4.1)
14
+ rake (13.0.3)
15
+
16
+ PLATFORMS
17
+ x86_64-linux
18
+
19
+ DEPENDENCIES
20
+ koto!
21
+ minitest (~> 5.0)
22
+ rake (~> 13.0)
23
+
24
+ BUNDLED WITH
25
+ 2.2.3
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 mansakondo
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.
@@ -0,0 +1,66 @@
1
+ # koto
2
+
3
+ *koto* is a Ruby symbol solver built on top of the [*parser*](https://github.com/whitequark/parser) gem. We it, we can resolves references like method calls, accesses to variables, inheritance relationships and more.
4
+
5
+ koto traverses the [AST](https://github.com/whitequark/ast) of a given source code, stores nodes in a [symbol table for each scopes](https://en.wikipedia.org/wiki/Parent_pointer_tree#Use_in_compilers) and uses it to resolve references.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'koto'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install koto
22
+
23
+ ## Usage
24
+
25
+ Load *koto*.
26
+ ```ruby
27
+ require 'koto'
28
+ ```
29
+ An code example with <code>Koto::Parser::AST::Processor</code> which extends <code>Parser::AST::Processor</code>.
30
+ ```ruby
31
+ node = Parser::CurrentRuby.parse("Koto::Parser::AST::Processor::Resolver")
32
+
33
+ p node
34
+ # (const
35
+ # (const
36
+ # (const
37
+ # (const
38
+ # (const
39
+ # nil
40
+ # :Koto)
41
+ # :Parser)
42
+ # :AST)
43
+ # :Processor)
44
+ # :Resolver)
45
+
46
+ processor = Koto::Parser::AST::Processor.new
47
+
48
+ p processor.process(node)
49
+ # (const
50
+ # nil
51
+ # :Koto::Parser::Processor::Resolver)
52
+ ```
53
+
54
+ ## Development
55
+
56
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
57
+
58
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/koto.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "koto"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -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,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/koto/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "koto"
7
+ spec.version = Koto::VERSION
8
+ spec.authors = ["mansakondo"]
9
+ spec.email = ["mansakondo22@gmail.com"]
10
+
11
+ spec.summary = "A Ruby symbol solver"
12
+ spec.homepage = "https://github.com/mansakondo/koto.git"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency 'parser', '~> 3.0'
29
+
30
+ # For more information and examples about making a new gem, checkout our
31
+ # guide at: https://bundler.io/guides/creating_gem.html
32
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'parser/current'
4
+
5
+ module Koto
6
+ require "koto/version"
7
+
8
+ module Parser
9
+ module AST
10
+ require 'koto/parser/ast/processor'
11
+ require 'koto/parser/ast/processor/name_processor'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koto
4
+ module Parser
5
+ module AST
6
+ class Processor < ::Parser::AST::Processor
7
+ attr_reader :name_processor
8
+
9
+ def initialize
10
+ @name_processor = NameProcessor.new
11
+ end
12
+
13
+ def on_const(node)
14
+ scope, name = *node
15
+
16
+ if scope
17
+ name = name_processor.process node
18
+ end
19
+
20
+ node.updated nil, [nil, name]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koto
4
+ module Parser
5
+ module AST
6
+ class NameProcessor < ::Parser::AST::Processor
7
+ def on_const(node)
8
+ scope, name = *node
9
+ return name unless scope
10
+
11
+ top_level = ::Parser::AST::Node.new(:cbase)
12
+
13
+ if scope == top_level
14
+ name = "::#{name}"
15
+ else
16
+ scope = process scope
17
+ name = "#{scope}::#{name}"
18
+ end
19
+
20
+ name.to_sym
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koto
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koto
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mansakondo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description:
28
+ email:
29
+ - mansakondo22@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".github/workflows/main.yml"
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - bin/console
42
+ - bin/setup
43
+ - koto.gemspec
44
+ - lib/koto.rb
45
+ - lib/koto/parser/ast/processor.rb
46
+ - lib/koto/parser/ast/processor/name_processor.rb
47
+ - lib/koto/version.rb
48
+ homepage: https://github.com/mansakondo/koto.git
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/mansakondo/koto.git
53
+ source_code_uri: https://github.com/mansakondo/koto.git
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.1.4
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: A Ruby symbol solver
73
+ test_files: []