Added semicolon support to combine several statements in one line.

This commit is contained in:
PaddiM8 2020-06-14 22:03:22 +02:00
parent c21977a131
commit 80690a5575
2 changed files with 7 additions and 1 deletions

View File

@ -27,6 +27,7 @@ pub enum TokenKind {
OpenParenthesis,
ClosedParenthesis,
Comma,
Semicolon,
EOF,
}
@ -105,6 +106,7 @@ impl<'a> Lexer<'a> {
'=' => build(TokenKind::Equals, "", span),
'!' => build(TokenKind::Exclamation, "", span),
',' => build(TokenKind::Comma, "", span),
';' => build(TokenKind::Semicolon, "", span),
_ => build(TokenKind::Unknown, "", span),
};
@ -196,7 +198,7 @@ fn build(kind: TokenKind, value: &str, span: (usize, usize)) -> Token {
fn is_valid_identifier(c: Option<&char>) -> bool {
if let Some(c) = c {
regex::Regex::new(r"[^\s\n\r0-9\+-/\*\^!\(\)=\.,|⌊⌋⌈⌉]")
regex::Regex::new(r"[^\s\n\r0-9\+-/\*\^!\(\)=\.,;|⌊⌋⌈⌉]")
.unwrap()
.is_match(&c.to_string())
} else {

View File

@ -89,6 +89,10 @@ pub fn parse(context: &mut Context, input: &str) -> Result<Vec<Stmt>, CalcError>
let mut statements: Vec<Stmt> = Vec::new();
while !is_at_end(context) {
statements.push(parse_stmt(context)?);
if match_token(context, TokenKind::Semicolon) {
advance(context);
}
}
Ok(statements)