unparser 0.5.1 → 0.5.2
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/lib/unparser.rb +17 -0
- data/lib/unparser/validation.rb +21 -0
- data/lib/unparser/writer/send.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87327818d4054325cbf2017759e01a434fd80242e6319747ea97326770752e35
|
4
|
+
data.tar.gz: 8832d57dfb3f1a4e5755ad5c6737cea20ee4302a2b67d6ff2bb7a0a6cc71dc74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3e889b7a0130dbe3a77c32ae8d38cc0260b39b2785fba78e8f9033e29f1364699564dc6e2269b0c6a99a989d91f684a5dbbb78dc584c71b53ed05b102eaa9f7
|
7
|
+
data.tar.gz: d34a0f19d72855c962ceb9165d909133859ca38f055426b05b905266c9f9145655f1370219a70f2de1d04f2b4cd29cbd818c623b9a77a95385f70d457182ab02
|
data/lib/unparser.rb
CHANGED
@@ -50,6 +50,23 @@ module Unparser
|
|
50
50
|
end.content
|
51
51
|
end
|
52
52
|
|
53
|
+
# Unparse with validation
|
54
|
+
#
|
55
|
+
# @param [Parser::AST::Node, nil] node
|
56
|
+
# @param [Array] comment_array
|
57
|
+
#
|
58
|
+
# @return [Either<Validation,String>]
|
59
|
+
def self.unparse_validate(node, comment_array = [])
|
60
|
+
generated = unparse(node, comment_array)
|
61
|
+
validation = Validation.from_string(generated)
|
62
|
+
|
63
|
+
if validation.success?
|
64
|
+
MPrelude::Either::Right.new(generated)
|
65
|
+
else
|
66
|
+
MPrelude::Either::Left.new(validation)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
53
70
|
# Unparse capturing errors
|
54
71
|
#
|
55
72
|
# This is mostly useful for writing testing tools against unparser.
|
data/lib/unparser/validation.rb
CHANGED
@@ -71,6 +71,27 @@ module Unparser
|
|
71
71
|
)
|
72
72
|
end
|
73
73
|
|
74
|
+
# Create validator from node
|
75
|
+
#
|
76
|
+
# @param [Parser::AST::Node] original_node
|
77
|
+
#
|
78
|
+
# @return [Validator]
|
79
|
+
def self.from_node(original_node)
|
80
|
+
generated_source = Unparser.unparse_either(original_node)
|
81
|
+
|
82
|
+
generated_node = generated_source
|
83
|
+
.lmap(&method(:const_unit))
|
84
|
+
.bind(&Unparser.public_method(:parse_either))
|
85
|
+
|
86
|
+
new(
|
87
|
+
identification: '(string)',
|
88
|
+
original_source: generated_source,
|
89
|
+
original_node: MPrelude::Either::Right.new(original_node),
|
90
|
+
generated_source: generated_source,
|
91
|
+
generated_node: generated_node
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
74
95
|
# Create validator from file
|
75
96
|
#
|
76
97
|
# @param [Pathname] path
|
data/lib/unparser/writer/send.rb
CHANGED
@@ -45,7 +45,7 @@ module Unparser
|
|
45
45
|
def effective_writer_class
|
46
46
|
if details.binary_syntax_allowed?
|
47
47
|
Binary
|
48
|
-
elsif details.selector_unary_operator?
|
48
|
+
elsif details.selector_unary_operator? && n_send?(node)
|
49
49
|
Unary
|
50
50
|
elsif write_as_attribute_assignment?
|
51
51
|
AttributeAssignment
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unparser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Schirp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: abstract_type
|