| 1 | package srscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/ |
| 2 | |
| 3 | import ( |
| 4 | "testingscip-go gomod github.com/golang/go/src go1.24 testing/" |
| 5 | |
| 6 | "github.com/goccmack/gocc/example/sr/astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/" |
| 7 | "github.com/goccmack/gocc/example/sr/lexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/lexer`/" |
| 8 | "github.com/goccmack/gocc/example/sr/parserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/parser`/" |
| 9 | ) |
| 10 | |
| 11 | func parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/parse().(src string) (stmt astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.Stmtscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/Stmt#, err error) { |
| 12 | lex := lexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/lexer`/.NewLexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/lexer`/NewLexer().([]byte(src)) |
| 13 | p := parserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/parser`/.NewParserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/parser`/NewParser().() |
| 14 | if res, err := p.Parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/parser`/Parser#Parse().(lex); err == nil { |
| 15 | stmt = res.(astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.Stmtscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/Stmt#) |
| 16 | } |
| 17 | return |
| 18 | } |
| 19 | |
| 20 | func Test1scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/Test1().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 21 | stmt, err := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/parse().("if c1 then s1") |
| 22 | if err != nil { |
| 23 | t.Fatalscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatal().(err.Error()) |
| 24 | } |
| 25 | ifs, ok := stmt.(*astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.Ifscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/If#) |
| 26 | if !ok { |
| 27 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("sr_test.Test1: stmt is not *ast.If") |
| 28 | } |
| 29 | if !ifs.MatchIfscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/If#MatchIf().("c1", astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.IdStmtscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IdStmt#("s1")) { |
| 30 | t.Failscip-go gomod github.com/golang/go/src go1.24 testing/common#Fail().() |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func Test2scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/Test2().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 35 | stmt, err := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/parse().("if c1 then s1 else s2") |
| 36 | if err != nil { |
| 37 | t.Fatalscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatal().(err.Error()) |
| 38 | } |
| 39 | ifes, ok := stmt.(*astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.IfElsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IfElse#) |
| 40 | if !ok { |
| 41 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("stmt is not *ast.IfElse") |
| 42 | } |
| 43 | if !ifes.MatchIfElsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IfElse#MatchIfElse().("c1", astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.IdStmtscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IdStmt#("s1"), astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.IdStmtscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IdStmt#("s2")) { |
| 44 | t.Failscip-go gomod github.com/golang/go/src go1.24 testing/common#Fail().() |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | func Test3scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/Test3().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 49 | stmt, err := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr`/parse().("if c1 then if c2 then s2 else s3") |
| 50 | if err != nil { |
| 51 | t.Fatalscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatal().(err.Error()) |
| 52 | } |
| 53 | ifs, ok := stmt.(*astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.Ifscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/If#) |
| 54 | if !ok { |
| 55 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("stmt is not *ast.IfElse") |
| 56 | } |
| 57 | ife2 := &astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.IfElsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IfElse#{Cscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IfElse#C.: "c2", S1scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IfElse#S1.: astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.IdStmtscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IdStmt#("s2"), S2scip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IfElse#S2.: astscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/.IdStmtscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/IdStmt#("s3")} |
| 58 | if !ifs.MatchIfscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/sr/ast`/If#MatchIf().("c1", ife2) { |
| 59 | t.Failscip-go gomod github.com/golang/go/src go1.24 testing/common#Fail().() |
| 60 | } |
| 61 | } |