summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2015-04-26 15:47:16 -0400
committerAdrian Thurston <thurston@complang.org>2015-04-26 15:47:16 -0400
commitb1f87bcea3d8fc1ed4d3de02ac335e7a6f281c37 (patch)
tree226d8b218caddb4701e9357aa266bbd5c5eae014
parent313b51b53c749bc7f49d4b2b6fdd8b7a42cf7c80 (diff)
downloadragel-b1f87bcea3d8fc1ed4d3de02ac335e7a6f281c37.tar.gz
warning elim, fix for genrep1 test, added genrep2 test
-rw-r--r--src/fsmgraph.h10
-rw-r--r--test/genrep1.rl117
-rw-r--r--test/genrep2.rl118
-rw-r--r--test/nfa1.rl2
-rw-r--r--test/nfa2.rl2
5 files changed, 178 insertions, 71 deletions
diff --git a/src/fsmgraph.h b/src/fsmgraph.h
index fd596d67..0c48abb3 100644
--- a/src/fsmgraph.h
+++ b/src/fsmgraph.h
@@ -1043,6 +1043,8 @@ template <class ItemIter1, class ItemIter2 = ItemIter1> struct ValPairIter
ItemIter trans;
ItemIter next;
+ NextTrans() { key = 0; }
+
void load() {
if ( trans.end() )
next.clear();
@@ -1196,6 +1198,12 @@ template <class ItemIter1, class ItemIter2 = ItemIter1> struct RangePairIter
ItemIter trans;
ItemIter next;
+ NextTrans()
+ {
+ highKey = 0;
+ lowKey = 0;
+ }
+
void load() {
if ( trans.end() )
next.clear();
@@ -1250,6 +1258,8 @@ template <class ItemIter1, class ItemIter2> RangePairIter<ItemIter1, ItemIter2>:
list2(list2),
itState(Begin)
{
+ bottomLow = 0;
+ bottomHigh = 0;
findNext();
}
diff --git a/test/genrep1.rl b/test/genrep1.rl
index e114456b..a7b29656 100644
--- a/test/genrep1.rl
+++ b/test/genrep1.rl
@@ -32,13 +32,11 @@ struct nfa_state_rec nfa_s[1024];
void nfa_push()
{
- printf( "push\n" );
nfa_s[nfa_len].c = c;
}
void nfa_pop()
{
- printf( "pop\n" );
c = nfa_s[nfa_len].c;
}
@@ -52,27 +50,23 @@ void nfa_pop()
action ini6
{
- printf( "ini_6\n" );
c = 0;
}
action min6
{
- printf( "min_6\n" );
if ( ++c < 2 )
fgoto *match_any_error;
}
action max6
{
- printf( "max_6\n" );
if ( ++c == 3 )
fgoto *match_any_error;
}
main :=
- ( :( ( 'a' @{printf("b\n");} ),
- ini6, min6, max6, {nfa_push();}, {nfa_pop();} ): ' ' ) {2}
+ ( :( ( 'a' ), ini6, min6, max6, {nfa_push();}, {nfa_pop();} ): ' ' ) {2}
eol
any @{printf("----- MATCH\n");}
;
@@ -87,77 +81,62 @@ int test( const char *data )
const unsigned char *pe = p + strlen(data) + 1;
const unsigned char *eof = pe;
- %%write init;
- %%write exec;
+ printf( "testing: %s\n", data );
+
+ %% write init;
+ %% write exec;
return 0;
}
int main()
{
+ test( "a " );
+ test( "aa " );
+ test( "aaa " );
+ test( "aaaa " );
+
+ test( "a a " );
+ test( "aa aa " );
test( "aaa aaa " );
+ test( "aaaa aaaa " );
+
+ test( "a a a " );
+ test( "aa aa aa " );
+ test( "aaa aaa aaa " );
+ test( "aaaa aaaa aaaa " );
+
+ test( "aa a " );
+ test( "aa aaa " );
+ test( "aa aaaa " );
+
+ test( "aaa a " );
+ test( "aaa aa " );
+ test( "aaa aaaa " );
+
return 0;
}
##### OUTPUT #####
-push
-pop
-ini_6
-b
-push
-push
-push
-pop
-min_6
-pop
-max_6
-b
-push
-push
-push
-pop
-min_6
-pop
-max_6
-b
-push
-push
-push
-pop
-min_6
-push
-pop
-ini_6
-b
-push
-push
-push
-pop
-min_6
-pop
-max_6
-b
-push
-push
-push
-pop
-min_6
-pop
-max_6
-b
-push
-push
-push
-pop
-min_6
+testing: a
+testing: aa
+testing: aaa
+testing: aaaa
+testing: a a
+testing: aa aa
+----- MATCH
+testing: aaa aaa
+----- MATCH
+testing: aaaa aaaa
+testing: a a a
+testing: aa aa aa
+testing: aaa aaa aaa
+testing: aaaa aaaa aaaa
+testing: aa a
+testing: aa aaa
+----- MATCH
+testing: aa aaaa
+testing: aaa a
+testing: aaa aa
----- MATCH
-pop
-max_6
-pop
-pop
-pop
-pop
-max_6
-pop
-pop
-pop
+testing: aaa aaaa
diff --git a/test/genrep2.rl b/test/genrep2.rl
new file mode 100644
index 00000000..a96bf7f8
--- /dev/null
+++ b/test/genrep2.rl
@@ -0,0 +1,118 @@
+/*
+ * @LANG: c
+ * @PROHIBIT_GENFLAGS: -T0 -T1 -F0 -G0 -G1 -G2
+ */
+
+#include <stddef.h> /* NULL */
+#include <stdint.h> /* uint64_t */
+#include <stdlib.h> /* malloc(3) free(3) */
+#include <stdbool.h> /* bool */
+#include <string.h>
+#include <stdio.h>
+
+struct nfa_bp_rec
+{
+ long state;
+ const unsigned char *p;
+ int pop;
+};
+
+struct nfa_bp_rec nfa_bp[1024];
+long nfa_len = 0;
+long nfa_count = 0;
+
+long c;
+
+struct nfa_state_rec
+{
+ long c;
+};
+
+struct nfa_state_rec nfa_s[1024];
+
+void nfa_push()
+{
+ nfa_s[nfa_len].c = c;
+}
+
+void nfa_pop()
+{
+ c = nfa_s[nfa_len].c;
+}
+
+%%{
+ machine match_any;
+ alphtype unsigned char;
+
+ action eol { p+1 == eof }
+
+ eol = '' %when eol;
+
+ action ini6
+ {
+ c = 0;
+ }
+
+ action min6
+ {
+ if ( ++c < 2 )
+ fgoto *match_any_error;
+ }
+
+ action max6
+ {
+ if ( ++c == 3 )
+ fgoto *match_any_error;
+ }
+
+ main :=
+ ( :( ( 'a' ), ini6, min6, max6, {nfa_push();}, {nfa_pop();} ): ) {2}
+ eol
+ any @{printf("----- MATCH\n");}
+ ;
+
+ write data;
+}%%
+
+int test( const char *data )
+{
+ int cs;
+ const unsigned char *p = (const unsigned char *)data;
+ const unsigned char *pe = p + strlen(data) + 1;
+ const unsigned char *eof = pe;
+
+ printf( "testing: %s\n", data );
+
+ %% write init;
+ %% write exec;
+
+ return 0;
+}
+
+int main()
+{
+ test( "a" );
+ test( "aa" );
+ test( "aaa" );
+ test( "aaaa" );
+ test( "aaaaa" );
+ test( "aaaaaa" );
+ test( "aaaaaaa" );
+ test( "aaaaaaaa" );
+
+ return 0;
+}
+
+##### OUTPUT #####
+testing: a
+testing: aa
+testing: aaa
+testing: aaaa
+----- MATCH
+testing: aaaaa
+----- MATCH
+----- MATCH
+testing: aaaaaa
+----- MATCH
+testing: aaaaaaa
+testing: aaaaaaaa
diff --git a/test/nfa1.rl b/test/nfa1.rl
index 794330f0..853b1df0 100644
--- a/test/nfa1.rl
+++ b/test/nfa1.rl
@@ -54,7 +54,7 @@ long nfa_count = 0;
main1 = atoi '\n' @print1;
main2 = [0-9]* '00000000' [0-9]* '\n' @print2;
- main |= "main" (5, 0) "main1" main1 | "main2" main2;
+ main |= (5, 0) main1 | main2;
}%%
%% write data;
diff --git a/test/nfa2.rl b/test/nfa2.rl
index d232f6e3..556b8902 100644
--- a/test/nfa2.rl
+++ b/test/nfa2.rl
@@ -63,7 +63,7 @@
main1 = atoi '\n' @print1;
main2 = [0-9]* '00000000' [0-9]* '\n' @print2;
- main |= "main" (5, 0) "main1" main1 | "main2" main2;
+ main |= (5, 0) main1 | main2;
}%%
.file "tmp.c"