From 1801afdbd0058cc9cc040b977de0d5652d65aab9 Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Sun, 10 May 2026 12:47:18 +0300 Subject: Remove Quote from parser Dropped to make the language simpler. --- compiler/src/lex/lexer.rs | 6 +---- compiler/src/lex/tests.rs | 63 ----------------------------------------------- compiler/src/lex/token.rs | 1 - 3 files changed, 1 insertion(+), 69 deletions(-) (limited to 'compiler/src/lex') diff --git a/compiler/src/lex/lexer.rs b/compiler/src/lex/lexer.rs index 801d382..6efbca0 100644 --- a/compiler/src/lex/lexer.rs +++ b/compiler/src/lex/lexer.rs @@ -4,7 +4,7 @@ use crate::{ }; fn is_terminator(ch: char) -> bool { - ch.is_whitespace() || matches!(ch, '(' | ')' | '\'' | '"' | ';') + ch.is_whitespace() || matches!(ch, '(' | ')' | '"' | ';') } pub struct Lexer<'a> { @@ -128,10 +128,6 @@ impl<'a> Iterator for Lexer<'a> { self.consume(); Token::RightPar } - '\'' => { - self.consume(); - Token::Quote - } // Number ch if ch.is_ascii_digit() diff --git a/compiler/src/lex/tests.rs b/compiler/src/lex/tests.rs index 2d872a2..d0ed658 100644 --- a/compiler/src/lex/tests.rs +++ b/compiler/src/lex/tests.rs @@ -37,24 +37,6 @@ fn test_parens() { } } -#[test] -fn test_quote() { - let cases = vec![ - ("'", vec![Quote]), - ("'a", vec![Quote, Symbol("a")]), - ("''a", vec![Quote, Quote, Symbol("a")]), - ("'()", vec![Quote, LeftPar, RightPar]), - ( - "'(1 2)", - vec![Quote, LeftPar, Number("1"), Number("2"), RightPar], - ), - ("(' )", vec![LeftPar, Quote, RightPar]), - ]; - for (code, tokens) in cases { - assert_eq!(tokenize(code), tokens); - } -} - #[test] fn test_numbers() { let cases = vec![ @@ -83,7 +65,6 @@ fn test_strings() { (r#""hello""#, vec![String("hello")]), (r#""hello world""#, vec![String("hello world")]), (r#""(not a list)""#, vec![String("(not a list)")]), - (r#""'not a quote""#, vec![String("'not a quote")]), (r#""; not a comment""#, vec![String("; not a comment")]), (r#"" spaces ""#, vec![String(" spaces ")]), ]; @@ -96,7 +77,6 @@ fn test_strings() { fn test_string_escapes() { let cases = vec![ (r#""line\nbreak""#, vec![String(r"line\nbreak")]), - (r#""with \"quotes\"""#, vec![String(r#"with \"quotes\""#)]), (r#""\\""#, vec![String(r"\\")]), ("\"single\\\nline\"", vec![String("single\\\nline")]), ]; @@ -169,7 +149,6 @@ fn test_no_separators() { ("(foo)", vec![LeftPar, Symbol("foo"), RightPar]), ("(1)", vec![LeftPar, Number("1"), RightPar]), ("(a)b", vec![LeftPar, Symbol("a"), RightPar, Symbol("b")]), - ("'(a)", vec![Quote, LeftPar, Symbol("a"), RightPar]), (r#"("s")"#, vec![LeftPar, String("s"), RightPar]), ]; for (code, tokens) in cases { @@ -211,23 +190,6 @@ fn test_expressions() { "(+ 1 2)", vec![LeftPar, Symbol("+"), Number("1"), Number("2"), RightPar], ), - ( - "(if (= x 0) 'zero 'nonzero)", - vec![ - LeftPar, - Symbol("if"), - LeftPar, - Symbol("="), - Symbol("x"), - Number("0"), - RightPar, - Quote, - Symbol("zero"), - Quote, - Symbol("nonzero"), - RightPar, - ], - ), ( r#"(print "hello, world")"#, vec![LeftPar, Symbol("print"), String("hello, world"), RightPar], @@ -248,17 +210,6 @@ fn test_expressions() { RightPar, ], ), - ( - "'(1 2 3)", - vec![ - Quote, - LeftPar, - Number("1"), - Number("2"), - Number("3"), - RightPar, - ], - ), ]; for (code, tokens) in cases { assert_eq!(tokenize(code), tokens); @@ -367,17 +318,3 @@ fn test_span_after_comment() { let s = spans("; cm\nfoo"); assert_eq!(s, vec![(Pos::new(2, 0, 5), Pos::new(2, 3, 8))]); } - -#[test] -fn test_span_after_quote() { - // 'hello - // 0123456 - let s = spans("'hello"); - assert_eq!( - s, - vec![ - (Pos::new(1, 0, 0), Pos::new(1, 1, 1)), - (Pos::new(1, 1, 1), Pos::new(1, 6, 6)) - ] - ); -} diff --git a/compiler/src/lex/token.rs b/compiler/src/lex/token.rs index 2d07885..910c8ff 100644 --- a/compiler/src/lex/token.rs +++ b/compiler/src/lex/token.rs @@ -2,7 +2,6 @@ pub enum Token<'a> { LeftPar, RightPar, - Quote, Number(&'a str), String(&'a str), UnclosedString(&'a str), -- cgit v1.3