dtr_core 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4f18cef3a0ec84890c70f6e491a206c175173da2fa1afcaa35edbb4f16f389f
4
- data.tar.gz: 76733758b94e9e1dfe1a6b048ae97bcde7d8101e5aa377ec8c367146fe533a05
3
+ metadata.gz: f1d08e671686f002deb8379c32077c2049a81930748cc6a1836c9bea80e8ed39
4
+ data.tar.gz: adcb40a8999cbbc23ba1ee48da7b29296437012b7dd9fcd4d31aabf70a1532c0
5
5
  SHA512:
6
- metadata.gz: 9815551cfb8564a2ef71499f4a797ab16c36cabfc22f8e2e0b94fba8e8766ef0d5b36b6d12b73e9cde49bcf3ca44ea45f35e074d8ed93b98537e164370daa340
7
- data.tar.gz: 1da1eb0d8df324d693dd66d7f3fa4ff225461768f121ef48e7ef3f07f8aa29da4dfad4e6c6426a00680d839cb0efc37d5ce7c5e75704228a2dd476b9246f2c5f
6
+ metadata.gz: 062a411d6c59d9e00a86b41059c7dbaccde844f9671259430b27136074c99131922581f58ba99ba0a96e60bd2c1cfe1768178e6d0b7d6c57e2225d4bd4878bea
7
+ data.tar.gz: a7cb26e036aa3173a595c4ba65bcd6955e196e773af7da95756ef6cbfda0f63237517f06ec4ba7d2fca08d64c39f4ee0ef2ca1bea098d48b7e92364ca7265388
@@ -20,5 +20,86 @@ module DTRCore
20
20
  def clean_name(definition)
21
21
  definition.gsub(/[\*\n\[]/, '').strip
22
22
  end
23
+
24
+ def self.get_input_content(some_string)
25
+ start_index = some_string.index('input:')
26
+ return nil if start_index.nil?
27
+
28
+ start_parse_parent_index = some_string.index('(', start_index)
29
+
30
+ paren_contents(some_string[start_parse_parent_index..])
31
+ end
32
+
33
+ def self.paren_contents(some_string)
34
+ cur_word = ''
35
+ index = 0
36
+ cur_words = []
37
+ how_many_deep_soft_brackets = 0
38
+ how_many_deep_hard_brackets = 0
39
+ how_many_deep_square_brackets = 0
40
+ in_string = false
41
+
42
+ while index < some_string.length
43
+ char = some_string[index]
44
+
45
+ if char == ')' && !in_string
46
+ how_many_deep_soft_brackets -= 1
47
+
48
+ if how_many_deep_soft_brackets.zero?
49
+ cur_words.push(cur_word.strip) unless cur_word.empty?
50
+ return cur_words
51
+ else
52
+ cur_word += char
53
+ end
54
+ elsif char == '[' && !in_string
55
+ how_many_deep_square_brackets += 1
56
+ cur_word += char
57
+ elsif char == ']' && !in_string
58
+ how_many_deep_square_brackets -= 1
59
+ cur_word += char
60
+ elsif char == '{' && !in_string
61
+ how_many_deep_hard_brackets += 1
62
+ cur_word += char
63
+ elsif char == '}' && !in_string
64
+ how_many_deep_hard_brackets -= 1
65
+ cur_word += char
66
+ elsif ['\'', '"'].include?(char)
67
+ in_string = in_string ? false : true
68
+ cur_word += char
69
+ elsif char == '(' && !in_string
70
+ how_many_deep_soft_brackets += 1
71
+ cur_word += char if how_many_deep_soft_brackets > 1
72
+ elsif char == ',' && how_many_deep_soft_brackets == 1 &&
73
+ how_many_deep_hard_brackets.zero? &&
74
+ how_many_deep_square_brackets.zero? &&
75
+ !in_string
76
+ cur_words.push(cur_word.strip) unless cur_word.empty?
77
+ cur_word = ''
78
+ else
79
+ cur_word += char
80
+ end
81
+
82
+ index += 1
83
+ end
84
+
85
+ raise 'No closing parenthesis found.'
86
+ end
87
+
88
+ def self.nested_array_to_string(array)
89
+ # Base case: if the element is not an array, return the element as a string
90
+ return array.to_s unless array.is_a?(Array)
91
+
92
+ # Recursively process each element in the array and join them with commas
93
+ elements = array.map { |element| nested_array_to_string(element) }.join(', ')
94
+
95
+ # Wrap the joined elements with parentheses
96
+ "(#{elements})"
97
+ end
98
+
99
+ def self.parse_instruction_input(instruction)
100
+ result = get_input_content(instruction)
101
+
102
+ result.nil? || result.empty? ? nil : result
103
+ end
23
104
  end
24
105
  end
@@ -96,7 +96,7 @@ module DTRCore
96
96
  def parse_function_instruction(instruction)
97
97
  instruction = DTRCore::Instruction.new(
98
98
  instruction[/instruction:\s*(?<all>[^\s,]+)/, 1],
99
- parse_function_instruction_input(instruction),
99
+ DTRCore::Common.parse_instruction_input(instruction),
100
100
  instruction[/\s*assign:\s*\[?(?<all>[^\s\,\]]+)\]?/, 1],
101
101
  instruction[/\s*scope:\s*(?<all>[^\s\,]+)/, 1].to_i || 0,
102
102
  instruction[/\sid:\s*(?<all>[^\s,]+)/, 1].to_i || 0
@@ -106,42 +106,5 @@ module DTRCore
106
106
 
107
107
  instruction
108
108
  end
109
-
110
- def parse_function_instruction_input(definition)
111
- raw_inputs = definition[/\s*input:\s*\((?<all>[^\)]+)\)/, 1]
112
- return nil if raw_inputs.nil?
113
-
114
- cur_word = ''
115
- inputs_to_return = []
116
- in_string = false
117
-
118
- raw_inputs.each_char do |char|
119
- if in_string
120
- if char == '"'
121
- in_string = false
122
- inputs_to_return.push("\"#{cur_word}\"")
123
- cur_word = ''
124
- else
125
- cur_word += char
126
- end
127
- elsif cur_word.empty? && char == '"'
128
- in_string = true
129
- elsif char == ','
130
- inputs_to_return.push(cur_word)
131
- cur_word = ''
132
- in_string = false
133
- elsif char == ' ' && cur_word.empty?
134
- next
135
- else
136
- cur_word += char
137
- end
138
- end
139
-
140
- inputs_to_return.push(cur_word) unless cur_word.empty?
141
-
142
- inputs_to_return.filter! { |x| !x.empty? }
143
-
144
- inputs_to_return&.map(&:strip)
145
- end
146
109
  end
147
110
  end
data/lib/dtr_core.rb CHANGED
@@ -12,6 +12,7 @@ module DTRCore
12
12
  autoload :InstructionValidator, 'dtr_core/instruction_validator'
13
13
  autoload :Instruction, 'dtr_core/instruction'
14
14
  autoload :UserDefinedType, 'dtr_core/user_defined_type'
15
+ autoload :Common, 'dtr_core/common'
15
16
 
16
17
  # A graph is a collection of nodes and edges representing the structure of a DTR file.
17
18
  module Graph
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.12.0
4
+ version: 0.12.1
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-07-16 00:00:00.000000000 Z
11
+ date: 2024-07-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |+
14
14
  Ruby gem serving as the reference implementation for the parsing and consumption of Digicus Textual Representation (DTR). We expect folks to leverage this gem when writing Digicus compiler plugins.