mirror of
https://github.com/tweag/nickel.git
synced 2024-11-10 10:46:49 +03:00
Support line comments
This commit is contained in:
parent
edb90e6fa6
commit
17af56f7c5
@ -234,6 +234,8 @@ pub enum NormalToken<'input> {
|
||||
RAngleBracket,
|
||||
#[token(">=")]
|
||||
GreaterOrEq,
|
||||
#[regex("//[^\n]*")]
|
||||
LineComment,
|
||||
}
|
||||
|
||||
/// The tokens in string mode.
|
||||
@ -542,6 +544,8 @@ impl<'input> Iterator for Lexer<'input> {
|
||||
| Some(MultiStr(MultiStringToken::Error)) => {
|
||||
return Some(Err(LexicalError::Generic(span.start, span.end)))
|
||||
}
|
||||
// Ignore comment
|
||||
Some(Normal(NormalToken::LineComment)) => return self.next(),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
@ -294,3 +294,19 @@ fn multiline_str_escape() {
|
||||
mk_single_chunk("#Hel##{lo###{"),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line_comments() {
|
||||
assert_eq!(
|
||||
parse_without_pos("// 1 +\n1 + 1// + 3\n//+ 2"),
|
||||
parse_without_pos("1 + 1")
|
||||
);
|
||||
assert_eq!(
|
||||
parse_without_pos(
|
||||
"{ // Some comment
|
||||
field = foo; // Some description
|
||||
} // Some other"
|
||||
),
|
||||
parse_without_pos("{field = foo}")
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user