summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2021-12-28 19:00:43 +0000
committerAdrian Thurston <thurston@colm.net>2021-12-28 19:02:27 +0000
commit841bd4cf20c9d512fa7a3c80326f0013ac2e3ced (patch)
tree3a8ce2d1b8d4c411cb271e1d75193a4bd08e98a0
parentf5116edb1e8773ea21e51e5d9644dcea173c9016 (diff)
downloadragel-841bd4cf20c9d512fa7a3c80326f0013ac2e3ced.tar.gz
test case verifying reset of ts after EOF
The ts var is currently getting set on EOF due to ragel 7 executing from-state actions on EOF. This is a regression from ragel 6. refs #76.
-rw-r--r--test/ragel.d/tsreset.rl57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/ragel.d/tsreset.rl b/test/ragel.d/tsreset.rl
new file mode 100644
index 00000000..77c35a78
--- /dev/null
+++ b/test/ragel.d/tsreset.rl
@@ -0,0 +1,57 @@
+/*
+ * @LANG: c++
+ */
+#include <cstdio>
+#include <cstdlib>
+#include <string>
+
+%%{
+ machine part_token;
+
+ main := |*
+ ' '+;
+ ',';
+ 'abcd' => { printf("token: %s\n", std::string(ts, te).c_str()); };
+ *|;
+}%%
+
+%% write data;
+
+int scan(const std::string &in)
+{
+ int cs = 0, act = 0;
+ const char *p = in.c_str();
+ const char *pe = in.c_str() + in.length();
+ const char *ts = nullptr, *te = nullptr;
+ const char *eof = pe;
+
+ %% write init;
+ %% write exec;
+
+ printf("done\n");
+
+ if (cs == part_token_error)
+ printf("Error near %zd\n", p-in.data());
+ else if(ts)
+ printf("offsets: ts %zd te: %zd pe: %zd\n", ts-in.data(), te-in.data(), pe-in.data());
+ else
+ printf("ts is null\n");
+
+ return EXIT_SUCCESS;
+}
+
+int main(int argc, char *argv[])
+{
+ printf("scan: %d\n", scan("abcd") );
+ printf("scan: %d\n", scan("abcd,ab") );
+}
+
+##### OUTPUT #####
+token: abcd
+done
+ts is null
+scan: 0
+token: abcd
+done
+offsets: ts 5 te: 5 pe: 7
+scan: 0