Skip to content

Commit 8823b73

Browse files
author
mendelsshop
committed
cargo formatted: added new keyword
working on docs removed a lot of the .uwnrap
1 parent 3b47929 commit 8823b73

File tree

5 files changed

+43
-30
lines changed

5 files changed

+43
-30
lines changed

src/eval.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl Scope {
381381
}
382382
}
383383
pub fn drop_scope(&mut self) {
384-
let p_scope: Self = match self.parent_scope.take(){
384+
let p_scope: Self = match self.parent_scope.take() {
385385
Some(scope) => *scope,
386386
None => error(0, "no parent scope"),
387387
};
@@ -691,7 +691,13 @@ impl Eval {
691691
}
692692
}
693693
TokenType::Type => {
694-
arg_error(1, call.arguments.len() as u32, &call.keyword, false, call.line);
694+
arg_error(
695+
1,
696+
call.arguments.len() as u32,
697+
&call.keyword,
698+
false,
699+
call.line,
700+
);
695701
match self.find_pointer_in_stuff(&call.arguments[0]) {
696702
LiteralOrFile::Literal(a) => {
697703
LiteralOrFile::Literal(LiteralType::String(a.get_type()))

src/lexer.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,22 @@ impl Lexer {
169169
y if y.is_ascii_hexdigit() => {
170170
self.insert_text(
171171
self.current,
172-
u8::from_str_radix(format!("{x}{y}").as_str(), 16).unwrap_or_else(|_| {
173-
error::error(self.line, "invalid hex escape sequence");
174-
}) as char,
172+
u8::from_str_radix(format!("{x}{y}").as_str(), 16)
173+
.unwrap_or_else(|_| {
174+
error::error(self.line, "invalid hex escape sequence");
175+
}) as char,
175176
);
176177
self.advance();
177178
}
178179
y => {
179180
self.insert_text(
180181
self.current,
181-
u8::from_str_radix(format!("{x}").as_str(), 16).unwrap_or_else(|_| {
182-
error::error(self.line, "invalid hex escape sequence");
183-
}) as char);
182+
u8::from_str_radix(format!("{x}").as_str(), 16).unwrap_or_else(
183+
|_| {
184+
error::error(self.line, "invalid hex escape sequence");
185+
},
186+
) as char,
187+
);
184188
self.insert_text(self.current + 1, y);
185189
self.advance();
186190
}
@@ -203,11 +207,14 @@ impl Lexer {
203207
}
204208
self.insert_text(
205209
self.current,
206-
char::from_u32(u32::from_str_radix(hex_string.as_str(), 16).unwrap_or_else(|_| {
207-
error::error(self.line, "invalid unicode escape sequence");
208-
} ) ).unwrap_or_else(|| {
210+
char::from_u32(
211+
u32::from_str_radix(hex_string.as_str(), 16).unwrap_or_else(|_| {
209212
error::error(self.line, "invalid unicode escape sequence");
210-
})
213+
}),
214+
)
215+
.unwrap_or_else(|| {
216+
error::error(self.line, "invalid unicode escape sequence");
217+
}),
211218
);
212219
self.current += 1;
213220
} else {

src/main.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ fn main() {
2727
'l: loop {
2828
let mut input = String::new();
2929
print!(">> "); // print the prompt
30-
io::stdout().flush().unwrap_or_else(|_| panic!("Failed to flush stdout"));
31-
io::stdin().read_line(&mut input).unwrap_or_else(|_| panic!("Failed to read stdin"));
30+
io::stdout()
31+
.flush()
32+
.unwrap_or_else(|_| panic!("Failed to flush stdout"));
33+
io::stdin()
34+
.read_line(&mut input)
35+
.unwrap_or_else(|_| panic!("Failed to read stdin"));
3236
if input.trim() == "exit" {
3337
// if the input is exit, then exit
3438
info!("Exiting...");
@@ -37,9 +41,13 @@ fn main() {
3741
if Path::new(&parsed_args.file).exists() && !parsed_args.force {
3842
// if the file exists and we are not forcing it to overwrite
3943
print!("Do you want to overwrite the {}? (y/n): ", parsed_args.file); // ask the user if they want to overwrite the file
40-
io::stdout().flush().unwrap_or_else(|_| panic!("Failed to flush stdout"));
44+
io::stdout()
45+
.flush()
46+
.unwrap_or_else(|_| panic!("Failed to flush stdout"));
4147
let mut y_or_n: String = String::new();
42-
io::stdin().read_line(&mut y_or_n).unwrap_or_else(|_| panic!("Failed to read stdin")); // read the input
48+
io::stdin()
49+
.read_line(&mut y_or_n)
50+
.unwrap_or_else(|_| panic!("Failed to read stdin")); // read the input
4351
if y_or_n == "n" {
4452
// if the user does not want to overwrite the file exit
4553
exit(0);
@@ -63,11 +71,9 @@ fn main() {
6371
}
6472
} else {
6573
// if we are not in repl mode ie we are reading a file
66-
let mut file: File = File::open(&parsed_args.file).unwrap_or_else(
67-
|_| {
68-
error::error(0, "Error encountered while opening file!");
69-
},
70-
); // open the file
74+
let mut file: File = File::open(&parsed_args.file).unwrap_or_else(|_| {
75+
error::error(0, "Error encountered while opening file!");
76+
}); // open the file
7177
let mut contents: String = String::new(); // create a string to hold the contents of the file
7278
match file.read_to_string(&mut contents) {
7379
Ok(contents) => contents,

src/parser/rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl LiteralType {
148148
}
149149
}
150150

151-
pub fn get_type(&self) -> String {
151+
pub fn get_type(&self) -> String {
152152
match self {
153153
Self::Number(_) => "number".to_string(),
154154
Self::String(_) => "string".to_string(),

src/token.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub enum TokenType {
8383
WriteLine,
8484
CreateFile,
8585
DeleteFile,
86-
Type
86+
Type,
8787
}
8888

8989
impl TokenType {
@@ -196,13 +196,7 @@ impl TokenType {
196196
| Self::StrToHempty
197197
| Self::StrToNum
198198
| Self::RunCommand => {
199-
arg_error(
200-
1,
201-
args.len() as u32,
202-
self,
203-
false,
204-
line
205-
);
199+
arg_error(1, args.len() as u32, self, false, line);
206200
match &args[0] {
207201
LiteralType::String(ref string) => match self {
208202
Self::Error => exit(1),

0 commit comments

Comments
 (0)