feat(tokenizer): add Token::Int & UnexpectedToken error type
This commit is contained in:
parent
faedfadeab
commit
71a9d82d96
5 changed files with 24 additions and 6 deletions
|
|
@ -212,7 +212,11 @@ i will use rustyline, since it seems like the most feature-complete
|
|||
|
||||
* DONE remove uneeded error variants
|
||||
|
||||
* TODO cli tests using insta-cmd
|
||||
* STRT parse integers
|
||||
|
||||
* TODO parse strings
|
||||
|
||||
* WAIT cli tests using insta-cmd
|
||||
https://insta.rs/docs/cmd/
|
||||
|
||||
* WAIT autocompletion
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::meta_commands::{MetaCommand, MetaCommandExecuteResult};
|
||||
use crate::statements::{Statement, StatementExecuteResult};
|
||||
use crate::tokens::ScanError;
|
||||
use crate::tokens::{ScanError, Token};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Command {
|
||||
|
|
@ -50,6 +50,7 @@ impl Command {
|
|||
#[derive(Debug)]
|
||||
pub enum CommandParseError {
|
||||
Scan(ScanError),
|
||||
UnexpectedToken(Token, &'static [&'static str]),
|
||||
}
|
||||
|
||||
impl From<MetaCommand> for Command {
|
||||
|
|
|
|||
|
|
@ -7,9 +7,13 @@ pub trait OSDBError {
|
|||
|
||||
impl OSDBError for CommandParseError {
|
||||
fn display(&self, file: &str, input: &str) {
|
||||
let CommandParseError::Scan(x) = self;
|
||||
match self {
|
||||
CommandParseError::Scan(x) => {
|
||||
x.display(file, input);
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OSDBError for ScanError {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub fn parse(file: String, input: String) -> Result<Vec<Command>, Vec<CommandPar
|
|||
.map_err(|x| x.into_iter().map(|x| x.into()).collect::<Vec<_>>())?
|
||||
.into();
|
||||
let mut cmds = Vec::new();
|
||||
let errs = Vec::new();
|
||||
let mut errs = Vec::new();
|
||||
while let Some(token) = tokens.pop_front() {
|
||||
match token.data {
|
||||
crate::tokens::TokenData::Insert => cmds.push(Command::Statement(Statement::Insert)),
|
||||
|
|
@ -19,10 +19,18 @@ pub fn parse(file: String, input: String) -> Result<Vec<Command>, Vec<CommandPar
|
|||
crate::tokens::TokenData::MetaCommand(meta_command) => {
|
||||
cmds.push(Command::MetaCommand(meta_command))
|
||||
}
|
||||
crate::tokens::TokenData::Int(_) => errs.push(CommandParseError::UnexpectedToken(
|
||||
token,
|
||||
&["statement", "meta command", "eof"],
|
||||
)),
|
||||
crate::tokens::TokenData::EndOfFile => (),
|
||||
}
|
||||
}
|
||||
if errs.is_empty() { Ok(cmds) } else { Err(errs) }
|
||||
if errs.is_empty() {
|
||||
Ok(cmds)
|
||||
} else {
|
||||
Err(errs)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ pub enum TokenData {
|
|||
Select,
|
||||
MetaCommand(MetaCommand),
|
||||
EndOfFile,
|
||||
Int(i64),
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue