PVN-gem 0.0.3
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 +7 -0
- data/lib/PVN.rb +121 -0
- metadata +39 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 21b12d503900858afc31053c024bb11b5a06f0049fd60217f1155648a6e385e2
|
|
4
|
+
data.tar.gz: 8219393c381d53f0d223c2c7ca6938abc5b5975742e37bf5287696261c74b751
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 838197b65cae4ac4eb8b23a92459734cb61697188c9daf67ad5f4da42f228aff0c33e3a021d83ebcfcebb0a1adcf9e568f04d9494ab70ffd9d7ce9da65138d06
|
|
7
|
+
data.tar.gz: 60928b4987d1cfda52831bdb87104148a6ddeab132355268f2d110a59c9db90b7d728062d1e6dd7c54283767e9ac7a9608bacbb40432e21ef6a831ac7e88f0dc
|
data/lib/PVN.rb
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
class PVN
|
|
2
|
+
def self.read(file)
|
|
3
|
+
lines = File.readlines(file)
|
|
4
|
+
|
|
5
|
+
values = {}
|
|
6
|
+
@groups = {}
|
|
7
|
+
lines.each_with_index do |element, id|
|
|
8
|
+
tokens = element.split
|
|
9
|
+
line = id +1
|
|
10
|
+
if self.check_syntax(tokens)
|
|
11
|
+
values[tokens[1]] = self.set_value(tokens, line)
|
|
12
|
+
else
|
|
13
|
+
self.error_handler("syntax", line, 2)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
return values
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
def self.list(var)
|
|
20
|
+
var.each do |key, value|
|
|
21
|
+
puts "#{key} = #{value}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
def self.check_syntax(tokens)
|
|
25
|
+
if tokens[2] == "="
|
|
26
|
+
return true
|
|
27
|
+
else
|
|
28
|
+
return false
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
def self.set_value(tokens, line)
|
|
32
|
+
case true
|
|
33
|
+
|
|
34
|
+
when tokens[0].start_with?("s")
|
|
35
|
+
|
|
36
|
+
if tokens[0].end_with?("new")
|
|
37
|
+
return tokens[3].to_s
|
|
38
|
+
elsif tokens[0].end_with?("edit")
|
|
39
|
+
return tokens[3].to_s
|
|
40
|
+
else
|
|
41
|
+
self.error_handler("syntax", line, 0)
|
|
42
|
+
end
|
|
43
|
+
when tokens[0].start_with?("i")
|
|
44
|
+
|
|
45
|
+
if tokens[0].end_with?("new")
|
|
46
|
+
|
|
47
|
+
return tokens[3].to_i
|
|
48
|
+
elsif tokens[0].end_with?("edit")
|
|
49
|
+
|
|
50
|
+
return tokens[3].to_i
|
|
51
|
+
else
|
|
52
|
+
self.error_handler("syntax", line, 0)
|
|
53
|
+
end
|
|
54
|
+
when tokens[0].start_with?("f")
|
|
55
|
+
if tokens[0].end_with?("new")
|
|
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
|
|
64
|
+
when tokens[0].start_with?("b")
|
|
65
|
+
if tokens[0].end_with?("new")
|
|
66
|
+
if tokens[3] == "true" || tokens[3] == "yes" || tokens[3] == "1"
|
|
67
|
+
return true
|
|
68
|
+
elsif tokens[3] == "false" || tokens[3] == "no" || tokens[3] == "0"
|
|
69
|
+
return false
|
|
70
|
+
else
|
|
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)
|
|
93
|
+
end
|
|
94
|
+
else
|
|
95
|
+
self.error_handler("syntax", line, 0)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
def self.error_handler(type, line, token)
|
|
99
|
+
error = ""
|
|
100
|
+
case type
|
|
101
|
+
|
|
102
|
+
when "syntax"
|
|
103
|
+
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
|
+
when "not_existing"
|
|
105
|
+
error = "The variable you try to access is not declared"
|
|
106
|
+
when "already_exists"
|
|
107
|
+
error = "The variable you try to declare is already declared"
|
|
108
|
+
end
|
|
109
|
+
self.logo_printer()
|
|
110
|
+
puts "Error: Line: #{line}, Token: #{token}. #{error}."
|
|
111
|
+
|
|
112
|
+
end
|
|
113
|
+
def self.logo_printer()
|
|
114
|
+
puts " _____ ___ _ "
|
|
115
|
+
puts " | _ \\ \\ / / \\ | | "
|
|
116
|
+
puts " | |_) \\ \\ / /| \\| | "
|
|
117
|
+
puts " | __/ \\ V / | |\\ | "
|
|
118
|
+
puts " |_| \\_/ |_| \\_| "
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
PVN.read("/home/axi/PandaVariableNotation/examples/example.pvn")
|
metadata
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: PVN-gem
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- LordAxi
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Gem for interpreting the PandaVariableNotation(PVN)
|
|
13
|
+
executables: []
|
|
14
|
+
extensions: []
|
|
15
|
+
extra_rdoc_files: []
|
|
16
|
+
files:
|
|
17
|
+
- lib/PVN.rb
|
|
18
|
+
homepage: https://github.com/LordAxi/PandaVariableNotation
|
|
19
|
+
licenses:
|
|
20
|
+
- MIT
|
|
21
|
+
metadata: {}
|
|
22
|
+
rdoc_options: []
|
|
23
|
+
require_paths:
|
|
24
|
+
- lib
|
|
25
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
requirements: []
|
|
36
|
+
rubygems_version: 4.0.3
|
|
37
|
+
specification_version: 4
|
|
38
|
+
summary: PandaVariableNotation
|
|
39
|
+
test_files: []
|