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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67b02827614947fae7b084aec80c3844210811a765d5743b78e18a7a6ed31e2f
4
- data.tar.gz: fd41bf27d87220aba965f3024998719f4b10ec8b372321af5039809c2b72c590
3
+ metadata.gz: '04062694ac01bf4a4806421936bb2c451b09553f66e5b6fbac2c61f002c709eb'
4
+ data.tar.gz: 3f2a066a5d861f7d6ff4eb2fc0d155dcc3afd41b6856d1cc93e0ded30e461d72
5
5
  SHA512:
6
- metadata.gz: d56dfa6185fb8ee23a665b0a3572777e4f733ababbc5a156e90b7c1259e76bd463a8c6ae6caabdfcdd516df10e363927231fd3f3cf27f5a346731aec019e00ec
7
- data.tar.gz: 483258f27af4f4dd4be3ab2d215bc7a866faf72d9795ac128df9229abe28512431579d097f92430cc53b2c0c89caf7762d26a7470cc17b30fcbc3041d41a41fe
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)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "lexer"
4
4
  require_relative "builder"
5
+ require_relative "source/map/endless_definition"
5
6
 
6
7
  module Parser
7
8
  # Patch the base parser class to use custom builder and lexer
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Parser
4
- NEXT_VERSION = "2.8.0.0"
4
+ NEXT_VERSION = "2.8.0.1"
5
5
  end