diff --git a/compiler/erg_parser/lex.rs b/compiler/erg_parser/lex.rs index b7700f8f..45af3be8 100644 --- a/compiler/erg_parser/lex.rs +++ b/compiler/erg_parser/lex.rs @@ -323,6 +323,8 @@ impl Lexer /*<'a>*/ { (']', '#') => { nest_level -= 1; if nest_level == 0 { + self.consume(); // ] + self.consume(); // # return Ok(()); } } @@ -448,8 +450,7 @@ impl Lexer /*<'a>*/ { if let Err(e) = self.lex_multi_line_comment() { return Some(Err(e)); } - } - if let Err(e) = self.lex_comment() { + } else if let Err(e) = self.lex_comment() { return Some(Err(e)); } } @@ -1059,8 +1060,7 @@ impl Iterator for Lexer /*<'a>*/ { if let Err(e) = self.lex_multi_line_comment() { return Some(Err(e)); } - } - if let Err(e) = self.lex_comment() { + } else if let Err(e) = self.lex_comment() { return Some(Err(e)); } } diff --git a/tests/should_ok/comment.er b/tests/should_ok/comment.er new file mode 100644 index 00000000..306824c1 --- /dev/null +++ b/tests/should_ok/comment.er @@ -0,0 +1,11 @@ +#[]#print! "hi"#[ if there isn't `;`, this code is evaluated `print! "hi"h print! "there"` +]#;print! "there" +print! #[]#0, 1#[]#, 2,#[]#3 +a = { + #[first]#name #[second]#=#[third]#"John"#[fouth]# +} +Del a +#[]#print! 0 +print!#[]#1 +#[]#print! 2#[ +]# \ No newline at end of file diff --git a/tests/test.rs b/tests/test.rs index b639df1a..a79ab89c 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -224,3 +224,8 @@ fn exec_callable() -> Result<(), ()> { fn exec_multiline_invalid_next() -> Result<(), ()> { expect_failure("tests/should_err/multi_line_invalid_nest.er", 1) } + +#[test] +fn exec_comment() -> Result<(), ()> { + expect_success("tests/should_ok/comment.er") +}