listener_test.go 789 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package urn
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/antlr/antlr4/runtime/Go/antlr"
  6. "github.com/leodido/go-urn/grammar"
  7. )
  8. func TestListener(t *testing.T) {
  9. inputs := []string{
  10. //"URN:1ab:xxx",
  11. }
  12. fmt.Println("---")
  13. for _, input := range inputs {
  14. stream := antlr.NewInputStream(input)
  15. lexer := grammar.NewUrnLexer(stream)
  16. tokens := antlr.NewCommonTokenStream(lexer, 0)
  17. parser := grammar.NewUrnParser(tokens)
  18. parser.AddErrorListener(antlr.NewDiagnosticErrorListener(true))
  19. parser.BuildParseTrees = true
  20. /*
  21. urn := URN{}
  22. parser.AddParseListener(NewListener(&urn))
  23. */
  24. parser.Urn()
  25. //fmt.Printf("getstruct=> %+v\n", tree.GetStructure())
  26. //fmt.Println(tree.ToStringTree(nil, parser))
  27. // fmt.Printf("%s => %+v\n", input, urn)
  28. fmt.Println("---")
  29. }
  30. }