Skip to content

Commit 171d45b

Browse files
committed
handle quote syntax in ClojureScript
1 parent 3e7c246 commit 171d45b

File tree

1 file changed

+69
-0
lines changed
  • crates/oxide/src/extractor/pre_processors

1 file changed

+69
-0
lines changed

crates/oxide/src/extractor/pre_processors/clojure.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,75 @@ impl PreProcessor for Clojure {
108108
}
109109
}
110110

111+
// Handle quote with a list, e.g.: `'(…)`
112+
// and with a vector, e.g.: `'[…]`
113+
b'\'' if matches!(cursor.next, b'[' | b'(') => {
114+
result[cursor.pos] = b' ';
115+
cursor.advance();
116+
result[cursor.pos] = b' ';
117+
let end = match cursor.curr {
118+
b'[' => b']',
119+
b'(' => b')',
120+
_ => unreachable!(),
121+
};
122+
123+
// Consume until the closing `]`
124+
while cursor.pos < len {
125+
match cursor.curr {
126+
x if x == end => {
127+
result[cursor.pos] = b' ';
128+
break;
129+
}
130+
131+
// Consume strings as-is
132+
b'"' => {
133+
result[cursor.pos] = b' ';
134+
cursor.advance();
135+
136+
while cursor.pos < len {
137+
match cursor.curr {
138+
// Escaped character, skip ahead to the next character
139+
b'\\' => cursor.advance_twice(),
140+
141+
// End of the string
142+
b'"' => {
143+
result[cursor.pos] = b' ';
144+
break;
145+
}
146+
147+
// Everything else is valid
148+
_ => cursor.advance(),
149+
};
150+
}
151+
}
152+
_ => {}
153+
};
154+
155+
cursor.advance();
156+
}
157+
}
158+
159+
// Handle quote with a keyword, e.g.: `'bg-white`
160+
b'\'' if !cursor.next.is_ascii_whitespace() => {
161+
result[cursor.pos] = b' ';
162+
cursor.advance();
163+
164+
while cursor.pos < len {
165+
match cursor.curr {
166+
// End of keyword.
167+
_ if !is_keyword_character(cursor.curr) => {
168+
result[cursor.pos] = b' ';
169+
break;
170+
}
171+
172+
// Consume everything else.
173+
_ => {}
174+
};
175+
176+
cursor.advance();
177+
}
178+
}
179+
111180
// Aggressively discard everything else, reducing false positives and preventing
112181
// characters surrounding keywords from producing false negatives.
113182
// E.g.:

0 commit comments

Comments
 (0)