dtr_core 0.2.9 → 0.3.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/common.rb +2 -2
- data/lib/dtr_core/contract.rb +7 -5
- data/lib/dtr_core/parser.rb +16 -0
- data/lib/dtr_core/supported_attributes.rb +7 -3
- data/lib/dtr_core/user_defined_type.rb +49 -0
- data/lib/dtr_core.rb +2 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71e3bee98b2e2a2d771fe881f059b1a7a0546bfcedbb26bf299d6b438881ea22
|
4
|
+
data.tar.gz: 6ca9e2267461705e4cfec44be4d18100c1bbbc9d557d81f143fe93974eb6b35a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87a726b517b10ee0abbfe9e30f9f5361b1da910b43fada3f32733640ddc9d58980c5f00d136c27b3e078a9611dae5181289aae082ee5da78dcf0c25766cf9f92
|
7
|
+
data.tar.gz: 918302834a7156779d967ae6453755eea5d0bb59633f174ed254ec071c025e57dd674ca099805390bf61598952bee67e026dc5108f242ef6f42d1d7d2622c3fa
|
data/lib/dtr_core/common.rb
CHANGED
@@ -11,8 +11,8 @@ module DTRCore
|
|
11
11
|
some_list&.split("\n")&.map(&:strip)&.select { |x| x.length.positive? }
|
12
12
|
end
|
13
13
|
|
14
|
-
def first_match_for_content(
|
15
|
-
content.match(
|
14
|
+
def first_match_for_content(pattern)
|
15
|
+
content.match(pattern)&.captures&.first
|
16
16
|
end
|
17
17
|
|
18
18
|
def clean_name(definition)
|
data/lib/dtr_core/contract.rb
CHANGED
@@ -3,30 +3,32 @@
|
|
3
3
|
module DTRCore
|
4
4
|
# Represents a contract in a DTR file.
|
5
5
|
class Contract
|
6
|
-
attr_reader :functions, :name, :state
|
6
|
+
attr_reader :functions, :name, :state, :user_defined_types
|
7
7
|
|
8
|
-
def initialize(name, state, functions)
|
8
|
+
def initialize(name, state, functions, user_defined_types)
|
9
9
|
@name = name
|
10
10
|
@state = state
|
11
11
|
@functions = functions
|
12
|
+
@user_defined_types = user_defined_types
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.from_dtr(filepath)
|
15
16
|
parser = DTRCore::Parser.new(filepath)
|
16
17
|
|
17
|
-
new(parser.name_section, parser.state_section, parser.function_section)
|
18
|
+
new(parser.name_section, parser.state_section, parser.function_section, parser.user_defined_types_section)
|
18
19
|
end
|
19
20
|
|
20
21
|
def self.from_dtr_raw(content)
|
21
22
|
parser = DTRCore::Parser.new('', content:)
|
22
23
|
|
23
|
-
new(parser.name_section, parser.state_section, parser.function_section)
|
24
|
+
new(parser.name_section, parser.state_section, parser.function_section, parser.user_defined_types_section)
|
24
25
|
end
|
25
26
|
|
26
27
|
def ==(other)
|
27
28
|
name == other.name &&
|
28
29
|
state == other.state &&
|
29
|
-
functions == other.functions
|
30
|
+
functions == other.functions &&
|
31
|
+
user_defined_types == other.user_defined_types
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
data/lib/dtr_core/parser.rb
CHANGED
@@ -63,5 +63,21 @@ module DTRCore
|
|
63
63
|
|
64
64
|
@function_section ||= function_definitions
|
65
65
|
end
|
66
|
+
|
67
|
+
def user_defined_types_section
|
68
|
+
return @user_defined_types if @user_defined_types
|
69
|
+
|
70
|
+
user_defined_types_regex = /\[User Defined Types\]:([\s\S]*?)\s*:\[User Defined Types\]/
|
71
|
+
user_defined_types_section_parsed_out = first_match_for_content(user_defined_types_regex)
|
72
|
+
|
73
|
+
return nil if user_defined_types_section_parsed_out.nil?
|
74
|
+
|
75
|
+
user_defined_types = user_defined_types_section_parsed_out
|
76
|
+
.split(/\n\s*\*\s*\(/).map { |x| "(#{x.strip}" }
|
77
|
+
.filter { |x| x.length > 1 }
|
78
|
+
.map { |definition| DTRCore::UserDefinedType.from_definition(definition) }
|
79
|
+
|
80
|
+
@user_defined_types_section ||= user_defined_types
|
81
|
+
end
|
66
82
|
end
|
67
83
|
end
|
@@ -32,7 +32,9 @@ module DTRCore
|
|
32
32
|
{ name: 'save_state', description: 'Save a value to the state.', category: INSTRUCTION_CATEGORY_STATE },
|
33
33
|
# untyped operations
|
34
34
|
{ name: 'add', description: 'Add two things of unknown types together.', category: INSTRUCTION_CATEGORY_UNTYPED },
|
35
|
-
{ name: 'add_and_assign',
|
35
|
+
{ name: 'add_and_assign',
|
36
|
+
description: 'Add two things of unknown types together and then assign to the first one.',
|
37
|
+
category: INSTRUCTION_CATEGORY_UNTYPED },
|
36
38
|
# numeric operations
|
37
39
|
{ name: 'add_numbers', description: 'Add two numbers.', category: INSTRUCTION_CATEGORY_NUMERIC },
|
38
40
|
{ name: 'subtract_numbers', description: 'Subtract two numbers.', category: INSTRUCTION_CATEGORY_NUMERIC },
|
@@ -41,9 +43,11 @@ module DTRCore
|
|
41
43
|
# string operations
|
42
44
|
{ name: 'add_strings', description: 'Concatenate two strings.', category: INSTRUCTION_CATEGORY_STRING },
|
43
45
|
# environment operations
|
44
|
-
{ name: 'contract_address', description: 'Get the contract address.',
|
46
|
+
{ name: 'contract_address', description: 'Get the contract address.',
|
47
|
+
category: INSTRUCTION_CATEGORY_ENVIRONMENT },
|
45
48
|
# method operations
|
46
|
-
{ name: 'evaluate', description: 'Evaluate a method. Method name is the first input and arguments follow',
|
49
|
+
{ name: 'evaluate', description: 'Evaluate a method. Method name is the first input and arguments follow',
|
50
|
+
category: INSTRUCTION_CATEGORY_METHODS },
|
47
51
|
# object operations
|
48
52
|
{ name: 'field', description: 'Reference an object field.', category: INSTRUCTION_CATEGORY_OBJECTS }
|
49
53
|
].freeze
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dtr_core/common'
|
4
|
+
|
5
|
+
module DTRCore
|
6
|
+
# Represents a state in a DTR file.
|
7
|
+
class UserDefinedType
|
8
|
+
include ::DTRCore::Common
|
9
|
+
|
10
|
+
attr_reader :attributes, :name
|
11
|
+
|
12
|
+
def initialize(name, attributes)
|
13
|
+
@name = name
|
14
|
+
@attributes = attributes
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_definition(definition)
|
18
|
+
name = capture_name(definition)
|
19
|
+
attributes = capture_attributes(definition)
|
20
|
+
|
21
|
+
new(name, attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.capture_attributes(definition)
|
25
|
+
captured_definitions = definition.match(/\{(.+?)\}/m)&.captures&.first
|
26
|
+
|
27
|
+
transform_attributes(captured_definitions.split("\n"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.transform_attributes(capture_attribute_definition)
|
31
|
+
capture_attribute_definition&.map { |x| x.split(':') }
|
32
|
+
&.filter { |x| x.length > 1 }
|
33
|
+
&.map { |x| { name: x[0].strip, type: x[1].strip } }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.capture_name(definition)
|
37
|
+
definition.match(/\((\w+)\)/)&.captures&.first
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"#{name} { #{attributes.map { |x| "#{x[:name]}: #{x[:type]}" }.join("\n")} }"
|
42
|
+
end
|
43
|
+
|
44
|
+
def ==(other)
|
45
|
+
name == other.name &&
|
46
|
+
attributes == other.attributes
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/dtr_core.rb
CHANGED
@@ -7,6 +7,7 @@ module DTRCore
|
|
7
7
|
autoload :Number, 'dtr_core/number'
|
8
8
|
autoload :Parser, 'dtr_core/parser'
|
9
9
|
autoload :State, 'dtr_core/state'
|
10
|
-
autoload :TypeValidator, 'dtr_core/type_validator'
|
11
10
|
autoload :SupportedAttributes, 'dtr_core/supported_attributes'
|
11
|
+
autoload :TypeValidator, 'dtr_core/type_validator'
|
12
|
+
autoload :UserDefinedType, 'dtr_core/user_defined_type'
|
12
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtr_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Durst
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/dtr_core/state.rb
|
28
28
|
- lib/dtr_core/supported_attributes.rb
|
29
29
|
- lib/dtr_core/type_validator.rb
|
30
|
+
- lib/dtr_core/user_defined_type.rb
|
30
31
|
homepage: https://spaced-out-thoughts-dev-foundation.github.io/digicus/
|
31
32
|
licenses:
|
32
33
|
- MIT
|