Updated examples for the first of the 6.0 changes: removed write eof and added
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 30 Sep 2007 15:08:13 +0000 (15:08 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Sun, 30 Sep 2007 15:08:13 +0000 (15:08 +0000)
eof pointer.

git-svn-id: http://svn.complang.org/ragel/trunk@294 052ea7fc-9027-0410-9066-f65837a77df0

examples/clang.rl
examples/concurrent.rl
examples/cppscan.rl
examples/format.rl
examples/gotocallret.rl
examples/mailbox.rl
examples/params.rl
examples/pullscan.rl
examples/rlscan.rl
examples/statechart.rl

index 7ecfeef..09b109e 100644 (file)
@@ -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 ) {
index b70fd5d..4b9d421 100644 (file)
@@ -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 )
index 5c979eb..d1a3130 100644 (file)
@@ -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. */
index ea5fdfb..f8a37be 100644 (file)
@@ -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 )
index 84384a9..d7fa49b 100644 (file)
@@ -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;
 }
index 74e3310..3abc1c7 100644 (file)
@@ -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 )
index 3cf908f..a8ffeae 100644 (file)
@@ -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 )
index cbb0ca3..3a232ed 100644 (file)
@@ -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 := |*
 
index f912b8d..10b0671 100644 (file)
@@ -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 ) {
index b61f35e..7d7e5cf 100644 (file)
@@ -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 )