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:
parent
cdff149b5e
commit
057102c491
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue