ruby-next-parser 2.8.0.0 → 2.8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/parser/ruby-next/AST_FORMAT.md +27 -0
- data/lib/parser/ruby-next/builder.rb +37 -0
- data/lib/parser/ruby-next/meta.rb +1 -1
- data/lib/parser/ruby-next/parser_ext.rb +1 -0
- data/lib/parser/ruby-next/source/map/endless_definition.rb +23 -0
- data/lib/parser/ruby-next/version.rb +1 -1
- data/lib/parser/rubynext.rb +3744 -3670
- data/lib/parser/rubynext.y +60 -28
- 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: '04062694ac01bf4a4806421936bb2c451b09553f66e5b6fbac2c61f002c709eb'
|
4
|
+
data.tar.gz: 3f2a066a5d861f7d6ff4eb2fc0d155dcc3afd41b6856d1cc93e0ded30e461d72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50bba4f66c114063700b09494821be684e2ec2ac33c905f6c6b3c523b3729e8ae2ca6359146dbb21b873032809f8f7ddbcd56c6467fdf52c65821a69be6ac16b
|
7
|
+
data.tar.gz: ee09122563cccbf5c6cc70d169ff1b5f67910cc4dea305ac4743ad60c87632fb27f399ee4255459b5b0613df9b342a385b85800c30a5e7d7586d6f1f50a0b71b
|
@@ -12,3 +12,30 @@ Format:
|
|
12
12
|
^^^ selector
|
13
13
|
^^^^^^^^^ expression
|
14
14
|
~~~
|
15
|
+
|
16
|
+
### "Endless" method
|
17
|
+
|
18
|
+
Format:
|
19
|
+
|
20
|
+
~~~
|
21
|
+
(def_e :foo (args) (int 42))
|
22
|
+
"def foo() = 42"
|
23
|
+
~~~ keyword
|
24
|
+
~~~ name
|
25
|
+
^ assignment
|
26
|
+
~~~~~~~~~~~~~~ expression
|
27
|
+
~~~
|
28
|
+
|
29
|
+
|
30
|
+
### "Endless" singleton method
|
31
|
+
|
32
|
+
Format:
|
33
|
+
|
34
|
+
~~~
|
35
|
+
(defs_e (self) :foo (args) (int 42))
|
36
|
+
"def self.foo() = 42"
|
37
|
+
~~~ keyword
|
38
|
+
~~~ name
|
39
|
+
^ assignment
|
40
|
+
~~~~~~~~~~~~~~~~~~~ expression
|
41
|
+
~~~
|
@@ -10,5 +10,42 @@ module Parser
|
|
10
10
|
n(:meth_ref, [ receiver, value(selector_t).to_sym ],
|
11
11
|
send_map(receiver, dot_t, selector_t, nil, [], nil))
|
12
12
|
end
|
13
|
+
|
14
|
+
def def_endless_method(def_t, name_t, args,
|
15
|
+
assignment_t, body)
|
16
|
+
n(:def_e, [ value(name_t).to_sym, args, body ],
|
17
|
+
endless_definition_map(def_t, nil, name_t, assignment_t, body))
|
18
|
+
end
|
19
|
+
|
20
|
+
def def_endless_singleton(def_t, definee, dot_t,
|
21
|
+
name_t, args,
|
22
|
+
assignment_t, body)
|
23
|
+
return unless validate_definee(definee)
|
24
|
+
|
25
|
+
n(:defs_e, [ definee, value(name_t).to_sym, args, body ],
|
26
|
+
endless_definition_map(def_t, dot_t, name_t, assignment_t, body))
|
27
|
+
end
|
28
|
+
|
29
|
+
def endless_definition_map(keyword_t, operator_t, name_t, assignment_t, body_e)
|
30
|
+
body_l = body_e.loc.expression
|
31
|
+
|
32
|
+
Source::Map::EndlessDefinition.new(loc(keyword_t),
|
33
|
+
loc(operator_t), loc(name_t),
|
34
|
+
loc(assignment_t), body_l)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def validate_definee(definee)
|
40
|
+
case definee.type
|
41
|
+
when :int, :str, :dstr, :sym, :dsym,
|
42
|
+
:regexp, :array, :hash
|
43
|
+
|
44
|
+
diagnostic :error, :singleton_literal, nil, definee.loc.expression
|
45
|
+
false
|
46
|
+
else
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
13
50
|
end
|
14
51
|
end
|
@@ -5,7 +5,7 @@ require "parser/meta"
|
|
5
5
|
module Parser
|
6
6
|
# Parser metadata
|
7
7
|
module Meta
|
8
|
-
NEXT_NODE_TYPES = (NODE_TYPES + %i[meth_ref]).freeze
|
8
|
+
NEXT_NODE_TYPES = (NODE_TYPES + %i[meth_ref def_e defs_e]).freeze
|
9
9
|
|
10
10
|
remove_const(:NODE_TYPES)
|
11
11
|
const_set(:NODE_TYPES, NEXT_NODE_TYPES)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Parser
|
4
|
+
module Source
|
5
|
+
|
6
|
+
class Map::EndlessDefinition < Map
|
7
|
+
attr_reader :keyword
|
8
|
+
attr_reader :operator
|
9
|
+
attr_reader :name
|
10
|
+
attr_reader :assignment
|
11
|
+
|
12
|
+
def initialize(keyword_l, operator_l, name_l, assignment_l, body_l)
|
13
|
+
@keyword = keyword_l
|
14
|
+
@operator = operator_l
|
15
|
+
@name = name_l
|
16
|
+
@assignment = assignment_l
|
17
|
+
|
18
|
+
super(@keyword.join(body_l))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|