koto 0.2.0 → 0.2.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 +4 -4
- data/README.md +48 -21
- data/lib/koto.rb +1 -0
- data/lib/koto/core_ext/object.rb +14 -0
- data/lib/koto/parser/ast/node.rb +0 -2
- data/lib/koto/parser/ast/processor.rb +1 -1
- data/lib/koto/parser/ast/processor/context.rb +10 -21
- data/lib/koto/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d3523f6b174d584c4dca1e677ce6f22a36b24003ccff90274a0e47ce5fd5b4a
|
4
|
+
data.tar.gz: 1e8ddf910b85751130d90f93c9c38ec194e6eda9de41faa436641de880c6b880
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
25
|
+
Loading *koto*.
|
26
26
|
```ruby
|
27
27
|
require 'koto'
|
28
28
|
```
|
29
|
-
|
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
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
data/lib/koto.rb
CHANGED
data/lib/koto/parser/ast/node.rb
CHANGED
@@ -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
|
@@ -20,21 +20,21 @@ module Koto
|
|
20
20
|
|
21
21
|
def get_in(node)
|
22
22
|
copy = self.deep_dup
|
23
|
-
copy.get_in
|
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
|
-
|
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
|
-
|
52
|
+
private :get_out!
|
53
53
|
|
54
54
|
def save(node)
|
55
55
|
copy = self.deep_dup
|
56
|
-
copy.save
|
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
|
-
|
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
|
data/lib/koto/version.rb
CHANGED
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.
|
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-
|
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
|