| 1 | //Copyright 2012 Vastech SA (PTY) LTD |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package rrscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.24 fmt/" |
| 19 | "testingscip-go gomod github.com/golang/go/src go1.24 testing/" |
| 20 | |
| 21 | "github.com/goccmack/gocc/example/rr/lexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr/lexer`/" |
| 22 | "github.com/goccmack/gocc/example/rr/parserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr/parser`/" |
| 23 | ) |
| 24 | |
| 25 | func parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/parse().(src string) (ast string, err error) { |
| 26 | l := lexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr/lexer`/.NewLexerscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr/lexer`/NewLexer().([]byte(src)) |
| 27 | p := parserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr/parser`/.NewParserscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr/parser`/NewParser().() |
| 28 | res, err := p.Parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr/parser`/Parser#Parse().(l) |
| 29 | if err == nil { |
| 30 | ast = res.(string) |
| 31 | } |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | func testscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/test().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#, src, exp string) { |
| 36 | ast, err := parsescip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/parse().(src) |
| 37 | if err != nil { |
| 38 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("\tError: %s\n", err.Error()) |
| 39 | } |
| 40 | if ast != exp { |
| 41 | t.Fatalfscip-go gomod github.com/golang/go/src go1.24 testing/common#Fatalf().("\tError: ast= `%s`\n", ast) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | type TDscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD# struct { |
| 46 | srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD#src. string |
| 47 | expscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD#exp. string |
| 48 | } |
| 49 | |
| 50 | var testDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/testData. = []TDscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD#{ |
| 51 | {"a", "B "}, |
| 52 | {"a a", "A1 "}, |
| 53 | {"a a a", "A1 "}, |
| 54 | {"c a", "A1 "}, |
| 55 | {"c a a a a", "A1 "}, |
| 56 | } |
| 57 | |
| 58 | func Testscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/Test().(t *testingscip-go gomod github.com/golang/go/src go1.24 testing/.Tscip-go gomod github.com/golang/go/src go1.24 testing/T#) { |
| 59 | for _, td := range testDatascip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/testData. { |
| 60 | fmtscip-go gomod github.com/golang/go/src go1.24 fmt/.Printfscip-go gomod github.com/golang/go/src go1.24 fmt/Printf().("\tsrc: `%s`; exp: `%s`\n", td.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD#src., td.expscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD#exp.) |
| 61 | testscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/test().(t, td.srcscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD#src., td.expscip-go gomod github.com/goccmack/gocc . `github.com/goccmack/gocc/example/rr`/TD#exp.) |
| 62 | } |
| 63 | } |