dtr_to_rust 0.0.9 → 0.1.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/common/input_interpreter.rb +14 -6
- data/lib/instruction/evaluate.rb +0 -4
- data/lib/instruction/log_string.rb +17 -1
- 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: c0da890c9d6e5d3255e3e68e3682c44aa96dc9183300fcda4fd9213804e00177
|
4
|
+
data.tar.gz: f2e4076c01ae9df3ea11d6673638565b319ee5912d175a5ccbc961e1dc539727
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1afffffff9bbc3b1508bc51486b1c9baecc379c509d553b45a8083788544a8460f3ac9aff5b3c4bd1620fe8c957ff77f6696543c91b0d059e9d376bced1705a9
|
7
|
+
data.tar.gz: 71b9a961cd662205319e5604f563574ae770ed15baec2b28d3b3d35c69bdb09271d44ad1cafe0f63da58c4ec293af0684c25ad6480b4f9c58d96e058c070e289
|
@@ -13,12 +13,12 @@ module DTRToRust
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def interpret
|
16
|
-
if
|
17
|
-
|
16
|
+
if number?(@input)
|
17
|
+
number_return(@input)
|
18
18
|
elsif string?(@input)
|
19
19
|
string_return(@input)
|
20
|
-
|
21
|
-
|
20
|
+
else
|
21
|
+
variable_return(@input)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -44,11 +44,19 @@ module DTRToRust
|
|
44
44
|
|
45
45
|
## Number ##
|
46
46
|
def number?(input)
|
47
|
-
input.is_a?(Numeric)
|
47
|
+
input.is_a?(Numeric) || input&.match?(/^\s*\d+\.?\d*\s*$/)
|
48
48
|
end
|
49
49
|
|
50
50
|
def number_return(_input)
|
51
|
-
{ value: @input, type: 'number', needs_reference: false }
|
51
|
+
{ value: contains_decimal?(@input.to_s) ? @input.to_f : @input.to_i, type: 'number', needs_reference: false }
|
52
|
+
end
|
53
|
+
|
54
|
+
def contains_decimal?(str)
|
55
|
+
# Define a regular expression pattern for a decimal number
|
56
|
+
decimal_pattern = /\d+\.\d+/
|
57
|
+
|
58
|
+
# Check if the string matches the pattern
|
59
|
+
!!(str =~ decimal_pattern)
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
data/lib/instruction/evaluate.rb
CHANGED
@@ -5,7 +5,23 @@ module DTRToRust
|
|
5
5
|
# This class is responsible for generating Rust code for the LogString instruction.
|
6
6
|
class LogString < Handler
|
7
7
|
def handle
|
8
|
-
form_rust_string("log!(#{@instruction[:inputs]
|
8
|
+
form_rust_string("log!(#{inputs_to_rust_string(@instruction[:inputs])});", @instruction[:scope])
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def inputs_to_rust_string(inputs)
|
14
|
+
inputs.map { |input| ref_appender(input) }.join(', ')
|
15
|
+
end
|
16
|
+
|
17
|
+
def ref_appender(input)
|
18
|
+
decorated_input = Common::InputInterpreter.interpret(input)
|
19
|
+
|
20
|
+
if decorated_input[:needs_reference]
|
21
|
+
"&#{decorated_input[:value]}"
|
22
|
+
else
|
23
|
+
decorated_input[:value]
|
24
|
+
end
|
9
25
|
end
|
10
26
|
end
|
11
27
|
end
|