From 86db94d7d910054a17e314a79abae06d1d01d16d Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Mon, 20 Feb 2017 10:30:06 +0700 Subject: [PATCH] Problem: PumpkinScript has no comments Sometimes it's nice to annotate your code Solution: use () to denote comments. Anything enclosed there is considered a comment and will not get interpreted. Fixes #78 --- src/script/textparser.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/script/textparser.rs b/src/script/textparser.rs index 5d71024..98aa430 100644 --- a/src/script/textparser.rs +++ b/src/script/textparser.rs @@ -144,7 +144,8 @@ named!(string>, alt!(do_parse!(tag!(b"\"\"") >> (vec![0])) | named!(code>, do_parse!( prog: delimited!(char!('['), ws!(program), char!(']')) >> (sized_vec(prog)))); -named!(item>, alt!(binary | string | uint | code | wordref | word)); +named!(comment>, do_parse!(delimited!(char!('('), is_not!(")"), char!(')')) >> (vec![]))); +named!(item>, alt!(comment | binary | string | uint | code | wordref | word)); named!(program>, alt!(do_parse!( take_while!(is_multispace) >> v: eof >> @@ -221,6 +222,18 @@ mod tests { assert_eq!(script, script_multiline); } + #[test] + fn test_comment() { + let script = parse("1 (hello) 2").unwrap(); + assert_eq!(script, parse("1 2").unwrap()); + } + + #[test] + fn test_multiline_comment() { + let script = parse("1 (hel\nlo) 2").unwrap(); + assert_eq!(script, parse("1 2").unwrap()); + } + #[test] fn superfluous() { assert!(parse("HELP [DROP]]").is_err());