Updates parser to throw errors when a `!` is inappropriateley present/absent from the name given to a proc"

This commit is contained in:
sloum 2023-11-30 13:38:18 -08:00
parent 1a3eabd153
commit a7fe20ca08
2 changed files with 8 additions and 2 deletions

View File

@ -28,7 +28,7 @@ import (
)
const (
version float64 = 0.32
version float64 = 0.33
logo string = ` _
|, _ |. __ _
| (/,||_) (/,`
@ -47,7 +47,7 @@ var completions = []string{
"file-exists?", "file-read", "docstring!", "input", "re-match?",
"re-find", "re-replace", "slice", "stackdepth", "net-get", "try", "throw",
"catch", "import", "rot", "each!", "filter!", "INT", "STRING", "FLOAT",
"LIST", "BOOL", "words", "time", "char-conv",
"LIST", "BOOL", "TYPE", "words", "time", "char-conv", "end",
}
//go:embed lib/std.fe

View File

@ -15,6 +15,7 @@ package main
import (
"fmt"
"os"
"strings"
)
/*
@ -243,6 +244,11 @@ func eatProcedure(r *tokenReader, line int, hasArg bool, f string) (token, error
return token{}, fmt.Errorf("proc expected a name on line %d of %s", name.line, f)
}
p.name = name.val.(string)
if hasArg && !strings.HasSuffix(p.name, "!") {
return token{}, fmt.Errorf("proc! was passed a name (%q) that does not end with a '!' on line %d of %s", p.name, name.line, f)
} else if !hasArg && strings.HasSuffix(p.name, "!") {
return token{}, fmt.Errorf("proc was passed a name (%q) that ends with a '!' on line %d of %s", p.name, name.line, f)
}
doc, err := r.Read()
if err != nil {
return token{}, fmt.Errorf("eof reached without closing of procedure near line %d of %s", line, f)