koto 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 91a8cdd2c571cf39f6b9c6c41b8d90cf2f6730a9ae8d407dabf6647ba92706a9
4
- data.tar.gz: 41f6d7446084e509d3a88c8b9ca0d9b6097cb946dbf27a4effc5c514bb03c40d
3
+ metadata.gz: 7d3523f6b174d584c4dca1e677ce6f22a36b24003ccff90274a0e47ce5fd5b4a
4
+ data.tar.gz: 1e8ddf910b85751130d90f93c9c38ec194e6eda9de41faa436641de880c6b880
5
5
  SHA512:
6
- metadata.gz: c1738575d73950ab26c65caf2286477fbc6e990c57cbdbf28da9f6e1b4da4a28471c97841ee1b0f9345789aeac7b78936692718476173b46df7e7854ac8bcfed
7
- data.tar.gz: 58de4b49a75a1ab0805c81cf00ef7620c0465cecb3ad4731c48bef2001f56fffba011182b209099f90508ae5b73bfb2d248fbced1f984542ceeea6d6d8b4b11f
6
+ metadata.gz: c462b081af926271e010d897c753a7a4f4c9d8e46120ae6a7c19691ce6dcf4caa806da9d88c25e0d1038ceed12631ab2c546e8e1bac8c4d6a65102313ed7ce4d
7
+ data.tar.gz: 2db23913916901f444add896d7090eff12f419cdd428b4883ef1d82d7c7e76feab168b580013702e61ba698e9e9632b8514e29af83eb1c76ff815224444a401b
data/README.md CHANGED
@@ -22,33 +22,60 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Load *koto*.
25
+ Loading *koto*.
26
26
  ```ruby
27
27
  require 'koto'
28
28
  ```
29
- A code example with `Koto::Parser::AST::Processor` which extends `Parser::AST::Processor`.
29
+ Initializing the parser :
30
+ ```ruby
31
+ builder = Koto::Parser::Builders::Default.new
32
+ parser = Parser::CurrentRuby.new(builder)
33
+ ```
34
+ Setting a source buffer :
35
+ ```ruby
36
+ code = "class Context; private; def push; pass; end; end"
37
+ buffer = Parser::Source::Buffer.new('(string)', source: code)
38
+ ```
39
+ Processing data :
40
+ ```ruby
41
+ ast = parser.parse(buffer)
42
+
43
+ processor = Koto::Parser::AST::Processor.new
44
+ processor.process(ast)
45
+ ```
46
+ Getting contextual information :
47
+ ```ruby
48
+ context = processor.context
49
+ symbols = context.symbols
50
+
51
+ klass = symbols[:Context]
52
+ method = klass.symbols[:push]
53
+
54
+ p klass.access == :public
55
+ # => true
56
+ p klass.context.top_level?
57
+ # => true
58
+
59
+ p method.access == :private
60
+ # => true
61
+ p method.context.in_class?
62
+ # => true
63
+ ```
64
+ Processing nested names :
30
65
  ```ruby
31
- node = Parser::CurrentRuby.parse("Koto::Parser::AST::Processor::Resolver")
32
-
66
+ node = Parser::CurrentRuby.parse("Koto::Parser::AST::Processor::Resolver")
67
+
33
68
  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
-
69
+ # => s(:const,
70
+ # s(:const,
71
+ # s(:const,
72
+ # s(:const,
73
+ # s(:const, nil, :Koto), :Parser), :AST), :Processor), :Resolver)
74
+
75
+ processor = Koto::Parser::AST::Processor.new
76
+
48
77
  p processor.process(node)
49
- # (const
50
- # nil
51
- # :Koto::Parser::Processor::Resolver)
78
+ # => s(:const, nil, :"Koto::Parser::AST::Processor::Resolver")
52
79
  ```
53
80
 
54
81
  ## Development
@@ -4,6 +4,7 @@ require 'parser/current'
4
4
 
5
5
  module Koto
