From aba4d3b0f738eb9623117a943204cf6937e01fc5 Mon Sep 17 00:00:00 2001 From: y Date: Mon, 2 Oct 2023 10:37:07 -0400 Subject: [PATCH] zkas: add square brackets to lexer (for arrays) --- src/zkas/lexer.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/zkas/lexer.rs b/src/zkas/lexer.rs index 627b1f745..f453fe273 100644 --- a/src/zkas/lexer.rs +++ b/src/zkas/lexer.rs @@ -20,7 +20,7 @@ use std::{io::Result, str::Chars}; use super::error::ErrorEmitter; -const SPECIAL_CHARS: [char; 7] = ['{', '}', '(', ')', ',', ';', '=']; +const SPECIAL_CHARS: [char; 9] = ['{', '}', '(', ')', '[', ']', ',', ';', '=']; fn is_letter(ch: char) -> bool { ch.is_ascii_lowercase() || ch.is_ascii_uppercase() || ch == '_' @@ -39,6 +39,8 @@ pub enum TokenType { RightBrace, LeftParen, RightParen, + LeftBracket, + RightBracket, Comma, Semicolon, Assign, @@ -244,6 +246,14 @@ impl<'a> Lexer<'a> { tokens.push(Token::new(")", TokenType::RightParen, lineno, column)); continue } + '[' => { + tokens.push(Token::new("[", TokenType::LeftBracket, lineno, column)); + continue + } + ']' => { + tokens.push(Token::new("]", TokenType::RightBracket, lineno, column)); + continue + } ',' => { tokens.push(Token::new(",", TokenType::Comma, lineno, column)); continue