Commit Graph

50 Commits

Author SHA1 Message Date
Qi Xiao
a9f28832c4 pkg/parse: Improve coverage of quote.go. 2021-09-17 20:24:20 +01:00
Qi Xiao
4d62732ebc Fix "indicies" -> indices. 2021-08-22 23:31:26 +01:00
Shengjing Zhu
5724ec4c47 Fix typos and add codespell to CI 2021-08-22 23:07:34 +01:00
Qi Xiao
671c76be00 Add a lint Makefile target and CI task.
Both run staticcheck and go vet (but not golint).

Also make some small changes necessary to make the codebase lint-free under
staticcheck.
2021-07-08 00:13:38 +01:00
Qi Xiao
321a4e78eb Merge branch 'master' into reader-gone 2021-06-15 22:09:40 +01:00
Qi Xiao
83c81cc5b2 Fix unused symbols found by staticcheck.
Also consolidate pkg/sys/testutil_test.go into pkg/sys/select_test.go.
2021-06-15 17:46:31 +01:00
Kurtis Rader
12c7a08c97 Increase parse/string.go coverage from 44% to 70%
This is an unusual change in that it exists solely to exercise generated
code and thus increase test coverage. On the one hand, if we never care
about the string value of type `RedirMode` then it should be removed
from the stringified types. On the other hand, verifying a redirection
is correctly represented in the output of the parse.pprint...() family
of functions is useful given the importance of I/O redirections in shells
like Elvish.
2021-06-10 09:17:16 +01:00
Qi Xiao
fd70a5a274 pkg/eval/errs: Add ReaderGone error type.
Also fix the error message of SetReadOnlyVar.
2021-05-18 20:34:44 +01:00
Qi Xiao
b43e5b8793 Rename the query DSL to the filter DSL. 2021-03-28 23:52:25 +01:00
Qi Xiao
634d71dcba Extract utilities for compound nodes into pkg/parse/cmpd. 2021-02-24 00:02:47 +00:00
Qi Xiao
30ab4d4d80 pkg/parse: Introduce a new Query node type.
A Query is a sequence of compound expressions or pairs, like the arguments
and options in a command form. It is not used by any other node type, and is
intended to be a top-level node for representing a small DSL for filtering data,
such as the filter for history mode or location mode.

This addresses #1051.
2021-02-02 02:30:08 +00:00
Qi Xiao
6ef46a7c5f pkg/parse: Refactor tests.
- Consolidate non-error tests and error tests.

- Test different node types using the ParseAs function.
2021-02-02 02:21:02 +00:00
Qi Xiao
c96bfade21 pkg/parse: Small API tweak. 2021-02-01 14:20:56 +00:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
22dc0e6a6b Move parsing of ordinary assignment form to the compile phase.
This will unblock the implementation of the "var" special command.

This addresses #645.
2021-01-16 01:48:51 +00:00
Qi Xiao
5f7bcb91e5 Make the syntax for the argument of "del" consistent with assignment LHS.
This fixes #1218.
2021-01-13 23:27:38 +00:00
Qi Xiao
e040a4650f Quote variable names where applicable when completing variables. 2021-01-12 23:06:23 +00:00
Qi Xiao
80e944bee2 Support using arbitrary character in variable names by quoting. 2021-01-12 23:06:19 +00:00
Qi Xiao
7584319b69 pkg/parse: MultiError -> Error; add a GetError function. 2021-01-01 23:19:03 +00:00
Kurtis Rader
9c7c9cf7d9 [cleanup] trivial golint suggested changes
As with commit #eb2a792 I acknowledge that `golint` recommendations are
controversial and should not automatically be acted on. Nonetheless,
this change fixes legitimate lint issues such as copy/paste cleanups,
style problems I introduced (`i += 1` versus `i++`) or method/var comments
that are not in the preferred form.
2020-12-25 01:11:33 +00:00
Kurtis Rader
b5b3a0d607 go vet cleanup
Most of the code uses keyed fields in composite literals; i.e., struct
literals. However, running `go vet ./...` reports a few places that use
anonymous fields. This modifies those composite literals to use keyed
fields. This does make the code a bit more verbose without reducing
the likelihood of a bug. But it does make the code more consistent, use
best practices, and make it easier to notice if a potential problem is
introduced when running `go vet ./...` since that command now produces
no diagnostic output.

I considered adding a `make vet` target that explicitly ran

    go vet -composites=false ./...

I decided not to do that since consistently using keyed composite literals
is preferable to having a mix of keyed and unkeyed composite literals.

This also removes the unused `ExampleLoop` function which causes this
`go vet` warning:

    pkg/cli/loop_test.go:130:1: ExampleLoop refers to unknown identifier: Loop
