Skip to content

Commit 148c59b

Browse files
committed
Reject multiline Pine comments
1 parent bd4220f commit 148c59b

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/pinescript_validator/lexer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,35 @@ def _scan_block_comment(self) -> None:
254254
start = self.pos - 1
255255
start_line = self.line
256256
start_column = self.column - 1
257+
terminated = False
257258
self._advance()
258259
while not self._is_at_end():
259260
if self._peek() == "*" and self._peek_next() == "/":
260261
self._advance()
261262
self._advance()
263+
terminated = True
262264
break
263265
if self._peek() == "\n":
264266
self.line += 1
265267
self.column = 1
266268
self._advance()
269+
self.errors.append(
270+
LexerError(
271+
message="Pine Script does not support multiline comments. Use '//' comments instead.",
272+
line=start_line,
273+
column=start_column,
274+
length=2,
275+
)
276+
)
277+
if not terminated:
278+
self.errors.append(
279+
LexerError(
280+
message="Unterminated multiline comment",
281+
line=start_line,
282+
column=start_column,
283+
length=max(2, self.pos - start),
284+
)
285+
)
267286
value = self.source[start:self.pos]
268287
self._add_token_with_position(
269288
TokenType.COMMENT,

tests/test_validator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ def test_comment_does_not_trigger_function_error(self) -> None:
190190
diagnostics = self.validator.validate_text("x = 1 // no reclaim (close sweep)")
191191
self.assertFalse(any("Undefined function 'reclaim'" in diagnostic.message for diagnostic in diagnostics))
192192

193+
def test_multiline_comment_is_rejected(self) -> None:
194+
diagnostics = self.validator.validate_text("/*\nblock\n*/\nindicator(\"x\")")
195+
self.assertTrue(
196+
any(
197+
"Pine Script does not support multiline comments. Use '//' comments instead." in diagnostic.message
198+
for diagnostic in diagnostics
199+
)
200+
)
201+
193202
def test_generic_function_call_and_dotted_array_type(self) -> None:
194203
code = "var chart.point[] _points = array.new<chart.point>()"
195204
diagnostics = self.validator.validate_text(code)

0 commit comments

Comments
 (0)