scope.go 541 B

12345678910111213141516171819202122232425262728293031
  1. package raku
  2. type Scope interface {
  3. /* Chains a child scope to a parent scope. */
  4. Chain(*Scope) bool
  5. Classifier
  6. }
  7. type DefaultScope struct {
  8. DefaultClassifier
  9. Parent Scope
  10. }
  11. func (scope * DefaultScope) Chain(parent Scope) bool {
  12. scope.Parent = parent
  13. return true
  14. }
  15. func (scope * DefaultScope) Classify(text TokenText) (TokenType, bool) {
  16. typ, ok := scope.DefaultClassifier.Classify(text)
  17. if (!ok && scope.Parent != nil) {
  18. typ, ok = scope.Parent.Classify(text)
  19. }
  20. return typ, ok
  21. }