brine_kiwi_compiler/utils.rs
1use crate::error::KiwiError;
2use serde_json;
3
4/// Quote a string as JSON (so that things like newlines, quotes, etc. are escaped).
5pub fn quote(text: &str) -> String {
6 serde_json::to_string(text).unwrap()
7}
8
9/// Return a KiwiError::ParseError.
10/// Callers should do something like `return Err(error("msg", line, col));`
11pub fn error(msg: &str, line: usize, column: usize) -> KiwiError {
12 KiwiError::ParseError {
13 msg: msg.to_string(),
14 line,
15 column,
16 }
17}