Add function to uplc::parser for string escape

Was originally written as a way to fix a failing property test on the
  program_builder; but the program builder is now gone. This function
  is still useful to have around.
This commit is contained in:
KtorZ
2023-04-05 14:25:19 +02:00
parent cdff149b5e
commit 057102c491

View File

@@ -55,6 +55,21 @@ fn pair_sub_type(type_info: Option<&Type>) -> Option<(&Type, &Type)> {
} }
} }
pub fn escape(string: &str) -> String {
string
.chars()
.flat_map(|c| match c {
'\n' => vec!['\\', c],
'\r' => vec!['\\', c],
'\t' => vec!['\\', c],
'\'' => vec!['\\', c],
'\\' => vec!['\\', c],
'"' => vec!['\\', c],
_ => vec![c],
})
.collect::<String>()
}
peg::parser! { peg::parser! {
grammar uplc() for str { grammar uplc() for str {
pub rule program() -> Program<Name> pub rule program() -> Program<Name>