listener.go 654 B

123456789101112131415161718192021222324252627282930313233
  1. package urn
  2. import (
  3. "github.com/leodido/go-urn/grammar"
  4. )
  5. // Listener is ...
  6. type Listener struct {
  7. *grammar.BaseUrnListener
  8. target *URN
  9. }
  10. // NewListener is ...
  11. func NewListener(u *URN) *Listener {
  12. return &Listener{
  13. target: u,
  14. }
  15. }
  16. // ExitID is called when rule iD is exited
  17. func (l *Listener) ExitID(ctx *grammar.IDContext) {
  18. l.target.ID = ctx.GetText()
  19. }
  20. // ExitSS is called when rule sS is exited
  21. func (l *Listener) ExitSS(ctx *grammar.SSContext) {
  22. l.target.SS = ctx.GetText()
  23. }
  24. // ExitUrn is called when rule urn is exited
  25. func (l *Listener) ExitUrn(ctx *grammar.UrnContext) {
  26. l.target.tree = ctx.ToStringTree(nil, ctx.GetParser())
  27. }