my_precious 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +37 -0
- data/exe/my_precious +6 -0
- data/lib/my_precious/cli.rb +8 -0
- data/lib/my_precious/parser.rb +190 -0
- data/lib/my_precious/version.rb +1 -1
- data/lib/my_precious.rb +26 -1
- data/middle_earth.precious +36 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa99e2aca8eb96c5c7b3e953a77fbab98ac79b642c007a4e9e29f1278cf03d1c
|
4
|
+
data.tar.gz: b4cfe219a8148e80150e3ab920ba859da27301013d89e9d42ac437b527c2c5ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00142c94bd42e97a173dcdf7b4789d3af1b5d2d8ea8d950270bc6a825542f3227f7511206fbca3a4b78982aba38e02cf44aba5a00991d5d4ece040d860989202
|
7
|
+
data.tar.gz: 7c93f3c68ba3d58828e9ac208d2ff6687156ed51fdedf797ccfdef19694d25f39beb9595cff2c4875b1877dcd46d03ab9b1912130d3dee8ddd47c7c8d7620907
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
my_precious (0.1.3)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
thor (0.20.3)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.17)
|
31
|
+
my_precious!
|
32
|
+
rake (~> 10.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
thor
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.17.3
|
data/exe/my_precious
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
class Parser
|
4
|
+
# KEYWORDS
|
5
|
+
PUT_KEYWORDS = ['bring forth the ring', 'says', 'screams', 'exclaims', 'sobbs', 'coughs']
|
6
|
+
COMMENT_KEYWORDS = ['second breakfast', 'wear the ring']
|
7
|
+
ASSIGNMENT_KEYWORDS = ['is', 'has', 'was']
|
8
|
+
INCREMENT_KEYWORDS = ['eats lembas bread', 'fortifies stronghold', 'rests', 'recieves Evenstar', 'reforges Narsil']
|
9
|
+
DECREMENT_KEYWORDS = ['runs out of lembas bread', 'lost', 'hunted by orcs']
|
10
|
+
ADDITION_KEYWORDS = ['joins', 'join', 'and', 'accompanies']
|
11
|
+
SUBTRACTION_KEYWORDS = ['leaves the fellowship', 'stabs', 'banishes', 'steals']
|
12
|
+
MULTIPLICATION_KEYWORDS = ['gives aid to', 'procreates', 'bolsters']
|
13
|
+
DIVISION_KEYWORDS = ['decapitates', 'dismembers']
|
14
|
+
COMPARISON_KEYWORDS = ['as', 'equal']
|
15
|
+
CONDITION_KEYWORDS = ['does', 'if', 'will']
|
16
|
+
END_KEYWORDS = ['you shall not pass']
|
17
|
+
TRUE_KEYWORDS = ['precious']
|
18
|
+
FALSE_KEYWORDS = ['not precious']
|
19
|
+
LOOP_KEYWORDS = ['whilst', 'during the journey']
|
20
|
+
GREATER_THAN_KEYWORDS = ['stronger than', 'more']
|
21
|
+
LESS_THAN_KEYWORDS = ['weaker than', 'less']
|
22
|
+
OPERATOR_KEYWORDS = ['#', '+', '-', '=', '*', '/', '+=1', '-=1', 'puts', '==', 'if', 'end', 'true', 'false', 'while', '>', '<']
|
23
|
+
|
24
|
+
|
25
|
+
ALICIA_KEYS = [PUT_KEYWORDS, COMMENT_KEYWORDS, ASSIGNMENT_KEYWORDS,
|
26
|
+
INCREMENT_KEYWORDS, DECREMENT_KEYWORDS, ADDITION_KEYWORDS,
|
27
|
+
SUBTRACTION_KEYWORDS, DIVISION_KEYWORDS, MULTIPLICATION_KEYWORDS,
|
28
|
+
COMPARISON_KEYWORDS, CONDITION_KEYWORDS, END_KEYWORDS, TRUE_KEYWORDS, FALSE_KEYWORDS, LOOP_KEYWORDS, GREATER_THAN_KEYWORDS, LESS_THAN_KEYWORDS]
|
29
|
+
|
30
|
+
MAP = [{'puts': PUT_KEYWORDS}, {'#': COMMENT_KEYWORDS},
|
31
|
+
{'=': ASSIGNMENT_KEYWORDS}, {'+=1': INCREMENT_KEYWORDS},
|
32
|
+
{'-=1': DECREMENT_KEYWORDS}, {'+': ADDITION_KEYWORDS},
|
33
|
+
{'-': SUBTRACTION_KEYWORDS}, {'*': MULTIPLICATION_KEYWORDS},
|
34
|
+
{'/': DIVISION_KEYWORDS}, {'==': COMPARISON_KEYWORDS},
|
35
|
+
{'if': CONDITION_KEYWORDS}, {'end': END_KEYWORDS}, {'true': TRUE_KEYWORDS}, {'false': FALSE_KEYWORDS}, {'while': LOOP_KEYWORDS}, {'>': GREATER_THAN_KEYWORDS}, {'<': LESS_THAN_KEYWORDS}]
|
36
|
+
|
37
|
+
def self.parse_file(file, output_file_name)
|
38
|
+
str = ""
|
39
|
+
writer_file_name = output_file_name
|
40
|
+
file.each_with_index do |file, index|
|
41
|
+
file.each_line do |line|
|
42
|
+
line = parse_line(line, index)
|
43
|
+
str << (line + "\n")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
write(str, writer_file_name)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.parse_line(line, index)
|
50
|
+
|
51
|
+
#error handeling
|
52
|
+
#ignore lines of length 1, its empty
|
53
|
+
if line.length == 1
|
54
|
+
# write("#{line}")
|
55
|
+
return line
|
56
|
+
else
|
57
|
+
|
58
|
+
#check if there are strings in line
|
59
|
+
quote = ""
|
60
|
+
if line.include? '"'
|
61
|
+
quote = get_string(line)
|
62
|
+
line = line.gsub(quote, 'quote_placeholder')
|
63
|
+
end
|
64
|
+
|
65
|
+
#check if line is a comment
|
66
|
+
comment = ""
|
67
|
+
if COMMENT_KEYWORDS.any? { |word| line.include?(word) }
|
68
|
+
line = parse(line, COMMENT_KEYWORDS)
|
69
|
+
comment = get_comment(line)
|
70
|
+
line = line.gsub(comment, 'comment_placeholder')
|
71
|
+
end
|
72
|
+
|
73
|
+
#get rid of special chars
|
74
|
+
line_array = line.split(" ")
|
75
|
+
line_array.each_with_index do |word, index|
|
76
|
+
line_array[index] = purify(word)
|
77
|
+
end
|
78
|
+
|
79
|
+
#check for keywords
|
80
|
+
#calls if statements
|
81
|
+
line = line_array.join(" ")
|
82
|
+
line = check_for_keywords(line)
|
83
|
+
|
84
|
+
#remove extra english words
|
85
|
+
line = only_valuable_words(line).downcase
|
86
|
+
|
87
|
+
#put string back into line
|
88
|
+
if line.include? ('"quote_placeholder"')
|
89
|
+
line = line.gsub('quote_placeholder', quote)
|
90
|
+
end
|
91
|
+
|
92
|
+
if line.include? ('comment_placeholder')
|
93
|
+
line = line.gsub('comment_placeholder', comment)
|
94
|
+
end
|
95
|
+
#puts "end line: #{line}"
|
96
|
+
# write("#{line}")
|
97
|
+
return line
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.check_for_keywords(line)
|
102
|
+
ALICIA_KEYS.each do |keywords|
|
103
|
+
if keywords.any? { |word| line.include?(word) }
|
104
|
+
line = parse(line, keywords)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
line
|
108
|
+
end
|
109
|
+
|
110
|
+
# METHODS
|
111
|
+
def self.parse(line, keywords)
|
112
|
+
keywords.each do |keyword|
|
113
|
+
if line.include? keyword
|
114
|
+
replacement = find_replacement(keywords)
|
115
|
+
line = line.gsub(keyword, replacement)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
return line
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.purify(word)
|
122
|
+
word = word.gsub(/[!@%&.?,]/,'') # get rid of special chars
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.only_valuable_words(line)
|
126
|
+
important_words = []
|
127
|
+
line_array = line.split(" ")
|
128
|
+
line_array.each do |word|
|
129
|
+
valuable_word = valuable?(word)
|
130
|
+
if valuable_word
|
131
|
+
important_words << word
|
132
|
+
end
|
133
|
+
end
|
134
|
+
line = important_words.join(" ")
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.valuable?(word)
|
138
|
+
valuable = false
|
139
|
+
if /[[:upper:]]/.match(word[0]) #if variable
|
140
|
+
valuable = true
|
141
|
+
elsif word == '"quote_placeholder"' #if string
|
142
|
+
valuable = true
|
143
|
+
elsif word == '#comment_placeholder' #if string
|
144
|
+
valuable = true
|
145
|
+
elsif word.to_i.to_s == word #if num
|
146
|
+
valuable = true
|
147
|
+
elsif OPERATOR_KEYWORDS.include? word #if operator
|
148
|
+
valuable = true
|
149
|
+
end
|
150
|
+
valuable
|
151
|
+
end
|
152
|
+
|
153
|
+
def self.get_string(phrase)
|
154
|
+
phrase_array = phrase.split('')
|
155
|
+
index = phrase_array.find_index { |i| i == '"'} + 1
|
156
|
+
quote = ""
|
157
|
+
while phrase_array[index] != '"'
|
158
|
+
quote << phrase_array[index]
|
159
|
+
index += 1
|
160
|
+
end
|
161
|
+
quote
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.get_comment(phrase)
|
165
|
+
phrase_array = phrase.split('')
|
166
|
+
index = phrase_array.find_index { |i| i == '#'} + 1
|
167
|
+
comment = ""
|
168
|
+
while index < phrase_array.length
|
169
|
+
comment << phrase_array[index]
|
170
|
+
index += 1
|
171
|
+
end
|
172
|
+
comment
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.find_replacement(keywords)
|
176
|
+
MAP.each do |hash|
|
177
|
+
hash.each do |key, value|
|
178
|
+
if value == keywords
|
179
|
+
return key.to_s
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.write(str, writer_file_name)
|
186
|
+
writer_file = File.open(writer_file_name, 'w')
|
187
|
+
writer_file.write(str)
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
data/lib/my_precious/version.rb
CHANGED
data/lib/my_precious.rb
CHANGED
@@ -1,7 +1,32 @@
|
|
1
|
+
require 'thor'
|
1
2
|
require "my_precious/version"
|
2
3
|
|
3
4
|
module MyPrecious
|
4
5
|
class Error < StandardError; end
|
5
6
|
# Your code goes here...
|
6
|
-
|
7
|
+
class CLI < Thor
|
8
|
+
|
9
|
+
desc 'bring_forth FILE', 'creates a .precious FILE where users can write their LOTR code'
|
10
|
+
def bring_forth filename
|
11
|
+
file = File.open filename
|
12
|
+
puts "You have succesfully brought forth tome.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'parse FILE', 'parse a .precious FILE and output the result'
|
16
|
+
def parse input_file_name, output_file_name
|
17
|
+
file = File.open input_file_name
|
18
|
+
Parser.parse_file file, output_file_name
|
19
|
+
puts "You have successfully transcribed tome.rb"
|
20
|
+
file.close
|
21
|
+
end
|
22
|
+
|
23
|
+
# def run filename
|
24
|
+
# file = File.open filename
|
25
|
+
# puts "You have successfully closed tome.rb"
|
26
|
+
# end
|
27
|
+
|
28
|
+
# def speak_friend
|
29
|
+
# end
|
30
|
+
|
31
|
+
end #end of CLI
|
7
32
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
gandalf says "they are taking the hobbits to Isengard"
|
2
|
+
Frodo has 398 pieces of gold.
|
3
|
+
Saruman was worried when he saw 7 hobbits approaching his lair.
|
4
|
+
Frodo eats lembas bread
|
5
|
+
Despair is really sad because Frodo leaves the fellowship without Saruman knowing.
|
6
|
+
Ruin is Frodo.
|
7
|
+
|
8
|
+
bring forth the ring Despair and Ruin
|
9
|
+
Frodo joins the fellowship with Saruman.
|
10
|
+
Sam is 3.
|
11
|
+
i love second breakfast Sam is going to be a number
|
12
|
+
Frodo leaves the fellowship with Sam
|
13
|
+
Sam runs out of lembas bread
|
14
|
+
Sam decapitates Saruman
|
15
|
+
Saruman gives aid to Saruman
|
16
|
+
Gollum is "a good boy"
|
17
|
+
|
18
|
+
will Gollum grow as strong as Gollum
|
19
|
+
Sam is Sam and Frodo
|
20
|
+
gandalf screams you shall not pass
|
21
|
+
gimly says Sam
|
22
|
+
|
23
|
+
Legolas is precious!!!!
|
24
|
+
|
25
|
+
but the Balrog is not precious :(
|
26
|
+
|
27
|
+
whilst Frodo climed as strong as he could, Saruman cried, nooo!!
|
28
|
+
you shall not pass
|
29
|
+
|
30
|
+
Nazgul has 10 horsepower
|
31
|
+
|
32
|
+
if Frodo runs more quickly than a Nazgul
|
33
|
+
you shall not pass
|
34
|
+
|
35
|
+
does a Nazgul eat less hobbits than Saruman?
|
36
|
+
you shall not pass
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_precious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jessicabettsftw
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-03-
|
12
|
+
date: 2019-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -59,7 +59,8 @@ description: '"I wanted to make a fun programming language so I did it. It''s al
|
|
59
59
|
email:
|
60
60
|
- jessicaannbettsis@gmail.com
|
61
61
|
- crishanks12@gmail.com
|
62
|
-
executables:
|
62
|
+
executables:
|
63
|
+
- my_precious
|
63
64
|
extensions: []
|
64
65
|
extra_rdoc_files: []
|
65
66
|
files:
|
@@ -68,13 +69,18 @@ files:
|
|
68
69
|
- ".travis.yml"
|
69
70
|
- CODE_OF_CONDUCT.md
|
70
71
|
- Gemfile
|
72
|
+
- Gemfile.lock
|
71
73
|
- LICENSE.txt
|
72
74
|
- README.md
|
73
75
|
- Rakefile
|
74
76
|
- bin/console
|
75
77
|
- bin/setup
|
78
|
+
- exe/my_precious
|
76
79
|
- lib/my_precious.rb
|
80
|
+
- lib/my_precious/cli.rb
|
81
|
+
- lib/my_precious/parser.rb
|
77
82
|
- lib/my_precious/version.rb
|
83
|
+
- middle_earth.precious
|
78
84
|
- my_precious.gemspec
|
79
85
|
homepage: https://github.com/jessicabettsftw/my_precious
|
80
86
|
licenses:
|