[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] libpoke, testsuite: Fix strings to handle backslash and newline
From: |
Mohammad-Reza Nabipoor |
Subject: |
[PATCH] libpoke, testsuite: Fix strings to handle backslash and newline chars |
Date: |
Fri, 20 Nov 2020 19:17:07 +0330 |
2020-11-20 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
* libpoke/pkl-lex.l (STRING): Fix regexp to escape backslash and
newline characters correctly.
* libpoke/pkl-trans.c (pkl_trans1_ps_string): Ignore `\<NEWLINE>`
escape sequence.
* testsuite/Makefile.am (EXTRA_DIST): Add new tests.
* testsuite/poke.pkl/string-diag-2.pk: New test.
* testsuite/poke.pkl/string-multiline-1.pk: Likewise.
* testsuite/poke.pkl/string-multiline-diag-1.pk: Likewise.
---
ChangeLog | 11 +++++++++++
libpoke/pkl-lex.l | 2 +-
libpoke/pkl-trans.c | 8 ++++++++
testsuite/Makefile.am | 3 +++
testsuite/poke.pkl/string-diag-2.pk | 5 +++++
testsuite/poke.pkl/string-multiline-1.pk | 7 +++++++
testsuite/poke.pkl/string-multiline-diag-1.pk | 6 ++++++
7 files changed, 41 insertions(+), 1 deletion(-)
create mode 100644 testsuite/poke.pkl/string-diag-2.pk
create mode 100644 testsuite/poke.pkl/string-multiline-1.pk
create mode 100644 testsuite/poke.pkl/string-multiline-diag-1.pk
diff --git a/ChangeLog b/ChangeLog
index 0da786de..c39a0950 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2020-11-20 Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
+
+ * libpoke/pkl-lex.l (STRING): Fix regexp to escape backslash and
+ newline characters correctly.
+ * libpoke/pkl-trans.c (pkl_trans1_ps_string): Ignore `\<NEWLINE>`
+ escape sequence.
+ * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
+ * testsuite/poke.pkl/string-diag-2.pk: New test.
+ * testsuite/poke.pkl/string-multiline-1.pk: Likewise.
+ * testsuite/poke.pkl/string-multiline-diag-1.pk: Likewise.
+
2020-11-19 Jose E. Marchesi <jemarch@gnu.org>
* libpoke/pvm.h: Prototype for pvm_call_closure.
diff --git a/libpoke/pkl-lex.l b/libpoke/pkl-lex.l
index 441e4f2d..d69069eb 100644
--- a/libpoke/pkl-lex.l
+++ b/libpoke/pkl-lex.l
@@ -126,7 +126,7 @@ BLANK [ \t]
LETTER [a-zA-Z]
FIELD_NAME {LETTER}[a-zA-Z0-9_]*
CHAR '(.|\\[ntr\\]|\\[0-7]|\\[0-7][0-7]|\\[0-7][0-7][0-7])'
-STRING \"([^"]|\\(.|\n))*\"
+STRING \"([^"\n\\]|\\(.|\n))*\"
HEXCST 0[xX][0-9a-fA-F][0-9a-fA-F_]*
BINCST 0[bB][01][01_]*
OCTCST 0[oO][0-7_]*
diff --git a/libpoke/pkl-trans.c b/libpoke/pkl-trans.c
index 69398da6..09837224 100644
--- a/libpoke/pkl-trans.c
+++ b/libpoke/pkl-trans.c
@@ -337,6 +337,9 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_string)
case 't':
case '"':
break;
+ case '\n':
+ string_length--;
+ break;
case 'x':
++p;
if (!isxdigit (p[0]))
@@ -371,6 +374,11 @@ PKL_PHASE_BEGIN_HANDLER (pkl_trans1_ps_string)
continue;
}
++p;
+ if (*p == '\n') {
+ --i;
+ continue;
+ }
+
/* octal escape sequence */
if (ISODIGIT (p[0]))
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 1e67da37..df396241 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -1443,6 +1443,9 @@ EXTRA_DIST = \
poke.pkl/sref-diag-1.pk \
poke.pkl/sref-diag-2.pk \
poke.pkl/string-diag-1.pk \
+ poke.pkl/string-diag-2.pk \
+ poke.pkl/string-multiline-1.pk \
+ poke.pkl/string-multiline-diag-1.pk \
poke.pkl/sref-func-1.pk \
poke.pkl/sref-func-2.pk \
poke.pkl/sref-func-3.pk \
diff --git a/testsuite/poke.pkl/string-diag-2.pk
b/testsuite/poke.pkl/string-diag-2.pk
new file mode 100644
index 00000000..3ddf2d37
--- /dev/null
+++ b/testsuite/poke.pkl/string-diag-2.pk
@@ -0,0 +1,5 @@
+/* { dg-do compile } */
+
+/* Due to a lexer bug, this was a valid string */
+
+var s = "\\" foo"; /* { dg-error "" } */
diff --git a/testsuite/poke.pkl/string-multiline-1.pk
b/testsuite/poke.pkl/string-multiline-1.pk
new file mode 100644
index 00000000..33ff32ec
--- /dev/null
+++ b/testsuite/poke.pkl/string-multiline-1.pk
@@ -0,0 +1,7 @@
+/* { dg-do run } */
+
+var str = "foo\
+bar";
+
+/* { dg-command { str} } */
+/* { dg-output "\"foobar\"" } */
diff --git a/testsuite/poke.pkl/string-multiline-diag-1.pk
b/testsuite/poke.pkl/string-multiline-diag-1.pk
new file mode 100644
index 00000000..7ea94456
--- /dev/null
+++ b/testsuite/poke.pkl/string-multiline-diag-1.pk
@@ -0,0 +1,6 @@
+/* { dg-do compile } */
+
+/* Normal strings cannot span over multiple lines */
+
+/* { dg-error "" } */ var s = "foo
+bar";
--
2.29.2
- [PATCH] libpoke, testsuite: Fix strings to handle backslash and newline chars,
Mohammad-Reza Nabipoor <=