Fix single line comment

This commit is contained in:
dalance 2019-08-19 19:28:51 +09:00
parent 47a0d4f579
commit 74d637f511
2 changed files with 9 additions and 8 deletions

View File

@ -12,8 +12,12 @@ pub(crate) fn comment(s: Span) -> IResult<Span, Comment> {
#[packrat_parser] #[packrat_parser]
pub(crate) fn one_line_comment(s: Span) -> IResult<Span, Comment> { pub(crate) fn one_line_comment(s: Span) -> IResult<Span, Comment> {
let (s, a) = tag("//")(s)?; let (s, a) = tag("//")(s)?;
let (s, b) = is_not("\n")(s)?; let (s, b) = opt(is_not("\n"))(s)?;
let a = concat(a, b).unwrap(); let a = if let Some(b) = b {
concat(a, b).unwrap()
} else {
a
};
Ok(( Ok((
s, s,
Comment { Comment {

View File

@ -283,6 +283,7 @@ mod unit {
#[test] #[test]
fn test_comment() { fn test_comment() {
test!(comment, "// comment", Ok((_, _))); test!(comment, "// comment", Ok((_, _)));
test!(comment, "//", Ok((_, _)));
test!(comment, "/* comment\n\n */", Ok((_, _))); test!(comment, "/* comment\n\n */", Ok((_, _)));
} }
@ -15705,12 +15706,8 @@ mod spec {
fn debug() { fn debug() {
test!( test!(
source_text, source_text,
r##"`pragma protect encoding=(enctype="raw") r##"//aaa
`pragma protect data_method="x-caesar", data_keyname="rot13", begin //bbb"##,
`pragma protect
runtime_license=(library="lic.so",feature="runSecret",entry="chk", match=42)
`pragma protect end
"##,
Ok((_, _)) Ok((_, _))
); );
} }