Esempio n. 1
0
File: parser.go Progetto: mk2/yon
func (p *parser) ReadWord() (kit.Word, error) {

	if p.onceAgainWord {

		kit.Println("found unused last token")

		p.Lock()
		p.onceAgainWord = false
		p.Unlock()

		if p.lastWord == nil {
			return nil, errors.New("no last read token")
		}

		return p.lastWord, nil
	}

	kit.Println("waiting for incoming word")

	select {

	case t := <-p.words:
		p.lastWord = t
		return t, nil

	case <-time.After(kit.ParserTimeout):
		// timeout

	}

	return nil, errors.New("no word gained")
}
Esempio n. 2
0
File: lexer.go Progetto: mk2/yon
func (l *lexer) ReadToken() (kit.Token, error) {

	if l.onceAgainToken {

		kit.Printf("found unused last token: %+v\n", l.lastToken)

		l.Lock()
		l.onceAgainToken = false
		l.Unlock()

		if l.lastToken == nil {
			return nil, errors.New("no last read token")
		}

		return l.lastToken, nil
	}

	kit.Println("waiting for incoming token")

	select {

	case t := <-l.tokens:
		l.lastToken = t
		return t, nil

	case <-time.After(kit.LexerTimeout):
		// timeout

	}

	return nil, errors.New("no token gained")
}
Esempio n. 3
0
File: interp.go Progetto: mk2/yon
func (ip *interp) run(words kit.WordScanner) {

	m := ip.memo

	var (
		w   kit.Word
		err error
	)

	kit.Println("start RUN_LOOP")

RUN_LOOP:
	for {

		if w, err = words.ReadWord(); err != nil {
			ip.errorCh <- err
			break RUN_LOOP
		}

		kit.Printf("word: %+v", w)

		switch w.GetWordType() {

		case word.TNumberWord:
			kit.Println("number word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TStringWord:
			kit.Println("string word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TBoolWord:
			kit.Println("bool word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TArrayWord:
			kit.Println("array word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TFuncWord:
			kit.Println("func word")
			if _, err := w.Do(m); err != nil {
				ip.errorCh <- err
				break
			}

		case word.TNilWord:
			kit.Println("nil word")
			break RUN_LOOP

		default:
			kit.Printf("unknown word: %+v\n", w)
			ip.errorCh <- errors.New("unknown word")
			break RUN_LOOP

		}

	}

	kit.Println("exit RUN_LOOP")

	ip.stoppedCh <- struct{}{}
}