Skip to content

Commit

Permalink
Problem: PumpkinScript has no comments
Browse files Browse the repository at this point in the history
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 PumpkinDB#78
  • Loading branch information
yrashk committed Feb 20, 2017
1 parent 65fd086 commit 86db94d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/script/textparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ named!(string<Vec<u8>>, alt!(do_parse!(tag!(b"\"\"") >> (vec![0])) |
named!(code<Vec<u8>>, do_parse!(
prog: delimited!(char!('['), ws!(program), char!(']')) >>
(sized_vec(prog))));
named!(item<Vec<u8>>, alt!(binary | string | uint | code | wordref | word));
named!(comment<Vec<u8>>, do_parse!(delimited!(char!('('), is_not!(")"), char!(')')) >> (vec![])));
named!(item<Vec<u8>>, alt!(comment | binary | string | uint | code | wordref | word));
named!(program<Vec<u8>>, alt!(do_parse!(
take_while!(is_multispace) >>
v: eof >>
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 86db94d

Please sign in to comment.