dtr_core 0.2.9 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- 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 +9 -4
- 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: f4917a084a74054c729d66f2939d5c2a4166f08e38db858652e58a307119e1a8
|
4
|
+
data.tar.gz: 510ac11b521aca79f9d42eb877d4a717c34cb56b0b2adb967496cc248c03f6cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4b482496bf39d6cf3986a914ea1ee399a60f17213e20febc6de7625101b5e316e5d4aaa3f5a2d32aedc732106a9dadd495d861bb6413a3d107d90fff693f5bd
|
7
|
+
data.tar.gz: a6691c452e7056cdd017a91d9e8c4c794289b93e4361ffa0275d51b8ddc6a9a19fb2431aa67771e66d0659226b023d2236a95fe155285e549b07cef6240c1edb
|
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,11 +43,14 @@ 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
|
-
{ name: 'field', description: 'Reference an object field.', category: INSTRUCTION_CATEGORY_OBJECTS }
|
52
|
+
{ name: 'field', description: 'Reference an object field.', category: INSTRUCTION_CATEGORY_OBJECTS },
|
53
|
+
{ name: 'initialize_udt', description: 'Instantiate UDT object.', category: INSTRUCTION_CATEGORY_OBJECTS }
|
49
54
|
].freeze
|
50
55
|
|
51
56
|
# Supported Types for DTR.
|
@@ -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.1
|
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
|