-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: keyword filters + args working
- Loading branch information
Showing
11 changed files
with
507 additions
and
450 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{{ colors colors }} | ||
{{ colors.colors | a }} | ||
|
||
{{ colors.colors | b: c }} | ||
|
||
{{ colors.source_color.default.hex }} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use parse::ParseError; | ||
|
||
pub mod parse; | ||
|
||
pub fn handle_error<T>(f: Result<T, ParseError<'_>>) { | ||
if let Err(ref e) = f { | ||
std::eprintln!("{}", e); | ||
}; | ||
} | ||
|
||
pub fn handle_error_panic<T>(f: Result<T, ParseError<'_>>) { | ||
if let Err(ref e) = f { | ||
panic!("{}", e); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::fmt; | ||
|
||
use crate::parser::Parser; | ||
|
||
#[derive(Debug)] | ||
pub struct ParseError<'a> { | ||
pub err_type: ParseErrorTypes, | ||
pub start: usize, | ||
pub end: usize, | ||
pub source: &'a str, | ||
pub filename: &'a str, | ||
pub line_number: u64, | ||
} | ||
|
||
impl ParseError<'_> { | ||
pub fn new<'a>( | ||
err_type: ParseErrorTypes, | ||
start: usize, | ||
end: usize, | ||
source: &'a str, | ||
filename: &'a str, | ||
line_number: u64, | ||
) -> ParseError<'a> { | ||
ParseError { | ||
err_type, | ||
start, | ||
end, | ||
source, | ||
filename, | ||
line_number, | ||
} | ||
} | ||
pub fn new_from_parser<'a>(err_type: ParseErrorTypes, parser: &Parser<'a>) -> ParseError<'a> { | ||
ParseError { | ||
err_type, | ||
start: parser.last_bracket_start, | ||
end: parser.prev_token_end, | ||
source: parser.source, | ||
filename: &parser.filename, | ||
line_number: parser.lexer.cur_line, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> fmt::Display for ParseError<'a> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let err_msg = match self.err_type { | ||
ParseErrorTypes::UnexpectedFilterArgumentToken => { | ||
"Unexpected character in filter argument" | ||
} | ||
ParseErrorTypes::UnclosedBracket => "Unclosed bracket", | ||
ParseErrorTypes::DoubleDot => "Double dot", | ||
ParseErrorTypes::DoubleString => "Double string", | ||
}; | ||
let mut str = "".to_string(); | ||
|
||
let span = self.source.get(self.start..self.end).unwrap_or(""); | ||
|
||
for line in span.lines() { | ||
str.push_str(&format!("{} \x1b[94m|\x1b[0m {}\n", self.line_number, line)) | ||
} | ||
|
||
write!( | ||
f, | ||
"\n\u{1b}[2;30;41m ERROR \u{1b}[0m\u{1b}[2;30;47m {} \u{1b}[0m\n\x1b[94m-->\x1b[0m {}:{}:{}\n{}\n", | ||
err_msg, self.filename, self.start, self.end, str, | ||
) | ||
|
||
// write!( | ||
// f, | ||
// "\n\u{1b}[1;31m[ERROR] {} {}..{}: {}:\u{1b}[0m\n{}\n", | ||
// self.filename, self.start, self.end, err_msg, span, | ||
// ) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum ParseErrorTypes { | ||
UnclosedBracket, | ||
DoubleDot, | ||
DoubleString, | ||
UnexpectedFilterArgumentToken, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod errors; | ||
pub mod lexer; | ||
pub mod node; | ||
pub mod parser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.