1
0

importstack.go 453 B

1234567891011121314151617181920212223
  1. package ast
  2. import "errors"
  3. // ErrImportCycleNotAllowed defines an error for circular importing
  4. var ErrImportCycleNotAllowed = errors.New("import cycle not allowed")
  5. // importStack a stack of import paths
  6. type importStack []string
  7. func (s *importStack) push(p string) error {
  8. for _, x := range *s {
  9. if x == p {
  10. return ErrImportCycleNotAllowed
  11. }
  12. }
  13. *s = append(*s, p)
  14. return nil
  15. }
  16. func (s *importStack) pop() {
  17. *s = (*s)[0 : len(*s)-1]
  18. }