dtr_to_rust 0.0.1 → 0.0.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/generator.rb +12 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae0cdc8b9f770247678aedd34ee2b4696b3be0eb0260d7e161a71b8d8fd99b02
|
4
|
+
data.tar.gz: 11726ca922f86d4a190d43adccb6b3b071d656a85369a982437cb5ebd92fa86d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acb08dcbbd236fea83a3a94a1271a152f6121f4e8a8f135e700963cac741dece327ac9e250489c143fdbe75a72e7e304e9aac2cb60ce03ef0d285cec5e11bafc
|
7
|
+
data.tar.gz: 3414b1dbe008160c16472de55e20fad2eaa6eb0cca55c6f81626b13dca01ada7d9b2cad07e4530518dcb825d7d10e29aa057a1a7570f635c5bd52104a8153ac2
|
data/lib/generator.rb
CHANGED
@@ -5,9 +5,8 @@ require 'dtr_core'
|
|
5
5
|
module DTRToRust
|
6
6
|
# Generates Rust code from a DTR contract
|
7
7
|
class Generator
|
8
|
-
def initialize(
|
9
|
-
@
|
10
|
-
@dtr_contract = ::DTRCore::Parser.parse(file_path)
|
8
|
+
def initialize(content)
|
9
|
+
@dtr_contract = ::DTRCore::Contract.from_dtr_raw(content)
|
11
10
|
end
|
12
11
|
|
13
12
|
def generate
|
@@ -21,6 +20,14 @@ module DTRToRust
|
|
21
20
|
@content
|
22
21
|
end
|
23
22
|
|
23
|
+
def self.generate_from_file(file_path)
|
24
|
+
new(File.read(file_path)).generate
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.generate_from_string(dtr_string)
|
28
|
+
new(dtr_string).generate
|
29
|
+
end
|
30
|
+
|
24
31
|
private
|
25
32
|
|
26
33
|
attr_reader :dtr_contract
|
@@ -49,10 +56,10 @@ module DTRToRust
|
|
49
56
|
end
|
50
57
|
|
51
58
|
def generate_functions_each(functions)
|
52
|
-
functions
|
59
|
+
functions&.map do |function|
|
53
60
|
"\n pub fn #{function.name}(#{generate_function_args(function)}) " \
|
54
61
|
"-> #{function.output} {\n#{generate_instructions_each(function.instructions)}\n }\n"
|
55
|
-
end
|
62
|
+
end&.join("\n")
|
56
63
|
end
|
57
64
|
|
58
65
|
def generate_function_args(function)
|