| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package main
- import (
- "bufio"
- "fmt"
- "strings"
- )
- func opRead(scanner *bufio.Scanner) value {
- s := "\n"
- for s == "\n" && scanner.Scan() {
- s = scanner.Text()
- }
- if s == "\n" {
- panic(fmt.Errorf("read: %s", errUnexpectedEndOfInput))
- }
- return value{val: `"` + s}
- }
- func opPrint(val1 value) value {
- s := val1.val
- if s != "" {
- if s[0] == '"' {
- fmt.Println(s[1:])
- } else if s[0] == '[' {
- list, space := strings.Split(s, " "), false
- for i := 0; i < len(list); i++ {
- if space && list[i] != "]" {
- fmt.Print(" ")
- }
- fmt.Print(list[i])
- space = list[i] != "["
- }
- fmt.Println()
- } else {
- fmt.Println(s)
- }
- }
- return val1
- }
- func opReadList(scanner *bufio.Scanner) value {
- list, line := []string{}, false
- for scanner.Scan() {
- s := scanner.Text()
- if s == "\n" && line {
- break
- }
- line = true
- if s[0] == '[' || s[len(s)-1] == ']' {
- panic(fmt.Errorf("readlist: %s, (%s)", errWordExpceted, s))
- }
- if s != "\n" {
- list = append(list, s)
- }
- }
- return value{val: "[ " + strings.Join(list, " ") + " ]"}
- }
|