Skip to content

Commit

Permalink
Added semicolon support to combine several statements in one line.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Jun 14, 2020
1 parent c21977a commit 80690a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kalk/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum TokenKind {
OpenParenthesis,
ClosedParenthesis,
Comma,
Semicolon,

EOF,
}
Expand Down Expand Up @@ -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),
};

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions kalk/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 80690a5

Please sign in to comment.