Hi,

Thanks for developing Ragel.

Being new, I tried the example from the user manual.

It runs in C but it breaks in Go.

I've run: ragel -Z -G2 main.rl && go run main.go

Results are:

# command-line-arguments
./main.go:66: goto tr0 jumps into block starting at ./main.go:39
./main.go:71: goto tr3 jumps into block starting at ./main.go:48
./main.go:72: goto st0 jumps into block starting at ./main.go:48
... too many errors.

It happens in a backported go-1.1.2 from Sid to Wheezy, 64bit
and in go-1.02 on ubuntu 12.04 on 32bits.

I've run the same program in C: number.rl

   ragel number.rl && gcc number.c && ./a.out "123.456e+789"
DGT: 1
DGT: 2
DGT: 3
DEC: .
enz...


Is this a known problem? Do I (newbie) do something wrong?

Regards, Guido.

package main
import (
        "fmt"
)

%%{
        machine numbers;
        action dgt      { fmt.Printf("DGT: %c\n", fc); }
        action dec      { fmt.Printf("DEC: .\n"); }
        action exp      { fmt.Printf("EXP: %c\n", fc); }
        action exp_sign { fmt.Printf("SGN: %c\n", fc); }
        action number   { fmt.Printf("Number parsed"); }

        number = (
                [0-9]+ $dgt ( '.' @dec [0-9]+ $dgt )?
                ( [eE] ( [+\-] $exp_sign )? [0-9]+ $exp )?
        ) %number;
                
        main := ( number '\n' )*;
}%%

%% write data;

func main() {
        data := "123.456e+789" // data is the input to the state machine
        cs := 0 // state 
        p := 0 // data pointer (index into data)
        pe := len(data)

        %%      write init;
        %%      write exec;

        return
}
// line 1 "main.rl"
package main
import (
	"fmt"
)


// line 20 "main.rl"



// line 14 "main.go"
var numbers_start int = 7
var numbers_first_final int = 7
var numbers_error int = 0

var numbers_en_main int = 7


// line 23 "main.rl"

func main() {
	data := "123.456e+789" // data is the input to the state machine
	cs := 0 // state 
	p := 0 // data pointer (index into data)
	pe := len(data)

	
// line 31 "main.go"
	cs = numbers_start

// line 31 "main.rl"
	
// line 36 "main.go"
	{
	if p == pe { goto _test_eof }
	switch cs {
	case -666: // i am a hack D:
tr0:
// line 12 "main.rl"
	{ fmt.Printf("Number parsed"); }
	goto st7
st7:
	p++
	if p == pe { goto _test_eof7 }
	fallthrough
case 7:
// line 50 "main.go"
	if 48 <= data[p] && data[p] <= 57 { goto tr3 }
	goto st0
st0:
cs = 0;
	goto _out;
tr3:
// line 8 "main.rl"
	{ fmt.Printf("DGT: %c\n", data[p]); }
	goto st1
st1:
	p++
	if p == pe { goto _test_eof1 }
	fallthrough
case 1:
// line 65 "main.go"
	switch data[p] {
		case 10: goto tr0
		case 46: goto tr2
		case 69: goto st4
		case 101: goto st4
	}
	if 48 <= data[p] && data[p] <= 57 { goto tr3 }
	goto st0
tr2:
// line 9 "main.rl"
	{ fmt.Printf("DEC: .\n"); }
	goto st2
st2:
	p++
	if p == pe { goto _test_eof2 }
	fallthrough
case 2:
// line 83 "main.go"
	if 48 <= data[p] && data[p] <= 57 { goto tr5 }
	goto st0
tr5:
// line 8 "main.rl"
	{ fmt.Printf("DGT: %c\n", data[p]); }
	goto st3
st3:
	p++
	if p == pe { goto _test_eof3 }
	fallthrough
case 3:
// line 95 "main.go"
	switch data[p] {
		case 10: goto tr0
		case 69: goto st4
		case 101: goto st4
	}
	if 48 <= data[p] && data[p] <= 57 { goto tr5 }
	goto st0
st4:
	p++
	if p == pe { goto _test_eof4 }
	fallthrough
case 4:
	switch data[p] {
		case 43: goto tr6
		case 45: goto tr6
	}
	if 48 <= data[p] && data[p] <= 57 { goto tr7 }
	goto st0
tr6:
// line 11 "main.rl"
	{ fmt.Printf("SGN: %c\n", data[p]); }
	goto st5
st5:
	p++
	if p == pe { goto _test_eof5 }
	fallthrough
case 5:
// line 123 "main.go"
	if 48 <= data[p] && data[p] <= 57 { goto tr7 }
	goto st0
tr7:
// line 10 "main.rl"
	{ fmt.Printf("EXP: %c\n", data[p]); }
	goto st6
st6:
	p++
	if p == pe { goto _test_eof6 }
	fallthrough
case 6:
// line 135 "main.go"
	if data[p] == 10 { goto tr0 }
	if 48 <= data[p] && data[p] <= 57 { goto tr7 }
	goto st0
	}
	_test_eof7: cs = 7; goto _test_eof; 
	_test_eof1: cs = 1; goto _test_eof; 
	_test_eof2: cs = 2; goto _test_eof; 
	_test_eof3: cs = 3; goto _test_eof; 
	_test_eof4: cs = 4; goto _test_eof; 
	_test_eof5: cs = 5; goto _test_eof; 
	_test_eof6: cs = 6; goto _test_eof; 

	_test_eof: {}
	_out: {}
	}

// line 32 "main.rl"

	return
}
#include <string.h>
#include <stdio.h>

%%{
        machine numbers;

        action dgt      { printf("DGT: %c\n", fc); }
        action dec      { printf("DEC: .\n"); }
        action exp      { printf("EXP: %c\n", fc); }
        action exp_sign { printf("SGN: %c\n", fc); }
        action number   { res = 1; }

        number = (
                [0-9]+ $dgt ( '.' @dec [0-9]+ $dgt )?
                ( [eE] ( [+\-] $exp_sign )? [0-9]+ $exp )?
        ) $number;
                
        main := ( number '\n' )*;
}%%

%% write data;          

int main( int argc, char **argv )
{
        int cs, res = 0;
        if ( argc > 1 ) {
           char *p = argv[1];
           char *pe = p + strlen(p) + 1;

           %%   write init;
           %%   write exec;
           }
        printf("result = %i\n", res );
        return 0;
}

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
ragel-users mailing list
[email protected]
http://www.complang.org/mailman/listinfo/ragel-users

Reply via email to