PVN-gem 0.0.3 → 0.0.4
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/PVN.rb +60 -63
- 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: e3b9aabe6c037c2eb9fadab0ecff580da26ed43223996c9b29e03261f89ef1ee
|
|
4
|
+
data.tar.gz: 52492b4257cd128c55275007f679146c12d19668174576f76343d486f76043b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 303ee63aafed69aaa2d0afedf1e3a4adef7f163943fb9107ec6955b8c524ffe12aa36e384913e88f45466d4b16a1600a2218d261a424b6aa3cb0fbd5ee49e19e
|
|
7
|
+
data.tar.gz: 7af5c98c768bb653762c247c61d7e2977fa0b020f1d5d0da2b5b1a32c2491dc85bdf8eded6d91b129cf909078a5dd4d56db1b1abf53b35e19053f15cff03b4d8
|
data/lib/PVN.rb
CHANGED
|
@@ -7,8 +7,12 @@ class PVN
|
|
|
7
7
|
lines.each_with_index do |element, id|
|
|
8
8
|
tokens = element.split
|
|
9
9
|
line = id +1
|
|
10
|
-
if self.check_syntax(tokens)
|
|
10
|
+
if self.check_syntax(tokens, line, values)
|
|
11
|
+
if tokens[0].start_with?("g")
|
|
12
|
+
self.set_value(tokens, line)
|
|
13
|
+
else
|
|
11
14
|
values[tokens[1]] = self.set_value(tokens, line)
|
|
15
|
+
end
|
|
12
16
|
else
|
|
13
17
|
self.error_handler("syntax", line, 2)
|
|
14
18
|
end
|
|
@@ -21,79 +25,72 @@ class PVN
|
|
|
21
25
|
puts "#{key} = #{value}"
|
|
22
26
|
end
|
|
23
27
|
end
|
|
24
|
-
def self.check_syntax(tokens)
|
|
25
|
-
if tokens[
|
|
26
|
-
|
|
28
|
+
def self.check_syntax(tokens, line, values)
|
|
29
|
+
if (tokens[0].end_with?(".edit") && values.key?(tokens[1]) && tokens[0].length == 6) ||
|
|
30
|
+
(tokens[0].end_with?(".new") && !values.key?(tokens[1]) && tokens[0].length == 5)
|
|
31
|
+
if tokens.length >= 4
|
|
32
|
+
if tokens[2] == "="
|
|
33
|
+
return true
|
|
34
|
+
else
|
|
35
|
+
error_handler("syntax", line, 2)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
else
|
|
39
|
+
error_handler("syntax", line, "universal")
|
|
40
|
+
end
|
|
41
|
+
elsif (tokens[0].end_with?(".edit") && !values.key?(tokens[1]))
|
|
42
|
+
self.error_handler("not_existing", line, 0)
|
|
43
|
+
elsif (tokens[0].end_with?(".new") && values.key?(tokens[1]))
|
|
44
|
+
self.error_handler("already_existing", line, 0)
|
|
27
45
|
else
|
|
28
|
-
|
|
46
|
+
self.error_handler("syntax", line, 0)
|
|
29
47
|
end
|
|
30
48
|
end
|
|
31
49
|
def self.set_value(tokens, line)
|
|
50
|
+
|
|
32
51
|
case true
|
|
33
52
|
|
|
34
53
|
when tokens[0].start_with?("s")
|
|
54
|
+
text_raw = []
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else
|
|
41
|
-
self.error_handler("syntax", line, 0)
|
|
56
|
+
tokens.each_with_index do |element, id|
|
|
57
|
+
if id >= 3
|
|
58
|
+
text_raw << element
|
|
59
|
+
end
|
|
42
60
|
end
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
text = String.new(text_raw.join(" "))
|
|
62
|
+
if text.start_with?('"') && text.end_with?('"')
|
|
63
|
+
text = text.delete_prefix('"')
|
|
64
|
+
text = text.delete_suffix('"')
|
|
65
|
+
elsif text.start_with?('"') == false
|
|
66
|
+
self.error_handler("syntax", line, 3)
|
|
67
|
+
elsif text.end_with?('"') == false
|
|
68
|
+
self.error_handler("syntax", line, tokens.length - 1)
|
|
51
69
|
else
|
|
52
|
-
self.error_handler("syntax", line,
|
|
70
|
+
self.error_handler("syntax", line, "3 - #{tokens.length -1}")
|
|
53
71
|
end
|
|
72
|
+
return text
|
|
73
|
+
when tokens[0].start_with?("i")
|
|
74
|
+
return tokens[3].to_i
|
|
54
75
|
when tokens[0].start_with?("f")
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return tokens[3].to_f
|
|
58
|
-
elsif tokens[0].end_with?("edit")
|
|
59
|
-
|
|
60
|
-
return tokens[3].to_f
|
|
61
|
-
else
|
|
62
|
-
self.error_handler("syntax", line, 0)
|
|
63
|
-
end
|
|
76
|
+
return tokens[3].to_f
|
|
64
77
|
when tokens[0].start_with?("b")
|
|
65
|
-
if tokens[
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
self.error_handler("syntax", line, 3)
|
|
72
|
-
end
|
|
73
|
-
elsif tokens[0].end_with?("edit")
|
|
74
|
-
if tokens[3] == "true" || tokens[3] == "yes" || tokens[3] == "1"
|
|
75
|
-
return true
|
|
76
|
-
elsif tokens[3] == "false" || tokens[3] == "no" || tokens[3] == "0"
|
|
77
|
-
return false
|
|
78
|
-
else
|
|
79
|
-
self.error_handler("syntax", line, 3)
|
|
80
|
-
end
|
|
81
|
-
else
|
|
82
|
-
self.error_handler("syntax", line, 0)
|
|
83
|
-
end
|
|
84
|
-
when tokens[0].start_with?("g")
|
|
85
|
-
case tokens[3]
|
|
86
|
-
when "s", "i", "f", "b", "a"
|
|
87
|
-
if tokens[0].end_with?("new")
|
|
88
|
-
@groups[tokens[1]] = tokens[3]
|
|
89
|
-
return tokens[3]
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
else self.error_handler("syntax", line, 3)
|
|
78
|
+
if tokens[3] == "true" || tokens[3] == "yes" || tokens[3] == "1"
|
|
79
|
+
return true
|
|
80
|
+
elsif tokens[3] == "false" || tokens[3] == "no" || tokens[3] == "0"
|
|
81
|
+
return false
|
|
82
|
+
else
|
|
83
|
+
self.error_handler("syntax", line, 3)
|
|
93
84
|
end
|
|
94
85
|
else
|
|
95
|
-
|
|
86
|
+
self.error_handler("syntax", line, 0)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
def self.group_init()
|
|
90
|
+
case tokens[3]
|
|
91
|
+
when "s", "i", "f", "b"
|
|
96
92
|
end
|
|
93
|
+
@groups = tokens
|
|
97
94
|
end
|
|
98
95
|
def self.error_handler(type, line, token)
|
|
99
96
|
error = ""
|
|
@@ -102,12 +99,13 @@ class PVN
|
|
|
102
99
|
when "syntax"
|
|
103
100
|
error = "Wrong syntax. Look up the syntax in the docs on gihub. A version of the docs should also be bundeled with your pvn package"
|
|
104
101
|
when "not_existing"
|
|
105
|
-
error = "The variable you try to
|
|
106
|
-
when "
|
|
102
|
+
error = "The variable you try to edit is not declared"
|
|
103
|
+
when "already_existing"
|
|
107
104
|
error = "The variable you try to declare is already declared"
|
|
108
105
|
end
|
|
109
106
|
self.logo_printer()
|
|
110
|
-
puts "Error: Line: #{line}, Token: #{token}. #{error}."
|
|
107
|
+
puts "Error: Line: #{line}, Token: #{token}. #{error}."#
|
|
108
|
+
exit()
|
|
111
109
|
|
|
112
110
|
end
|
|
113
111
|
def self.logo_printer()
|
|
@@ -117,5 +115,4 @@ class PVN
|
|
|
117
115
|
puts " | __/ \\ V / | |\\ | "
|
|
118
116
|
puts " |_| \\_/ |_| \\_| "
|
|
119
117
|
end
|
|
120
|
-
end
|
|
121
|
-
PVN.read("/home/axi/PandaVariableNotation/examples/example.pvn")
|
|
118
|
+
end
|