summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2007-09-30 15:08:13 +0000
committerAdrian Thurston <thurston@complang.org>2007-09-30 15:08:13 +0000
commitfa7aae7416f8bd4f8765c2fb7390b75cceb1040a (patch)
tree30eb5496c3427a58214d5ec25887157658774b0b /examples
parentdaaafb3af537c09463f400483ec8f9abbce4c5bf (diff)
downloadragel-fa7aae7416f8bd4f8765c2fb7390b75cceb1040a.tar.gz
Updated examples for the first of the 6.0 changes: removed write eof and added
eof pointer.
Diffstat (limited to 'examples')
-rw-r--r--examples/clang.rl8
-rw-r--r--examples/concurrent.rl1
-rw-r--r--examples/cppscan.rl7
-rw-r--r--examples/format.rl10
-rw-r--r--examples/gotocallret.rl12
-rw-r--r--examples/mailbox.rl1
-rw-r--r--examples/params.rl2
-rw-r--r--examples/pullscan.rl3
-rw-r--r--examples/rlscan.rl5
-rw-r--r--examples/statechart.rl1
10 files changed, 20 insertions, 30 deletions
diff --git a/examples/clang.rl b/examples/clang.rl
index 7ecfeefd..09b109ec 100644
--- a/examples/clang.rl
+++ b/examples/clang.rl
@@ -104,7 +104,7 @@ void scanner()
%% write init;
while ( !done ) {
- char *p = buf + have, *pe;
+ char *p = buf + have, *pe, *eof = 0;
int len, space = BUFSIZE - have;
if ( space == 0 ) {
@@ -115,14 +115,14 @@ void scanner()
}
len = fread( p, 1, space, stdin );
+ pe = p + len;
- /* If this is the last buffer, tack on an EOF. */
+ /* Check if this is the end of file. */
if ( len < space ) {
- p[len++] = 0;
+ eof = pe;
done = 1;
}
- pe = p + len;
%% write exec;
if ( cs == clang_error ) {
diff --git a/examples/concurrent.rl b/examples/concurrent.rl
index b70fd5df..4b9d421c 100644
--- a/examples/concurrent.rl
+++ b/examples/concurrent.rl
@@ -99,7 +99,6 @@ int Concurrent::execute( const char *data, int len )
int Concurrent::finish( )
{
- %% write eof;
if ( cs == Concurrent_error )
return -1;
if ( cs >= Concurrent_first_final )
diff --git a/examples/cppscan.rl b/examples/cppscan.rl
index 5c979ebe..d1a31301 100644
--- a/examples/cppscan.rl
+++ b/examples/cppscan.rl
@@ -174,14 +174,15 @@ int main()
cin.read( p, space );
int len = cin.gcount();
+ char *pe = p + len;
+ char *eof = 0;
/* If we see eof then append the EOF char. */
- if ( len == 0 ) {
- p[0] = LAST_CHAR, len++;
+ if ( cin.eof() ) {
+ eof = pe;
done = true;
}
- char *pe = p + len;
%% write exec;
/* Check if we failed. */
diff --git a/examples/format.rl b/examples/format.rl
index ea5fdfb5..f8a37beb 100644
--- a/examples/format.rl
+++ b/examples/format.rl
@@ -144,18 +144,17 @@ void format_init( struct format *fsm )
%% write init;
}
-void format_execute( struct format *fsm, const char *data, int len )
+void format_execute( struct format *fsm, const char *data, int len, int isEof )
{
const char *p = data;
const char *pe = data + len;
+ const char *eof = isEof ? pe : 0;
%% write exec;
}
int format_finish( struct format *fsm )
{
- %% write eof;
-
if ( fsm->cs == format_error )
return -1;
if ( fsm->cs >= format_first_final )
@@ -180,8 +179,9 @@ int main()
format_init( &fsm );
while ( 1 ) {
int len = fread( buf, 1, INPUT_BUFSIZE, stdin );
- format_execute( &fsm, buf, len );
- if ( len != INPUT_BUFSIZE )
+ int eof = len != INPUT_BUFSIZE;
+ format_execute( &fsm, buf, len, eof );
+ if ( eof )
break;
}
if ( format_finish( &fsm ) <= 0 )
diff --git a/examples/gotocallret.rl b/examples/gotocallret.rl
index 84384a9c..d7fa49bc 100644
--- a/examples/gotocallret.rl
+++ b/examples/gotocallret.rl
@@ -76,16 +76,6 @@ int GotoCallRet::execute( const char *data, int len )
return 0;
}
-int GotoCallRet::finish( )
-{
- %% write eof;
- if ( cs == GotoCallRet_error )
- return -1;
- if ( cs >= GotoCallRet_first_final )
- return 1;
- return 0;
-}
-
#define BUFSIZE 1024
int main()
@@ -97,7 +87,7 @@ int main()
while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
gcr.execute( buf, strlen(buf) );
}
- if ( gcr.finish() <= 0 )
+ if ( gcr.cs < GotoCallRet_first_final )
cerr << "gotocallret: error: parsing input" << endl;
return 0;
}
diff --git a/examples/mailbox.rl b/examples/mailbox.rl
index 74e33108..3abc1c78 100644
--- a/examples/mailbox.rl
+++ b/examples/mailbox.rl
@@ -159,7 +159,6 @@ int MailboxScanner::execute( const char *data, int len )
int MailboxScanner::finish( )
{
- %% write eof;
if ( cs == MailboxScanner_error )
return -1;
if ( cs >= MailboxScanner_first_final )
diff --git a/examples/params.rl b/examples/params.rl
index 3cf908ff..a8ffeae9 100644
--- a/examples/params.rl
+++ b/examples/params.rl
@@ -78,8 +78,6 @@ void params_execute( struct params *fsm, const char *data, int len )
int params_finish( struct params *fsm )
{
- %% write eof;
-
if ( fsm->cs == params_error )
return -1;
if ( fsm->cs >= params_first_final )
diff --git a/examples/pullscan.rl b/examples/pullscan.rl
index cbb0ca3f..3a232ede 100644
--- a/examples/pullscan.rl
+++ b/examples/pullscan.rl
@@ -14,6 +14,7 @@ typedef struct _Scanner {
char *tokend;
char *p;
char *pe;
+ char *eof;
FILE *file;
int done;
@@ -36,6 +37,7 @@ void scan_init( Scanner *s, FILE *file )
memset (s, '\0', sizeof(Scanner));
s->curline = 1;
s->file = file;
+ s->eof = 0;
%% write init;
}
@@ -96,6 +98,7 @@ int scan( Scanner *s )
access s->;
variable p s->p;
variable pe s->pe;
+ variable eof s->eof;
main := |*
diff --git a/examples/rlscan.rl b/examples/rlscan.rl
index f912b8d8..10b06719 100644
--- a/examples/rlscan.rl
+++ b/examples/rlscan.rl
@@ -268,14 +268,15 @@ int main()
char *p = inbuf + have;
cin.read( p, space );
int len = cin.gcount();
+ char *pe = p + len;
+ char *eof = 0;
/* Check for EOF. */
if ( len == 0 ) {
- p[0] = 0, len++;
+ eof = pe;
done = true;
}
- char *pe = p + len;
%% write exec;
if ( cs == RagelScan_error ) {
diff --git a/examples/statechart.rl b/examples/statechart.rl
index b61f35e8..7d7e5cff 100644
--- a/examples/statechart.rl
+++ b/examples/statechart.rl
@@ -90,7 +90,6 @@ int StateChart::execute( const char *data, int len )
int StateChart::finish( )
{
- %% write eof;
if ( cs == StateChart_error )
return -1;
if ( cs >= StateChart_first_final )