示例#1
0
文件: lexer_test.go 项目: mk2/yon
func TestLexer_new(t *testing.T) {

	l := lexer.New(bytes.NewBufferString("a 'b `test` 123 1.23 test {}"))

	var cnt = 0
	for tkn := l.NextToken(); tkn.GetType() != token.TEOF; tkn = l.NextToken() {

		if tkn.GetType() == token.TSpace {
			continue
		}
		kit.Printf("token type: %v token value: %s", tkn.GetType(), tkn.GetVal())

		switch cnt {
		case 0:
			assertTokenType(t, tkn.GetType(), token.TIdentifier)
		case 1:
			assertTokenType(t, tkn.GetType(), token.TIdentifier)
		case 2:
			assertTokenType(t, tkn.GetType(), token.TString)
		case 3:
			assertTokenType(t, tkn.GetType(), token.TNumber)
		case 4:
			assertTokenType(t, tkn.GetType(), token.TNumber)
		case 5:
			assertTokenType(t, tkn.GetType(), token.TIdentifier)
		case 6:
			assertTokenType(t, tkn.GetType(), token.TLeftBrace)
		case 7:
			assertTokenType(t, tkn.GetType(), token.TRightBrace)
		}

		cnt++
	}
}
示例#2
0
文件: interp.go 项目: mk2/yon
func (ip *interp) Eval(runes kit.RuneScanner) (kit.StoppedCh, kit.ErrorCh) {

	tokens := lexer.New(runes)
	words := parser.New(tokens, ip.memo)

	go ip.run(words)

	return ip.stoppedCh, ip.errorCh
}