[COMMITTED] algol68: make lexer skip string/character denotations within nestable comments
Jose E. Marchesi
jemarch@gnu.org
Wed May 21 01:48:48 GMT 2025
---
gcc/algol68/a68-parser-scanner.cc | 27 ++++++++++++++-----
.../compile/error-nested-comment-1.a68 | 6 +++++
.../algol68/compile/nested-comment-1.a68 | 4 +++
.../algol68/compile/nested-comment-2.a68 | 6 +++++
gcc/testsuite/algol68/compile/snobol.a68 | 2 +-
5 files changed, 37 insertions(+), 8 deletions(-)
create mode 100644 gcc/testsuite/algol68/compile/error-nested-comment-1.a68
create mode 100644 gcc/testsuite/algol68/compile/nested-comment-1.a68
create mode 100644 gcc/testsuite/algol68/compile/nested-comment-2.a68
diff --git a/gcc/algol68/a68-parser-scanner.cc b/gcc/algol68/a68-parser-scanner.cc
index a9e986c46f1..88be8250ecf 100644
--- a/gcc/algol68/a68-parser-scanner.cc
+++ b/gcc/algol68/a68-parser-scanner.cc
@@ -552,7 +552,16 @@ skip_comment (LINE_T **top, char **ch, int delim)
{
while (v[0] != NULL_CHAR)
{
- if (is_bold (v, "COMMENT") && delim == BOLD_COMMENT_SYMBOL)
+ LINE_T *l = u;
+ char *c = v;
+
+ if (v[0] == QUOTE_CHAR && skip_string (&l, &c)
+ && (delim == BOLD_COMMENT_BEGIN_SYMBOL || delim == BRIEF_COMMENT_BEGIN_SYMBOL))
+ {
+ u = l;
+ v = c;
+ }
+ else if (is_bold (v, "COMMENT") && delim == BOLD_COMMENT_SYMBOL)
{
*top = u;
*ch = &v[1];
@@ -1230,7 +1239,7 @@ pragment (int type, LINE_T **ref_l, char **ref_c)
term_s_length = (int) strlen (term_s);
/* Scan for terminator. */
- bool nestable = (beg_s != NO_TEXT);
+ bool nestable_comment = (beg_s != NO_TEXT);
int nesting_level = 1;
INIT_BUFFER;
stop = false;
@@ -1238,8 +1247,11 @@ pragment (int type, LINE_T **ref_l, char **ref_c)
{
SCAN_ERROR (c == STOP_CHAR, start_l, start_c,
"unterminated pragment");
- /* A ".." or '..' delimited string in a PRAGMAT. */
- if (pragmat && (c == QUOTE_CHAR || c == '\''))
+
+ /* A ".." or '..' delimited string in a PRAGMAT, or
+ a ".." in a nestable comment. */
+ if ((pragmat && (c == QUOTE_CHAR || c == '\''))
+ || (nestable_comment && c == QUOTE_CHAR))
{
char delim = c;
bool eos = false;
@@ -1248,7 +1260,8 @@ pragment (int type, LINE_T **ref_l, char **ref_c)
while (!eos)
{
SCAN_ERROR (EOL (c), start_l, start_c,
- "string exceeds end of line");
+ "string within pragment exceeds end of line");
+
if (c == delim)
{
ADD_ONE_CHAR (delim);
@@ -1276,7 +1289,7 @@ pragment (int type, LINE_T **ref_l, char **ref_c)
else if (ISPRINT (c) || ISSPACE (c))
ADD_ONE_CHAR (c);
- if (nestable && chars_in_buf >= beg_s_length)
+ if (nestable_comment && chars_in_buf >= beg_s_length)
{
/* If we find another instance of the nestable begin mark, bump the
nesting level and continue scanning. */
@@ -1295,7 +1308,7 @@ pragment (int type, LINE_T **ref_l, char **ref_c)
if (strcmp (term_s,
&(A68_PARSER (scan_buf)[chars_in_buf - term_s_length])) == 0)
{
- if (nestable)
+ if (nestable_comment)
{
gcc_assert (nesting_level > 0);
nesting_level -= 1;
diff --git a/gcc/testsuite/algol68/compile/error-nested-comment-1.a68 b/gcc/testsuite/algol68/compile/error-nested-comment-1.a68
new file mode 100644
index 00000000000..3c78f34a51a
--- /dev/null
+++ b/gcc/testsuite/algol68/compile/error-nested-comment-1.a68
@@ -0,0 +1,6 @@
+{ The string in nested comment is in one logical line. }
+begin
+ { puts ("{'n { dg-error {} }
+"); { this prints foo }}
+ skip
+end
diff --git a/gcc/testsuite/algol68/compile/nested-comment-1.a68 b/gcc/testsuite/algol68/compile/nested-comment-1.a68
new file mode 100644
index 00000000000..f5752435a0e
--- /dev/null
+++ b/gcc/testsuite/algol68/compile/nested-comment-1.a68
@@ -0,0 +1,4 @@
+{ Comment delimiters within strings get ignored. }
+begin { puts { ("{""'n"); } }
+ skip
+end
diff --git a/gcc/testsuite/algol68/compile/nested-comment-2.a68 b/gcc/testsuite/algol68/compile/nested-comment-2.a68
new file mode 100644
index 00000000000..9fc912f2687
--- /dev/null
+++ b/gcc/testsuite/algol68/compile/nested-comment-2.a68
@@ -0,0 +1,6 @@
+{ The string in nested comment is in one logical line. }
+begin
+ { puts ("{'n\
+"); { this prints foo }}
+ skip
+end
More information about the Algol68
mailing list