|
@@ -12,27 +12,27 @@ func assign(s string, index []string, val string, envs []environ) string {
|
|
|
return val
|
|
return val
|
|
|
}
|
|
}
|
|
|
list := parseList(s)
|
|
list := parseList(s)
|
|
|
- i := toInt(value{word: index[0]}, envs)
|
|
|
|
|
|
|
+ i := toInt(&_unknown{s: index[0]}, envs)
|
|
|
return spliceList(list, i, 1, assign(indexOfList(list, i), index[1:], val, envs))
|
|
return spliceList(list, i, 1, assign(indexOfList(list, i), index[1:], val, envs))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func setValue(s string, val value, envs []environ) (value, error) {
|
|
func setValue(s string, val value, envs []environ) (value, error) {
|
|
|
- if !isNameWithIndex(value{word: s}) {
|
|
|
|
|
- return value{}, fmt.Errorf("set: %s (%s)", errInvalidName, s)
|
|
|
|
|
|
|
+ if !isNameWithIndex(&_unknown{s: s}) {
|
|
|
|
|
+ return nil, fmt.Errorf("set: %s (%s)", errInvalidName, s)
|
|
|
}
|
|
}
|
|
|
- name, index := toNameWithIndex(value{word: s})
|
|
|
|
|
|
|
+ name, index := toNameWithIndex(&_unknown{s: s})
|
|
|
_, ok := reserved[name]
|
|
_, ok := reserved[name]
|
|
|
if ok {
|
|
if ok {
|
|
|
- return value{}, fmt.Errorf("set: %s (%s)", errNameReserved, name)
|
|
|
|
|
|
|
+ return nil, fmt.Errorf("set: %s (%s)", errNameReserved, name)
|
|
|
}
|
|
}
|
|
|
oldVal, ok := envs[0][name]
|
|
oldVal, ok := envs[0][name]
|
|
|
if ok {
|
|
if ok {
|
|
|
delete(envs[0], name)
|
|
delete(envs[0], name)
|
|
|
if len(index) > 0 {
|
|
if len(index) > 0 {
|
|
|
- val = value{word: assign(toString(oldVal), index, toString(val), envs)}
|
|
|
|
|
|
|
+ val = &_unknown{s: assign(oldVal.String(), index, val.String(), envs)}
|
|
|
}
|
|
}
|
|
|
} else if len(index) > 0 {
|
|
} else if len(index) > 0 {
|
|
|
- return value{}, fmt.Errorf("set: %s (%s)", errNameNotFound, name)
|
|
|
|
|
|
|
+ return nil, fmt.Errorf("set: %s (%s)", errNameNotFound, name)
|
|
|
}
|
|
}
|
|
|
val = toValue(val, envs)
|
|
val = toValue(val, envs)
|
|
|
envs[0][name] = val
|
|
envs[0][name] = val
|
|
@@ -40,43 +40,43 @@ func setValue(s string, val value, envs []environ) (value, error) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func getValue(s string, envs []environ) (value, error) {
|
|
func getValue(s string, envs []environ) (value, error) {
|
|
|
- if !isNameWithIndex(value{word: s}) {
|
|
|
|
|
- return value{}, fmt.Errorf("get: %s (%s)", errInvalidName, s)
|
|
|
|
|
|
|
+ if !isNameWithIndex(&_unknown{s: s}) {
|
|
|
|
|
+ return nil, fmt.Errorf("get: %s (%s)", errInvalidName, s)
|
|
|
}
|
|
}
|
|
|
- name, index := toNameWithIndex(value{word: s})
|
|
|
|
|
|
|
+ name, index := toNameWithIndex(&_unknown{s: s})
|
|
|
for _, env := range envs {
|
|
for _, env := range envs {
|
|
|
val, ok := env[name]
|
|
val, ok := env[name]
|
|
|
if ok {
|
|
if ok {
|
|
|
if len(index) > 0 {
|
|
if len(index) > 0 {
|
|
|
- val = value{word: toString(val)}
|
|
|
|
|
for _, i := range index {
|
|
for _, i := range index {
|
|
|
- list := parseList(val.word)
|
|
|
|
|
- r := strings.Split(i, ":")
|
|
|
|
|
|
|
+ list := parseList(val.String())
|
|
|
|
|
+ r, s := strings.Split(i, ":"), ""
|
|
|
if len(r) == 1 {
|
|
if len(r) == 1 {
|
|
|
- val = value{word: indexOfList(list, toInt(value{word: r[0]}, envs))}
|
|
|
|
|
- if !isList(val) {
|
|
|
|
|
- val.word = `"` + val.word
|
|
|
|
|
|
|
+ s = indexOfList(list, toInt(&_unknown{s: r[0]}, envs))
|
|
|
|
|
+ if !isList(&_unknown{s: s}) {
|
|
|
|
|
+ s = `"` + s
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
num1, num2 := 0, len(list)
|
|
num1, num2 := 0, len(list)
|
|
|
- if r[0] != "" {
|
|
|
|
|
- num1 = toInt(value{word: r[0]}, envs)
|
|
|
|
|
|
|
+ if len(r[0]) > 0 {
|
|
|
|
|
+ num1 = toInt(&_unknown{s: r[0]}, envs)
|
|
|
}
|
|
}
|
|
|
- if r[1] != "" {
|
|
|
|
|
- num2 = toInt(value{word: r[1]}, envs)
|
|
|
|
|
|
|
+ if len(r[1]) > 0 {
|
|
|
|
|
+ num2 = toInt(&_unknown{s: r[1]}, envs)
|
|
|
}
|
|
}
|
|
|
- val = value{word: rangeOfList(list, num1, num2)}
|
|
|
|
|
|
|
+ s = rangeOfList(list, num1, num2)
|
|
|
}
|
|
}
|
|
|
|
|
+ val = &_unknown{s: s}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return val, nil
|
|
return val, nil
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return value{}, fmt.Errorf("get: %s (%s)", errNameNotFound, name)
|
|
|
|
|
|
|
+ return nil, fmt.Errorf("get: %s (%s)", errNameNotFound, name)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func opMake(val1, val2 value, envs []environ) value {
|
|
func opMake(val1, val2 value, envs []environ) value {
|
|
|
- val, err := setValue(val1.word, val2, envs)
|
|
|
|
|
|
|
+ val, err := setValue(val1.String(), val2, envs)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
panic(err)
|
|
panic(err)
|
|
|
}
|
|
}
|
|
@@ -84,7 +84,7 @@ func opMake(val1, val2 value, envs []environ) value {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func opThing(val1 value, envs []environ) value {
|
|
func opThing(val1 value, envs []environ) value {
|
|
|
- val, err := getValue(val1.word, envs)
|
|
|
|
|
|
|
+ val, err := getValue(val1.String(), envs)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
panic(err)
|
|
panic(err)
|
|
|
}
|
|
}
|
|
@@ -119,7 +119,7 @@ func opSave(val1 value, env environ) value {
|
|
|
name := toName(val1)
|
|
name := toName(val1)
|
|
|
s := ""
|
|
s := ""
|
|
|
for name, val := range env {
|
|
for name, val := range env {
|
|
|
- s += `make "` + name + " " + val.word + "\n"
|
|
|
|
|
|
|
+ s += `make "` + name + " " + val.String() + "\n"
|
|
|
}
|
|
}
|
|
|
err := ioutil.WriteFile(name, []byte(s), 0666)
|
|
err := ioutil.WriteFile(name, []byte(s), 0666)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -128,7 +128,7 @@ func opSave(val1 value, env environ) value {
|
|
|
return val1
|
|
return val1
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func opLoad(val1 value, env environ) value {
|
|
|
|
|
|
|
+func opLoad(val1 value, env environ) *_bool {
|
|
|
name := toName(val1)
|
|
name := toName(val1)
|
|
|
s, err := ioutil.ReadFile(name)
|
|
s, err := ioutil.ReadFile(name)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -137,20 +137,20 @@ func opLoad(val1 value, env environ) value {
|
|
|
scanner := bufio.NewScanner(strings.NewReader(string(s)))
|
|
scanner := bufio.NewScanner(strings.NewReader(string(s)))
|
|
|
scanner.Split(splitFunc)
|
|
scanner.Split(splitFunc)
|
|
|
interpret(&scanProvider{isList: false, scanner: scanner}, []environ{env, nil, nil})
|
|
interpret(&scanProvider{isList: false, scanner: scanner}, []environ{env, nil, nil})
|
|
|
- return value{tp: typeBool, b: true}
|
|
|
|
|
|
|
+ return &_bool{b: true}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func opErAll(env environ) value {
|
|
|
|
|
|
|
+func opErAll(env environ) *_bool {
|
|
|
for name := range env {
|
|
for name := range env {
|
|
|
delete(env, name)
|
|
delete(env, name)
|
|
|
}
|
|
}
|
|
|
- return value{tp: typeBool, b: true}
|
|
|
|
|
|
|
+ return &_bool{b: true}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func opPoAll(env environ) value {
|
|
|
|
|
|
|
+func opPoAll(env environ) *_list {
|
|
|
list := []string{}
|
|
list := []string{}
|
|
|
for name := range env {
|
|
for name := range env {
|
|
|
list = append(list, name)
|
|
list = append(list, name)
|
|
|
}
|
|
}
|
|
|
- return value{tp: typeList, list: list}
|
|
|
|
|
|
|
+ return &_list{list: list}
|
|
|
}
|
|
}
|