From 100d48deae36ef34cf6e05b0bf2dd8d921160262 Mon Sep 17 00:00:00 2001 From: nick_battle Date: Fri, 5 Feb 2021 10:52:52 +0000 Subject: [PATCH] Allow nested block comments, fixes #774 --- .../overture/parser/lex/LexTokenReader.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/core/parser/src/main/java/org/overture/parser/lex/LexTokenReader.java b/core/parser/src/main/java/org/overture/parser/lex/LexTokenReader.java index bdc09b1958..6d5f3521e7 100644 --- a/core/parser/src/main/java/org/overture/parser/lex/LexTokenReader.java +++ b/core/parser/src/main/java/org/overture/parser/lex/LexTokenReader.java @@ -929,10 +929,11 @@ else if (ch == '>') StringBuilder sb = new StringBuilder(); rdCh(); ILexLocation here = location(linecount, charpos, tokline, tokpos); + int nestedCount = 0; while (ch != EOF) { - while (ch != '*' && ch != EOF) + while (ch != '*' && ch != '/' && ch != EOF) { sb.append(ch); rdCh(); @@ -942,11 +943,32 @@ else if (ch == '>') { throwMessage(1011, tokline, tokpos, "Unterminated block comment"); } + else if (ch == '/') + { + sb.append('/'); + + if (rdCh() == '*') + { + nestedCount++; + sb.append('*'); + rdCh(); + } + } else { if (rdCh() == '/') { - break; + if (nestedCount == 0) + { + break; + } + else + { + nestedCount--; + sb.append('*'); + sb.append('/'); + rdCh(); + } } else {