The Error methods used to show the start and end indices, while the Show methods
used to show line ranges.
Showing line:col of the start position seems to be pretty standard; both Go and
Rust do that.
I tried including the line:col of the end position too, but can't find a good
enough format.
Rather than having specialized commands make a `file:pipe` object
indexable so we can use the generic `file:close` command. This does not
address existing problems; such as builtins not failing when writing to
a `file:pipe` object if the read-end is closed.
Related #1316
Prclose and pwclose with Deprecation marked in specific file. Give
feedback regarding the test cases.
File module now has prclose and pwclose
Wrote test cases for prclose and pwclose, need better test cases
Deprecation for prclose and pwclose marked in respective files.
This commit replaces scopeOp, the only remaining place that mutates *Ns in
place, with nsOp, which performs copy-on-write for *Ns.
As a result, the "eval" command no longer mutates the passed namespace. The
default namespace it uses is also changed to match the default of "-source" (an
amalgamated namespace from the local and upvalue scopes), making "-source $file"
equivalent to "eval (slurp <$file)", and formally deprecated.
Another result is that (*Evaler).Eval can now guard the mutation of the global
namespace with the mutex, making it concurrency-safe to execute multiple sources
that touch the global namespace.
This fixes#1137.
- Remove the Op type; it is no longer used by any code outside the eval package
and its use within the package is limited.
- Replace (*Evaler).execOp with (*Evaler).prepareFrame.
Most of the places that need to directly call a function is in the edit package,
which need to call user-defined callbacks.
This change eliminates most call sites of NewTopFrame (including all call sites
outside the eval package). Remove the function and inline it in the remaining
few call sites.
Remove NewTopFrame means that the eval package no longer offers other packages
a way to construct Frame instances. This is intended: Frame is a relatively
low-level concept, and all code outside the eval package now uses the more
high-level Eval, Call, Check/CheckTree methods of *Evaler. The most notable
exception is packages that implement modules; they may still use Frame to access
the information kept in it, but they never construct Frame instances.
In future, the Frame type can be changed to an interface.
The new (*Evaler).Check method allows the implementation to be simpler.
Also test the JSON format feature in an integration test instead of unit test;
this makes it unnecessary for the eval package to expose NewCompilationError.
I was reviewing test coverage and noticed that the `esleep`
implementation was undocumented and had no tests. This
a) implements `sleep` and deprecates `esleep`,
b) uses the Go time.ParseDuration function rather than assuming a
simple number of seconds,
c) documents the command,
d) adds tests of the function.
Related #1062
* pkg/eval/str: move builtin ord and chr to str
Move builtin string function ord and chr to the str module and rename to
to str:to-codepoints and str:from-codepoints respectively as suggested
in #851.
* pkg/eval/str: add from-utf8-bytes & to-utf8-bytes
Add from-utf8-bytes and to-utf8-bytes functions to the str module. This
functions differ from their *-codepoints in that they handle utf8 bytes
instead of whole codepoints. Closes#851
* pkg/eval/str: range check for codepoint and bytes
str:from-codepoints
Add check if arguments codepoints are within valid unicode range, return
an OutOfRange error otherwise. Return a BadValue error if the codepoint
isn't valid. Add/change testcases.
str:from-utf8-bytes
Add check if byte arguments are within valid range, return an OutOfRange
error otherwise. Return a BadValue error if the byte sequence isn't a
valid UTF-8 sequence. Add/change testcases.
Add additional test if piping from str:to-codepoints/str:to-utf8-bytes
to str:from-codpoints/str:from-utf8-bytes returns the original input.
To facilitate using the `^` character for line continuation we need to
remove its use an an exponentiation function. So introduce `math:pow`
and `math:pow10` as alternatatives and mark `^` as deprecated.
Related #989
The behavior is controlled by a global flag that will be flipped for the release
branch. A flag is available to force deprecations to be shown or hidden.
Commit 8c71635ca3 moved the creation to the start
of pipelines; the approach works for simplistic cases like "x = 1 | nop", but
fails in more complex cases, such as "nop (x = 1) | nop".
The correct place to hoist variable creations is the lexical scope, and this
commit implements this approach.
This fixes#623.
The implementations are mostly copied from the builtin joins, replaces and
splits, with small changes to the error behavior in the join function.
The versions in the builtin module are now deprecated.
This avoids race conditions of accessing the local scope. The test case
"x = 1", "put $x | y = (all)" used to contain a race condition but no longer
does.
This addresses #73.