2020-09-03 04:24:06 +01:00
Qi Xiao
cfcc53ac97 pkg/parse: Make \ a valid bareword character.
This fixes #979.
2020-08-17 05:01:53 +01:00
Kurtis Rader
28798ac053 Convert "XXX" to "TODO" comments
I stumbled across a comment that began with "XXX". It was clearly meant as
a "TODO" comment. This changes all such occurrences. However, a few "XXX"
comments are ambiguous and a better prefix might be "WARNING". The "TODO"
prefix at least ensures someone, eventually, looks into the situation
and either rewords the comment or fixes the problem. This change means
everyone can assume searching for "// TODO" will find all such comments
rather than requiring they also know to search for "// XXX".
2020-08-16 16:29:34 +01:00
Qi Xiao
9b754d44d8 Remove the path attribute of the output of src. 2020-08-16 16:23:01 +01:00
Qi Xiao
0c2d05f260 Remove support for using \ for line continuation. 2020-08-16 16:16:24 +01:00
Kurtis Rader
082052b5a8 Document double-quoted string escape sequences 2020-08-11 16:07:58 +01:00
Qi Xiao
06a00f4a5f pkg/parse: Show deprecation warning when using \ for line continuation.
This addresses #979.
2020-07-01 21:39:29 +01:00
Qi Xiao
28c076d64e pkg/parse: Convert Source into a structmap. 2020-06-28 11:56:29 +01:00
Qi Xiao
555b47bbd2 pkg/parse: Support using ^ for line continuation.
This fixes #989.
2020-05-05 00:28:37 +01:00
Qi Xiao
6fc83a03bf Support comments everywhere newline is treated as whitespace.
This fixes #924.
2020-05-05 00:19:51 +01:00
Qi Xiao
06901fb3c1 pkg/parse: Support \r\n in Elvish sources.
This fixes #918.
2020-05-03 22:54:02 +01:00
Qi Xiao
4d54943ffb Reintroduce the path field of Source as a deprecated feature. 2020-04-25 19:26:04 +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
13f7b29707 pkg/parse: Add a new Parse function and a Tree type.
This replaces the AsChunk function. All current users of parse.AsChunk has been
changed to use parse.Parse instead.
2020-04-25 19:16:22 +01:00
Qi Xiao
21f5a6f7c3 pkg/parse: Turn most public methods of Node into functions.
This make the godoc of the parse package much cleaner and removes some
boilerplate.
2020-04-25 18:55:44 +01:00
Qi Xiao
4b93d4579d pkg/parse: De-export the pprint functions. 2020-04-25 18:31:49 +01:00
Qi Xiao
b8505c7065 pkg/eval/source.go -> pkg/parse/source.go. 2020-04-25 18:26:17 +01:00
Qi Xiao
dc564dbffb pkg/parse: Add more test against error cases in parse.go.
Also clean up a few small historical artifacts in parse.go.
2020-04-17 00:14:10 +01:00
Qi Xiao
ba554bfc1e pkg/parse: Make TestParseError much more rigorous. 2020-04-16 23:19:23 +01:00
Qi Xiao
224a0df825 pkg/parse: Remove ExitusNode.
This construct is no longer compiled or evaluated.
2020-04-16 22:29:49 +01:00
Qi Xiao
a36a372624 pkg: Fix small issues found by staticcheck. 2020-04-13 13:56:10 +01:00
Qi Xiao
7832239b78 pkg/parse: Add skeleton tests for error.go.
Also rename the PPrint method to Show to keep up with a previous change.

This addresses #944.
2020-04-02 05:57:06 +01:00
Qi Xiao
c05f11d3dc [cleanup] pkg/diag: PPrint -> Show. 2020-03-31 00:27:08 +01:00
Qi Xiao
9bebf49b40 pkg/diag: Let NewContext accept a Ranging. 2020-03-28 22:12:42 +00:00
Qi Xiao
d35111c7b0 Format Go files and rerun go generate. 2020-03-28 21:38:17 +00:00
Qi Xiao
6b6029452f Revert "Validate namespace and function names"
This breaks the use of meta characters in names of user-defined functions. See
b.elv.sh/946 on how to resolve the inconsistency on the restrictions in variable
names.

This reverts commit 02f5433789.
2020-03-22 22:06:14 +00:00
Kurtis Rader
02f5433789 Validate namespace and function names
Resolves #561
2020-03-20 23:15:02 +00:00
Qi Xiao
6d4abe1666 pkg/eval: Handle ~username/* correctly.
This fixes #793.
2020-01-14 08:03:41 -05:00
Qi Xiao
6da3f5e9de pkg/parse: Remove the Error type; use diag.Error instead. 2019-12-29 23:23:13 +00:00
Qi Xiao
e45fdf7228 Move all libraries to new pkg/. 2019-12-23 20:00:59 +00:00