Skip to content

Commit 883219d

Browse files
committed
simplify single quote usage; tag 0.2.1
1 parent 89b77f9 commit 883219d

File tree

7 files changed

+91
-77
lines changed

7 files changed

+91
-77
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[package]
33
name = "cirru_parser"
4-
version = "0.2.0"
4+
version = "0.2.1"
55
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
66
edition = "2024"
77
license = "MIT"

examples/test_escape_debug.rs

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,77 @@
33
use cirru_parser::{parse, print_error};
44

55
fn main() {
6-
println!("🔍 Testing escape_debug in error messages\n");
7-
println!("{}\n", "═".repeat(70));
6+
println!("🔍 Testing escape_debug in error messages\n");
7+
println!("{}\n", "═".repeat(70));
88

9-
// Test 1: Newline in string
10-
println!("Test 1: Newline character in string");
11-
let code1 = "defn test\n print \"hello\nworld\"";
12-
println!("Code: {code1:?}\n");
13-
if let Err(e) = parse(code1) {
14-
print_error(&e, Some(code1));
15-
}
16-
println!("\n{}\n", "─".repeat(70));
9+
// Test 1: Newline in string
10+
println!("Test 1: Newline character in string");
11+
let code1 = "defn test\n print \"hello\nworld\"";
12+
println!("Code: {code1:?}\n");
13+
if let Err(e) = parse(code1) {
14+
print_error(&e, Some(code1));
15+
}
16+
println!("\n{}\n", "─".repeat(70));
1717

18-
// Test 2: Tab indentation error
19-
println!("Test 2: Tab character causing indentation issue");
20-
let code2 = "defn test\n\tabc"; // Tab character
21-
println!("Code: {code2:?}\n");
22-
if let Err(e) = parse(code2) {
23-
print_error(&e, Some(code2));
24-
}
25-
println!("\n{}\n", "─".repeat(70));
18+
// Test 2: Tab indentation error
19+
println!("Test 2: Tab character causing indentation issue");
20+
let code2 = "defn test\n\tabc"; // Tab character
21+
println!("Code: {code2:?}\n");
22+
if let Err(e) = parse(code2) {
23+
print_error(&e, Some(code2));
24+
}
25+
println!("\n{}\n", "─".repeat(70));
2626

27-
// Test 3: Multiple spaces (odd indentation)
28-
println!("Test 3: Odd number of spaces (visible with escape_debug)");
29-
let code3 = "defn test\n abc\n def"; // 3 spaces
30-
println!("Code: {code3:?}\n");
31-
if let Err(e) = parse(code3) {
32-
print_error(&e, Some(code3));
33-
}
34-
println!("\n{}\n", "─".repeat(70));
27+
// Test 3: Multiple spaces (odd indentation)
28+
println!("Test 3: Odd number of spaces (visible with escape_debug)");
29+
let code3 = "defn test\n abc\n def"; // 3 spaces
30+
println!("Code: {code3:?}\n");
31+
if let Err(e) = parse(code3) {
32+
print_error(&e, Some(code3));
33+
}
34+
println!("\n{}\n", "─".repeat(70));
3535

36-
// Test 4: Mixed whitespace
37-
println!("Test 4: Carriage return in string");
38-
let code4 = "print \"hello\rworld\"";
39-
println!("Code: {code4:?}\n");
40-
match parse(code4) {
41-
Ok(_) => println!("✅ Parsed successfully (\\r is valid in identifier)"),
42-
Err(e) => print_error(&e, Some(code4)),
43-
}
44-
println!("\n{}\n", "─".repeat(70));
36+
// Test 4: Mixed whitespace
37+
println!("Test 4: Carriage return in string");
38+
let code4 = "print \"hello\rworld\"";
39+
println!("Code: {code4:?}\n");
40+
match parse(code4) {
41+
Ok(_) => println!("✅ Parsed successfully (\\r is valid in identifier)"),
42+
Err(e) => print_error(&e, Some(code4)),
43+
}
44+
println!("\n{}\n", "─".repeat(70));
4545

46-
// Test 5: Long line with special chars
47-
println!("Test 5: Long line with special characters and error");
48-
let code5 = "defn process-long-text (data)\n let result \"This is a very long string with \\t tabs and \\n newlines \\x error\"";
49-
println!("Code: {code5:?}\n");
50-
if let Err(e) = parse(code5) {
51-
print_error(&e, Some(code5));
52-
}
53-
println!("\n{}\n", "─".repeat(70));
46+
// Test 5: Long line with special chars
47+
println!("Test 5: Long line with special characters and error");
48+
let code5 = "defn process-long-text (data)\n let result \"This is a very long string with \\t tabs and \\n newlines \\x error\"";
49+
println!("Code: {code5:?}\n");
50+
if let Err(e) = parse(code5) {
51+
print_error(&e, Some(code5));
52+
}
53+
println!("\n{}\n", "─".repeat(70));
5454

55-
// Test 6: Unicode with newline
56-
println!("Test 6: Unicode escape with newline nearby");
57-
let code6 = "print \"emoji \\u{1F600}\ntext\"";
58-
println!("Code: {code6:?}\n");
59-
if let Err(e) = parse(code6) {
60-
print_error(&e, Some(code6));
61-
}
62-
println!("\n{}\n", "─".repeat(70));
55+
// Test 6: Unicode with newline
56+
println!("Test 6: Unicode escape with newline nearby");
57+
let code6 = "print \"emoji \\u{1F600}\ntext\"";
58+
println!("Code: {code6:?}\n");
59+
if let Err(e) = parse(code6) {
60+
print_error(&e, Some(code6));
61+
}
62+
println!("\n{}\n", "─".repeat(70));
6363

64-
// Test 7: Indentation with spaces visible
65-
println!("Test 7: Clear space visualization");
66-
let code7 = "defn main\n line1\n line2\n line3"; // 5 spaces on line3
67-
println!("Code with explicit spaces: 'defn main\\n line1\\n line2\\n line3'\n");
68-
if let Err(e) = parse(code7) {
69-
print_error(&e, Some(code7));
70-
}
64+
// Test 7: Indentation with spaces visible
65+
println!("Test 7: Clear space visualization");
66+
let code7 = "defn main\n line1\n line2\n line3"; // 5 spaces on line3
67+
println!("Code with explicit spaces: 'defn main\\n line1\\n line2\\n line3'\n");
68+
if let Err(e) = parse(code7) {
69+
print_error(&e, Some(code7));
70+
}
7171

72-
println!("\n{}\n", "═".repeat(70));
73-
println!("✨ Now you can clearly see:");
74-
println!(" • \\n for newlines");
75-
println!(" • \\t for tabs");
76-
println!(" • Spaces are preserved and visible");
77-
println!(" • Special escape sequences are shown");
78-
println!(" • Context window is ~60 chars (increased from 40)");
72+
println!("\n{}\n", "═".repeat(70));
73+
println!("✨ Now you can clearly see:");
74+
println!(" • \\n for newlines");
75+
println!(" • \\t for tabs");
76+
println!(" • Spaces are preserved and visible");
77+
println!(" • Special escape sequences are shown");
78+
println!(" • Context window is ~60 chars (increased from 40)");
7979
}

