func parseChainWordBody(p *parser, expectType kit.WordType) (kit.ChainWord, kit.WordType) { w := word.NewChainWord() actualType := expectType PARSE_WORD_CHAIN_LOOP: for { switch t := p.peek(); { case w.Size() > 0 && t.GetType() == token.TDblColon: // TDblColon indicates the word is a dict word actualType = word.TDictWord p.next() case t.GetType() == token.TNumber: w.Push(word.NewNumberWord(t.GetVal())) p.next() case t.GetType() == token.TString: w.Push(word.NewStringWord(t.GetVal())) p.next() case t.GetType() == token.TIdentifier: ident := t.GetVal() if v := p.memo.Vocab().Read(ident); v != nil { w.Push(v) } else { w.Push(word.NewNameWord(ident)) } p.next() case t.GetType() == token.TLeftBrace: if aw, dw := parseArrayDictBody(p); aw != nil { w.Push(aw) } else if dw != nil { w.Push(dw) } case t.GetType() == token.TLeftSquareBracket: w.Push(parseAnonFuncBody(p)) case expectType == word.TArrayWord && t.GetType() == token.TRightBrace: p.next() break PARSE_WORD_CHAIN_LOOP case expectType == word.TFuncWord && t.GetType() == token.TRightSquareBracket: p.next() break PARSE_WORD_CHAIN_LOOP case t.GetType() == token.TEOF: break PARSE_WORD_CHAIN_LOOP case t.GetType() == token.TSpace: p.next() } } return w, actualType }
func parseIdentifier(p *parser) stateFn { t := p.next() ident := t.GetVal() if w := p.memo.Vocab().Read(ident); w != nil { p.emit(w) } else { p.emit(word.NewNameWord(ident)) } return parse }