Commit Graph

9 Commits

Author SHA1 Message Date
Qi Xiao
ae9e6d1565 Fixup for #1531.
- Fix the handling of actual occurrences of U+FFFD.

- Fix an existing bug of QuoteVariableName("$\n").
2022-06-11 21:26:32 +01:00
Kurtis Rader
d0f6858b95 Correctly encode strings with invalid UTF-8
In addition to fixing the encoding bugs standardize on \xNN notation for
bytes rather than \uNNNN; e.g., \x00 rather than \u0000.

Also, update the documentation for double-quoted strings to include the
\e sequence.

Fixes #1528
2022-06-11 20:42:06 +01:00
Qi Xiao
51e4d97568 interface{} -> any now that Elvish requires Go 1.18. 2022-03-20 16:17:19 +00:00
Qi Xiao
097e32b375 pkg/eval/vals: Add ReprPlain, Repr without pretty-printing.
Also de-export NoPretty now that it is no longer needed.
2021-12-31 21:05:07 +00:00
Qi Xiao
196eea21d4 Change module import path to src.elv.sh 2021-01-27 01:30:25 +00:00
Qi Xiao
b77a052e7e pkg/eval: Make Exception an interface.
This change is a preparation step for refining all *Op types to return Exception
as the error.

Keeping Exception as a struct type will make such a change error-prone, since
a (*Exception)(nil) != error(nil), so if an *Op returns a nil *Exception, it
is not nil if the return value is stored in an error-typed variable.
2021-01-08 00:56:45 +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
1f562505f3 Rework the API for introspecting exception causes.
* Use a "type" field to identify the type, instead of predicates in the exc:
  module.

* Make the reason values behave more like structmaps, including a Repr that
  mimics a map.

This fixes #208.
2020-06-30 22:27:07 +01:00
Qi Xiao
e45fdf7228 Move all libraries to new pkg/. 2019-12-23 20:00:59 +00:00