6
6
  require "koto/version"
7
+ require "koto/core_ext/object"
7
8
 
8
9
  module Parser
9
10
 
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Object
4
+ def deep_dup
5
+ copy = self.dup
6
+
7
+ copy.instance_variables.each do |attr|
8
+ value = instance_variable_get(attr).dup
9
+ copy.instance_variable_set attr, value
10
+ end
11
+
12
+ copy
13
+ end
14
+ end
@@ -24,12 +24,10 @@ module Koto
24
24
  end
25
25
 
26
26
  if (context = properties[:context])
27
- context = context.deep_dup if context.frozen?
28
27
  @context = context
29
28
  end
30
29
 
31
30
  if (symbols = properties[:symbols])
32
- symbols = symbols.dup if symbols.frozen?
33
31
  @symbols = symbols
34
32
  end
35
33
  end
@@ -6,7 +6,7 @@ module Koto
6
6
  class Processor < ::Parser::AST::Processor
7
7
 
8
8
  OBJECT_METHODS = [
9
- *(Object.methods - [:class])
9
+ *(Object.methods - [:class, :hash, :send])
10
10
  ]
11
11
 
12
12
  KERNEL_METHODS = [
@@ -20,21 +20,21 @@ module Koto
20
20
 
21
21
  def get_in(node)
22
22
  copy = self.deep_dup
23
- copy.get_in!(node)
23
+ copy.send :get_in!, node
24
24
  end
25
25
 
26
26
  def get_in!(node)
27
27
  @scopes << SymbolTable.new
28
28
  @stack << node
29
29
 
30
- self
30
+ self.freeze
31
31
  end
32
32
 
33
- protected :get_in!
33
+ private :get_in!
34
34
 
35
35
  def get_out
36
36
  copy = self.deep_dup
37
- copy.get_out!
37
+ copy.send :get_out!
38
38
  end
39
39
 
40
40
  def get_out!
@@ -46,24 +46,24 @@ module Koto
46
46
  @stack.pop
47
47
  end
48
48
 
49
- return symbol_table, self
49
+ return symbol_table, self.freeze
50
50
  end
51
51
 
52
- protected :get_out!
52
+ private :get_out!
53
53
 
54
54
  def save(node)
55
55
  copy = self.deep_dup
56
- copy.save! node
56
+ copy.send :save!, node
57
57
  end
58
58
 
59
59
  def save!(node)
60
60
  symbol_table = symbols.record(node)
61
61
  active_scope.update(symbol_table)
62
62
 
63
- self
63
+ self.freeze
64
64
  end
65
65
 
66
- protected :save!
66
+ private :save!
67
67
 
68
68
  def symbols
69
69
  active_scope.data
@@ -84,7 +84,7 @@ module Koto
84
84
  copy = self.dup
85
85
  copy.instance_variable_set(:@access, access)
86
86
 
87
- copy
87
+ copy.freeze
88
88
  end
89
89
 
90
90
  def top_level?
@@ -124,17 +124,6 @@ module Koto
124
124
  def in_dynamic_block?
125
125
  in_block? || in_lambda?
126
126
  end
127
-
128
- def deep_dup
129
- copy = self.dup
130
-
131
- copy.instance_variables.each do |attr|
132
- value = instance_variable_get(attr).dup
133
- copy.instance_variable_set attr, value
134
- end
135
-
136
- copy
137
- end
138
127
  end
139
128
  end
140
129
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Koto
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: koto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mansakondo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-06 00:00:00.000000000 Z
11
+ date: 2021-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -56,6 +56,7 @@ files:
56
56
  - bin/setup
57
57
  - koto.gemspec
58
58
  - lib/koto.rb
59
+ - lib/koto/core_ext/object.rb
59
60
  - lib/koto/parser/ast/node.rb
60
61
  - lib/koto/parser/ast/processor.rb
61
62
  - lib/koto/parser/ast/processor/context.rb