mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-13 10:00:51 +01:00
Added semicolon support to combine several statements in one line.
This commit is contained in:
parent
c21977a131
commit
80690a5575
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user