github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/types/generic/map.go (about) 1 package generic 2 3 import ( 4 "bufio" 5 "fmt" 6 "strconv" 7 8 "github.com/lmorg/murex/config" 9 "github.com/lmorg/murex/lang/stdio" 10 "github.com/lmorg/murex/lang/types" 11 ) 12 13 func readMap(read stdio.Io, _ *config.Config, callback func(*stdio.Map)) error { 14 scanner := bufio.NewScanner(read) 15 for scanner.Scan() { 16 row := rxWhitespace.Split(scanner.Text(), -1) 17 18 for i := range row { 19 callback(&stdio.Map{ 20 Key: strconv.Itoa(i), 21 Value: row[i], 22 DataType: types.String, 23 Last: i+1 == len(row), 24 }) 25 } 26 } 27 28 err := scanner.Err() 29 if err != nil { 30 return fmt.Errorf("error while reading a %s map: %s", types.Generic, err.Error()) 31 } 32 return err 33 34 }