dtr_core 0.8.1 → 0.10.0
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/dtr_core/contract.rb +16 -8
- data/lib/dtr_core/function.rb +3 -2
- data/lib/dtr_core/instruction.rb +10 -6
- data/lib/dtr_core/parser.rb +11 -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: ad7236ff8c846c7126d0d8e53f3d7cd5d6635eeefbca857dafdf22e85473cbe6
|
4
|
+
data.tar.gz: d8741a66894615c02d59be5ba8884f165acdcfdb045c2243c07c57c3116cb699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83a20837017ec8a60ae948918f6b1947332516248bac6f805bdfc12b7b2a5636d5f01157739c81167113a873218da6cf55b22c297e1903718c9913b29322f2f7
|
7
|
+
data.tar.gz: 42b2bd3b5ef207d88fe3a955a9358ea54270979115df12e10d2318d6d230c80e8d858979d9d91df91bd2158153dd93f0d2e8efd15e0e27c4f261dee6432d660d
|
data/lib/dtr_core/contract.rb
CHANGED
@@ -3,28 +3,29 @@
|
|
3
3
|
module DTRCore
|
4
4
|
# Represents a contract in a DTR file.
|
5
5
|
class Contract
|
6
|
-
attr_reader :helpers, :interface, :name, :state, :user_defined_types
|
6
|
+
attr_reader :helpers, :interface, :name, :state, :user_defined_types, :non_translatables
|
7
7
|
|
8
|
-
def initialize(name, state, interface, user_defined_types, helpers)
|
8
|
+
def initialize(name, state, interface, user_defined_types, helpers, non_translatables)
|
9
9
|
@name = name
|
10
10
|
@state = state
|
11
11
|
@interface = interface
|
12
12
|
@user_defined_types = user_defined_types
|
13
13
|
@helpers = helpers
|
14
|
+
@non_translatables = non_translatables
|
14
15
|
end
|
15
16
|
|
16
17
|
def self.from_dtr(filepath)
|
17
18
|
parser = DTRCore::Parser.new(filepath)
|
18
19
|
|
19
20
|
new(parser.name_section, parser.state_section, parser.interface_section, parser.user_defined_types_section,
|
20
|
-
parser.helpers_section)
|
21
|
+
parser.helpers_section, parser.non_translatable_section)
|
21
22
|
end
|
22
23
|
|
23
24
|
def self.from_dtr_raw(content)
|
24
25
|
parser = DTRCore::Parser.new('', content:)
|
25
26
|
|
26
27
|
new(parser.name_section, parser.state_section, parser.interface_section, parser.user_defined_types_section,
|
27
|
-
parser.helpers_section)
|
28
|
+
parser.helpers_section, parser.non_translatable_section)
|
28
29
|
end
|
29
30
|
|
30
31
|
def ==(other)
|
@@ -42,6 +43,7 @@ module DTRCore
|
|
42
43
|
return_string += interface_to_s
|
43
44
|
return_string += user_defined_types_to_s
|
44
45
|
return_string += helpers_to_s
|
46
|
+
return_string += non_translatables_to_s
|
45
47
|
|
46
48
|
return_string
|
47
49
|
end
|
@@ -53,27 +55,33 @@ module DTRCore
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def state_to_s
|
56
|
-
return '' if @state.nil?
|
58
|
+
return '' if @state.nil? || @state.empty?
|
57
59
|
|
58
60
|
"[State]:\n#{@state&.map(&:to_s)&.join("\n")}\n:[State]\n"
|
59
61
|
end
|
60
62
|
|
61
63
|
def interface_to_s
|
62
|
-
return '' if @
|
64
|
+
return '' if @interface.nil? || @interface.empty?
|
63
65
|
|
64
66
|
"[Interface]:\n#{@interface&.map(&:to_s)&.join("\n")}\n:[Interface]\n"
|
65
67
|
end
|
66
68
|
|
67
69
|
def user_defined_types_to_s
|
68
|
-
return '' if @user_defined_types.nil?
|
70
|
+
return '' if @user_defined_types.nil? || @user_defined_types.empty?
|
69
71
|
|
70
72
|
"[User Defined Types]:\n#{@user_defined_types&.map(&:to_s)&.join("\n")}\n:[User Defined Types]\n"
|
71
73
|
end
|
72
74
|
|
73
75
|
def helpers_to_s
|
74
|
-
return '' if @helpers.nil?
|
76
|
+
return '' if @helpers.nil? || @helpers.empty?
|
75
77
|
|
76
78
|
"[Helpers]:\n#{@helpers&.map(&:to_s)&.join("\n")}\n:[Helpers]\n"
|
77
79
|
end
|
80
|
+
|
81
|
+
def non_translatables_to_s
|
82
|
+
return '' if @non_translatables.nil? || @non_translatables.empty?
|
83
|
+
|
84
|
+
"[NonTranslatable]:\n#{@non_translatables}\n:[NonTranslatable]"
|
85
|
+
end
|
78
86
|
end
|
79
87
|
end
|
data/lib/dtr_core/function.rb
CHANGED
@@ -97,8 +97,9 @@ module DTRCore
|
|
97
97
|
instruction = DTRCore::Instruction.new(
|
98
98
|
instruction[/instruction:\s*(?<all>[^\s,]+)/, 1],
|
99
99
|
parse_function_instruction_input(instruction),
|
100
|
-
instruction[/\s*assign:\s
|
101
|
-
instruction[/\s*scope:\s*(?<all>[^\s\,]+)/, 1].to_i || 0
|
100
|
+
instruction[/\s*assign:\s*\[?(?<all>[^\s\,\]]+)\]?/, 1],
|
101
|
+
instruction[/\s*scope:\s*(?<all>[^\s\,]+)/, 1].to_i || 0,
|
102
|
+
instruction[/\sid:\s*(?<all>[^\s,]+)/, 1].to_i || 0
|
102
103
|
)
|
103
104
|
|
104
105
|
raise "Invalid instruction: #{instruction}" unless instruction.valid?
|
data/lib/dtr_core/instruction.rb
CHANGED
@@ -3,26 +3,29 @@
|
|
3
3
|
module DTRCore
|
4
4
|
# Instruction class
|
5
5
|
class Instruction
|
6
|
-
attr_reader :instruction, :inputs, :assign, :scope
|
6
|
+
attr_reader :instruction, :inputs, :assign, :scope, :id
|
7
7
|
|
8
|
-
def initialize(instruction, inputs, assign, scope)
|
8
|
+
def initialize(instruction, inputs, assign, scope, id)
|
9
9
|
@instruction = instruction
|
10
10
|
@inputs = inputs
|
11
11
|
@assign = assign
|
12
12
|
@scope = scope
|
13
|
+
@id = id
|
13
14
|
end
|
14
15
|
|
15
16
|
def ==(other)
|
16
17
|
instruction == other.instruction &&
|
17
18
|
inputs == other.inputs &&
|
18
19
|
assign == other.assign &&
|
19
|
-
scope == other.scope
|
20
|
+
scope == other.scope &&
|
21
|
+
id == other.id
|
20
22
|
end
|
21
23
|
|
22
24
|
def to_s
|
23
|
-
|
25
|
+
assignment = @assign.nil? ? '' : "assign: #{@assign}, "
|
26
|
+
"{ id: #{id}, instruction: #{instruction}, " \
|
24
27
|
"input: (#{inputs&.join(', ')}), " \
|
25
|
-
"
|
28
|
+
"#{assignment}scope: #{scope} }"
|
26
29
|
end
|
27
30
|
|
28
31
|
def to_json(*_args)
|
@@ -30,7 +33,8 @@ module DTRCore
|
|
30
33
|
instruction:,
|
31
34
|
inputs:,
|
32
35
|
assign:,
|
33
|
-
scope
|
36
|
+
scope:,
|
37
|
+
id:
|
34
38
|
}.to_json
|
35
39
|
end
|
36
40
|
|
data/lib/dtr_core/parser.rb
CHANGED
@@ -77,7 +77,7 @@ module DTRCore
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def helpers_section
|
80
|
-
return @
|
80
|
+
return @helpers_section if @helpers_section
|
81
81
|
|
82
82
|
helpers_section = capture_section(/\[Helpers\]:(?<all>.*)\s*:\[Helpers\]/m)
|
83
83
|
|
@@ -91,5 +91,15 @@ module DTRCore
|
|
91
91
|
|
92
92
|
@helpers_section ||= function_definitions
|
93
93
|
end
|
94
|
+
|
95
|
+
def non_translatable_section
|
96
|
+
return @non_translatable_section if @non_translatable_section
|
97
|
+
|
98
|
+
non_translatable_section = capture_section(/\[NonTranslatable\]:(?<all>.*)\s*:\[NonTranslatable\]/m)
|
99
|
+
|
100
|
+
return nil if non_translatable_section.nil?
|
101
|
+
|
102
|
+
@non_translatable_section = non_translatable_section
|
103
|
+
end
|
94
104
|
end
|
95
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtr_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Durst
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Core smart contract intermediate language (Digicus Textual Representation)
|
14
14
|
parser.
|