src/primes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ pub fn escape_cirru_leaf(s: &str) -> String {
241241
'\t' => chunk.push_str("\\t"),
242242
'\"' => chunk.push_str("\\\""),
243243
'\\' => chunk.push_str("\\\\"),
244-
'\'' => chunk.push_str("\\'"),
245244
_ => chunk.push(c),
246245
}
247246
}

src/writer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ fn generate_leaf(s: &str) -> String {
8181
'\t' => ret.push_str("\\t"),
8282
'\"' => ret.push_str("\\\""),
8383
'\\' => ret.push_str("\\\\"),
84-
'\'' => ret.push_str("\\'"),
8584
_ => ret.push(c),
8685
}
8786
}

tests/parser_test.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@ mod json_test {
1111
fn parse_demo() {
1212
assert_eq!(parse("a").map(Cirru::List), Ok(Cirru::List(vec!(vec!["a"].into()))));
1313

14-
assert_eq!(
15-
parse("a b c").map(Cirru::List),
16-
Ok(Cirru::List(vec!(vec!["a", "b", "c"].into())))
17-
);
14+
assert_eq!(parse("a b c").map(Cirru::List), Ok(Cirru::List(vec!(vec!["a", "b", "c"].into()))));
1815

1916
assert_eq!(
2017
parse("a\nb").map(Cirru::List),
2118
Ok(Cirru::List(vec!(vec!["a"].into(), vec!["b"].into())))
2219
);
2320

24-
assert_eq!(
25-
parse("a\rb").map(Cirru::List),
26-
Ok(Cirru::List(vec!(vec!["a\rb"].into())))
27-
);
21+
assert_eq!(parse("a\rb").map(Cirru::List), Ok(Cirru::List(vec!(vec!["a\rb"].into()))));
2822

2923
assert_eq!(
3024
parse("a (b) c").map(Cirru::List),

tests/writer_test.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,28 @@ fn leaves_escapeing() {
123123
assert_eq!("\"中文\\n\"", escape_cirru_leaf("中文\n"));
124124
}
125125

126+
#[test]
127+
fn leaf_single_quote_without_quotes() -> Result<(), String> {
128+
use cirru_parser::{Cirru, CirruWriterOptions, format};
129+
130+
let xs = vec![Cirru::List(vec![Cirru::leaf("foo'bar")])];
131+
let rendered = format(&xs, CirruWriterOptions::from(false))?;
132+
133+
assert_eq!("\nfoo'bar\n", rendered);
134+
Ok(())
135+
}
136+
137+
#[test]
138+
fn leaf_single_quote_with_spaces_requires_quotes() -> Result<(), String> {
139+
use cirru_parser::{Cirru, CirruWriterOptions, format};
140+
141+
let xs = vec![Cirru::List(vec![Cirru::leaf("foo bar'baz")])];
142+
let rendered = format(&xs, CirruWriterOptions::from(false))?;
143+
144+
assert_eq!("\n\"foo bar'baz\"\n", rendered);
145+
Ok(())
146+
}
147+
126148
#[test]
127149
fn test_writer_options_from_bool() -> Result<(), String> {
128150
use cirru_parser::{Cirru, CirruWriterOptions, format};

0 commit comments

Comments
 (0)