Skip to content

Commit

Permalink
Replace panic for unimplemented syntax error, closes #33
Browse files Browse the repository at this point in the history
If token is not implemented show a error. Beside add dates syntax support.
  • Loading branch information
hbro23 committed Aug 30, 2020
1 parent d73c282 commit da75f38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lang/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum ErrorLang {
_0
)]
ExpectedBoolOp(Token),
#[display(fmt = "Unimplemented syntax. {:?}", _0)]
Unimplemented(Token),
#[display(fmt = "Unexpected EOF.")]
Eof,
}
Expand Down
12 changes: 11 additions & 1 deletion lang/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,21 @@ pub enum Token {
#[regex(r#""""[\w\d\s[^\s"{}]]+""""#)]
Multiline,
*/
//Dates
#[display(fmt = "DateTime")]
#[regex(r#"dt"\d\d\d\d-(0[1-9]|1[012])-([12][0-9]|3[01]|0[1-9])T([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]""#)]
DateTime,
#[display(fmt = "Date")]
#[regex(r#"d"\d\d\d\d-(0[1-9]|1[012])-([12][0-9]|3[01]|0[1-9])""#)]
Date,
#[display(fmt = "Time")]
#[regex(r#"t"[0-1][0-9]|2[0-3]:[0-5][0-9]:[0-5][0-9]""#)]
Time,

//Identifiers
#[display(fmt = "{}", _0)]
#[regex(r"[[:upper:]]+[_[[:upper:]][[:digit:]]]*", |lex| parse_token_data::<String>(lex))]
Constant(String),
#[display(fmt = "{}", _0)]
#[regex(r"[[:upper:]](?:[[[:lower:]][[:digit:]]]+[[:upper:]]*)+", |lex| parse_token_data::<String>(lex))]
Type(String),
#[display(fmt = "{}", _0)]
Expand Down
2 changes: 1 addition & 1 deletion lang/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl<'source> Parser<'source> {
Column::Alias(Box::new(ColumnAlias::rename_name(&alias.from, &alias.to))).into()
}
Token::If => self.parse_if()?,
t => panic!("bad token: {:?}", t),
token => return Err(ErrorLang::Unimplemented(token.clone())),
};
Ok(expr)
}
Expand Down

0 comments on commit da75f38

Please sign in to comment.