Commit Graph

30 Commits

Author SHA1 Message Date
Qi Xiao
1be25a240c pkg/eval: Internal cleanups.
- 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.
2021-01-04 14:17:27 +00:00
Qi Xiao
7932f58201 pkg/eval: Add a (*Evaler).Call method for calling a function.
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.
2021-01-03 18:57:11 +00:00
Qi Xiao
3f6b5da2b9 pkg/shell: Print both parse and compile errors when using -compileonly -json.
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.
2021-01-03 16:32:04 +00:00
Qi Xiao
5f0e4fc196 pkg/eval: Remove the bool return value of GetCompilationError.
This is done for consistency with parse.GetError.
2021-01-01 23:27:11 +00:00
Qi Xiao
6419f4524a Implement namespaces using slices instead of maps.
More related improvements and cleanups will be done in followup commits.

This fixes #1139.
2020-12-25 17:46:46 +00:00
Kurtis Rader
19e158d08a Document builtin sleep and add tests
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
2020-08-31 20:22:47 +01:00
Qi Xiao
b04ea12d48 pkg/eval: Refactor effectOp and valuesOp, remove lvaluesOp.
* Make effectOp and valuesOp interfaces - implementations now handle the
  range information themselves.

* Remove lvaluesOp; it is no longer used.
2020-08-22 19:57:11 +01:00
Qi Xiao
ff7c500506 Deprecate the -source command. 2020-08-16 23:07:30 +01:00
Qi Xiao
d5df47f986 Deprecate has-{prefix suffix}. 2020-08-16 16:27:24 +01:00
Qi Xiao
bb24b63356 Remove builtin commands deprecated in v0.14.0. 2020-08-16 16:10:58 +01:00
Qi Xiao
2fb2c8e4a3 Fix the deprecation warnings for "ord" and "chr". 2020-08-16 16:02:48 +01:00
Gabriel Rauter
1124c10b56
Add str:from-utf8-bytes, str:to-utf8-bytes and move builtin ord and chr to str module (#1081)
* 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.
2020-08-13 21:56:28 +01:00
Kurtis Rader
720181be03 Fix two typos 2020-05-26 21:24:57 +01:00
Kurtis Rader
d9ec0447fc Implement math:pow and math:pow10
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
2020-05-03 21:40:10 +01:00
Qi Xiao
663b10d8e2 Suppress deprecations by default.
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.
2020-04-26 21:26:53 +01:00
Qi Xiao
90a34f2d19 pkg/eval: Support specifying a callback for the "time" builtin.
This fixes #295.
2020-04-26 21:11:01 +01:00
Qi Xiao
c211679f0c Move all variable creations to start of lexical scope.
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.
2020-04-26 19:05:16 +01:00
Qi Xiao
3e9d5e9e60 pkg/eval/str: Add join, replace and split.
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.
2020-04-26 17:01:10 +01:00
Qi Xiao
c767f92d01 Support compile-time deprecation.
This fixes #898.
2020-04-26 13:14:51 +01:00
Qi Xiao
88122a019e pkg: Simplify some APIs by using parse.Tree. 2020-04-25 19:36:35 +01:00
Qi Xiao
20979b44a2 pkg/parse: Use Source values, not pointers.
The Source type is small enough that using values is likely more efficient.
2020-04-25 19:22:38 +01:00
Qi Xiao
b8505c7065 pkg/eval/source.go -> pkg/parse/source.go. 2020-04-25 18:26:17 +01:00
Qi Xiao
8c71635ca3 pkg/eval: Move all assignments to the start of the pipeline they belong in.
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.
2020-03-28 23:49:30 +00:00
Qi Xiao
9bebf49b40 pkg/diag: Let NewContext accept a Ranging. 2020-03-28 22:12:42 +00:00
Qi Xiao
3abfc42a8e [cleanup] pkg/eval: Remove boilerplate.go. 2020-03-28 21:33:55 +00:00
Qi Xiao
e6b7d06e80 [cleanup] pkg/eval: Remove compiler.errorf and compiler.compiling.
All errors are now written using compiler.errorpf.
2020-03-28 21:33:55 +00:00
Qi Xiao
d306f33af6 [cleanup] pkg/eval: Let compiler.errorpf accept a single diag.Ranger. 2020-03-28 21:33:55 +00:00
Qi Xiao
4ef43e0bde pkg/eval: Inline the use of util.{Throw,Catch} in the compiler. 2020-01-12 17:55:17 -05:00
Qi Xiao
b3a48ed510 pkg/eval: Revamp Source. 2020-01-11 03:01:30 +00:00
Qi Xiao
e45fdf7228 Move all libraries to new pkg/. 2019-12-23 20:00:59 +00:00