iro 0.0.1

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
+ SHA256:
3
+ metadata.gz: fd440ced37fe11f8b7eb3ff318df09030028a2b076b03626446e0fa7afbe07d7
4
+ data.tar.gz: 76360b0971ccd4153774950ccaa05d8d05fb778a0657f38dde689ad7aeb94685
5
+ SHA512:
6
+ metadata.gz: 0fc95f70e32c968226f33bdb3fb3a70027c2f3a5cc65227a0c1a5abe0812c945e23c9c92d1d3dc0719bb128e90bd888dfb6f78771ca975265457619855dfe91d
7
+ data.tar.gz: fa6fad939da3bba78508f3d5a6bbde612dfbbde7310101bf004f20b146c9549db737a4fc0e0bc5062689dfdfff20cbc31ed9ab28ab34099f9e065fdc1dde9894
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /Gemfile.lock
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 iro.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Iro
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/iro`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'iro'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install iro
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/iro.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ task :default => :test
4
+
5
+ Rake::TestTask.new do |test|
6
+ test.libs << 'test'
7
+ test.test_files = Dir['test/**/*_test.rb']
8
+ test.verbose = true
9
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "iro"
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/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
data/iro.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "iro/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "iro"
7
+ spec.version = Iro::VERSION
8
+ spec.authors = ["Masataka Pocke Kuwabara"]
9
+ spec.email = ["kuwabara@pocke.me"]
10
+
11
+ spec.summary = %q{}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/pocke/iro"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = '>= 2.3.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency 'minitest', '~> 5.11'
27
+ end
@@ -0,0 +1,61 @@
1
+ module Iro
2
+ module RipperWrapper
3
+ refine Array do
4
+ def type
5
+ self.first
6
+ end
7
+
8
+ def children
9
+ [].tap do |res|
10
+ self[1..-1].each do |child|
11
+ if child.is_a?(Array)
12
+ if child.node?
13
+ res << child
14
+ else
15
+ res.concat(child)
16
+ end
17
+ else
18
+ res << child
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def content
25
+ self[1]
26
+ end
27
+
28
+ def position
29
+ self[2]
30
+ end
31
+
32
+ def node?
33
+ self.first.is_a?(Symbol)
34
+ end
35
+
36
+ def parser_event?
37
+ type !~ /\A@/
38
+ end
39
+
40
+ def scanner_event?
41
+ type =~ /\A@/
42
+ end
43
+
44
+ Ripper::SCANNER_EVENTS.each do |e|
45
+ eval <<~RUBY
46
+ def #{e}_type?
47
+ type == #{:"@#{e}".inspect}
48
+ end
49
+ RUBY
50
+ end
51
+
52
+ Ripper::PARSER_EVENTS.each do |e|
53
+ eval <<~RUBY
54
+ def #{e}_type?
55
+ type == #{e.inspect}
56
+ end
57
+ RUBY
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,78 @@
1
+ module Iro
2
+ module Ruby
3
+ class Parser < Ripper::SexpBuilderPP
4
+ using RipperWrapper
5
+
6
+ EVENT_NAME_TO_HIGHLIGT_NAME = {
7
+ tstring_content: 'String',
8
+ CHAR: 'Character',
9
+ int: 'Number',
10
+ float: 'Float',
11
+
12
+ kw: 'Keyword',
13
+ comment: 'Comment',
14
+ embdoc: 'Comment',
15
+ embdoc_beg: 'Comment',
16
+ embdoc_end: 'Comment',
17
+ const: 'Type',
18
+
19
+ regexp_beg: 'Delimiter',
20
+ regexp_end: 'Delimiter',
21
+ heredoc_beg: 'Delimiter',
22
+ heredoc_end: 'Delimiter',
23
+ tstring_beg: 'Delimiter',
24
+ tstring_end: 'Delimiter',
25
+ embexpr_beg: 'Delimiter',
26
+ embexpr_end: 'Delimiter',
27
+ }.freeze
28
+
29
+ attr_reader :tokens
30
+
31
+ def initialize(*)
32
+ super
33
+ @tokens = {}
34
+ end
35
+
36
+ def register_token(group, token)
37
+ @tokens[group] ||= []
38
+ @tokens[group] << token
39
+ end
40
+
41
+ EVENT_NAME_TO_HIGHLIGT_NAME.each do |tok_type, group|
42
+ eval <<~RUBY
43
+ def on_#{tok_type}(str)
44
+ str.split("\\n").each.with_index do |s, idx|
45
+ register_token #{group.inspect}, [
46
+ lineno + idx,
47
+ idx == 0 ? column+1 : 1,
48
+ s.size]
49
+ end
50
+ super
51
+ end
52
+ RUBY
53
+ end
54
+
55
+ def traverse(node)
56
+ return if node.scanner_event?
57
+
58
+ if node.var_ref_type?
59
+ ident = node.children.first
60
+ if ident.ident_type?
61
+ pos = ident.position
62
+ register_token 'rubyLocalVariable', [pos[0], pos[1]+1, ident.content.size]
63
+ end
64
+ end
65
+ node.children.each do |child|
66
+ traverse(child) if child.is_a?(Array)
67
+ end
68
+ end
69
+
70
+ def self.tokens(source)
71
+ parser = self.new(source)
72
+ sexp = parser.parse
73
+ parser.traverse(sexp) unless parser.error?
74
+ parser.tokens
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Iro
2
+ VERSION = "0.0.1"
3
+ end
data/lib/iro.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'ripper'
2
+
3
+ require "iro/version"
4
+ require 'iro/ripper_wrapper'
5
+ require 'iro/ruby/parser'
6
+
7
+ module Iro
8
+ # Your code goes here...
9
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iro
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masataka Pocke Kuwabara
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-09 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.11'
55
+ description: ''
56
+ email:
57
+ - kuwabara@pocke.me
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - iro.gemspec
69
+ - lib/iro.rb
70
+ - lib/iro/ripper_wrapper.rb
71
+ - lib/iro/ruby/parser.rb
72
+ - lib/iro/version.rb
73
+ homepage: https://github.com/pocke/iro
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.3.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.7.3
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: ''
96
+ test_files: []