Commit Graph

136 Commits

Author SHA1 Message Date
Yehuda Katz
4d3e7efe25 Close a bunch of holes in external command args
Previously, there was a single parsing rule for "bare words" that
applied to both internal and external commands.

This meant that, because `cargo +nightly` needed to work, we needed to
add `+` as a valid character in bare words.

The number of characters continued to grow, and the situation was
becoming untenable. The current strategy would eventually eat up all
syntax and make it impossible to add syntax like `@foo` to internal
commands.

This patch significantly restricts bare words and introduces a new token
type (`ExternalWord`). An `ExternalWord` expands to an error in the
internal syntax, but expands to a bare word in the external syntax.

`ExternalWords` are highlighted in grey in the shell.
2019-09-09 10:43:10 -07:00
Jonathan Turner
b84c77d23a
Merge pull request #603 from jonathandturner/oop_to_table
Move internal terminology to tables/rows
2019-09-06 05:22:24 +12:00
Jonathan Turner
dcd97b6346 Move internal terminology to tables/rows 2019-09-06 04:23:42 +12:00
George Pollard
60212611e5
Allow leading space before head of pipeline 2019-09-05 04:13:07 +12:00
George Pollard
6034de641a
Improve parsing of pipelines, require pipes
At the moment the pipeline parser does not enforce
that there must be a pipe between each part of the pipeline,
which can lead to confusing behaviour or misleading errors.
2019-09-05 03:30:51 +12:00
Jonathan Turner
7bd2fa1bfc
Merge pull request #580 from est31/trailing_spaces
Trim trailing whitespace and set it in editorconfig
2019-09-03 16:25:41 +12:00
est31
cf0efb811e Trim trailing whitespace and set it in editorconfig 2019-09-03 02:52:52 +02:00
est31
225ef8e75d Use serde to deserialize the remaining things 2019-09-03 02:10:48 +02:00
est31
cc8872b4ee Use serde to deserialize Tagged<Value> 2019-09-03 01:41:26 +02:00
est31
9ba2e75ac1 Move code into separate visit function 2019-09-03 01:32:54 +02:00
est31
e8880a1a57 Deserialize Block using serde 2019-09-02 22:30:51 +02:00
est31
9b3a561e83 Small refactor 2019-09-02 22:06:46 +02:00
Yehuda Katz
7fa09f59c2 Remove unused code
Closes #467
2019-09-01 23:11:05 -07:00
Yehuda Katz
246c9c06dc
Merge pull request #569 from est31/serde_instead_of_specialization
Remove use of ExtractType in deserialize_any
2019-09-01 22:39:13 -07:00
Yehuda Katz
3d5e31c55d
Merge pull request #571 from nushell/bigint
Migrated numerics to BigInt/BigDecimal
2019-09-01 22:08:48 -07:00
Yehuda Katz
8a29c9e6ab Migrated numerics to BigInt/BigDecimal
This commit migrates Value's numeric types to BigInt and BigDecimal. The
basic idea is that overflow errors aren't great in a shell environment,
and not really necessary.

The main immediate consequence is that new errors can occur when
serializing Nu values to other formats. You can see this in changes to
the various serialization formats (JSON, TOML, etc.). There's a new
`CoerceInto` trait that uses the `ToPrimitive` trait from `num_traits`
to attempt to coerce a `BigNum` or `BigDecimal` into a target type, and
produces a `RangeError` (kind of `ShellError`) if the coercion fails.

Another possible future consequence is that certain performance-critical
numeric operations might be too slow. If that happens, we can introduce
specialized numeric types to help improve the performance of those
situations, based on the real-world experience.
2019-09-01 21:00:30 -07:00
est31
113c2c380f deserialize_any isn't used any more 2019-09-02 04:07:02 +02:00
est31
bbde86c20d Use serde to deserialize bare bools
There are still tagged bools in use so we can't
remove the ExtractType implementation.
2019-09-02 03:45:00 +02:00
est31
a69a0bc5ee Use serde to deserialize options 2019-09-02 03:40:21 +02:00
est31
e8bbd330e0 Deserialize tuples with serde 2019-09-02 03:40:18 +02:00
est31
79a779dbea Deserialize vecs with serde 2019-09-02 03:37:30 +02:00
est31
5491b54859 Make key and struct_field optional in DeserializerItem
The main point of this struct seems to be debugging,
as key_struct_field is unused except for debugging.
2019-09-02 03:31:11 +02:00
Jonathan Turner
f9d54c2f25 Allow % in bare words 2019-09-02 12:32:15 +12:00
Jonathan Turner
6e0cb6b809
Merge pull request #563 from est31/field_shorthand
Adopt field init shorthand in a few places
2019-09-02 11:45:32 +12:00
est31
8504c7a8e6 Adopt field init shorthand in a few places
Found by running 'egrep "(\b[a-zA-Z]+): \1\b" -R src'
2019-09-01 23:39:59 +02:00
Dirkjan Ochtman
8523ce3d01 Get rid of feature(crate_visibility_modifier) (see #362) 2019-09-01 21:56:17 +02:00
Andrés N. Robalino
ca0c6eaf58 This commit introduces a basic help feature. We can go to it
with the `help` command to explore and list all commands available.

Enter will also try to see if the location to be entered is an existing
Nu command, if it is it will let you inspect the command under `help`.

This provides baseline needed so we can iterate on it.
2019-08-31 19:06:11 -05:00
Yehuda Katz
138b5af82b Basic support for decimal numbers
This commit is more substantial than it looks: there was basically no
real support for decimals before, and that impacted values all the way
through.

I also made Size contain a decimal instead of an integer (`1.6kb` is a
reasonable thing to type), which impacted a bunch of code.

The biggest impact of this commit is that it creates many more possible
ways for valid nu types to fail to serialize as toml, json, etc. which
typically can't support the full range of Decimal (or Bigint, which I
also think we should support). This commit makes to-toml fallible, and a
similar effort is necessary for the rest of the serializations.

We also need to figure out how to clearly communicate to users what has
happened, but failing to serialize to toml seems clearly superior to me
than weird errors in basic math operations.
2019-08-30 21:05:32 -07:00
Jonathan Turner
fa2c6ec227 Merge master 2019-08-31 10:13:09 +12:00
Taiki Endo
58a32490c5 Remove usage of in_band_lifetimes feature 2019-08-30 01:32:31 +09:00
est31
c87fa14fc8 Replace crate visibility identifier with pub(crate)
Result of running:

find src -name *.rs -exec sed -i 's/crate /pub(crate) /g' {} \;
2019-08-29 13:09:09 +02:00
Jonathan Turner
f730296e45 WIP supporting from/to automatically 2019-08-29 15:53:45 +12:00
Jonathan Turner
e0a13de943 Remove bind_by_move nightly feature 2019-08-29 14:44:08 +12:00
Yehuda Katz
dfe452bbc4 Remove unwraps from the parser
I intend to add regression tests for these cases to the parser as a
follow-up PR.

Fixes #490
Fixes #494
2019-08-27 14:20:18 -07:00
Yehuda Katz
34292b282a Add support for ~ expansion
This ended up being a bit of a yak shave. The basic idea in this commit is to
expand `~` in paths, but only in paths.

The way this is accomplished is by doing the expansion inside of the code that
parses literal syntax for `SyntaxType::Path`.

As a quick refresher: every command is entitled to expand its arguments in a
custom way. While this could in theory be used for general-purpose macros,
today the expansion facility is limited to syntactic hints.

For example, the syntax `where cpu > 0` expands under the hood to
`where { $it.cpu > 0 }`. This happens because the first argument to `where`
is defined as a `SyntaxType::Block`, and the parser coerces binary expressions
whose left-hand-side looks like a member into a block when the command is
expecting one.

This is mildly more magical than what most programming languages would do,
but we believe that it makes sense to allow commands to fine-tune the syntax
because of the domain nushell is in (command-line shells).

The syntactic expansions supported by this facility are relatively limited.
For example, we don't allow `$it` to become a bare word, simply because the
command asks for a string in the relevant position. That would quickly
become more confusing than it's worth.

This PR adds a new `SyntaxType` rule: `SyntaxType::Path`. When a command
declares a parameter as a `SyntaxType::Path`, string literals and bare
words passed as an argument to that parameter are processed using the
path expansion rules. Right now, that only means that `~` is expanded into
the home directory, but additional rules are possible in the future.

By restricting this expansion to a syntactic expansion when passed as an
argument to a command expecting a path, we avoid making `~` a generally
reserved character. This will also allow us to give good tab completion
for paths with `~` characters in them when a command is expecting a path.

In order to accomplish the above, this commit changes the parsing functions
to take a `Context` instead of just a `CommandRegistry`. From the perspective
of macro expansion, you can think of the `CommandRegistry` as a dictionary
of in-scope macros, and the `Context` as the compile-time state used in
expansion. This could gain additional functionality over time as we find
more uses for the expansion system.
2019-08-26 21:03:24 -07:00
Jonathan Turner
439700b87c Fix a few issues with textview and the parser 2019-08-25 19:15:56 +12:00
est31
8af4713237 Replace type_name intrinsic by stable type_name 2019-08-24 17:52:36 +02:00
Jonathan Turner
e3e4e30fb3 Lots of fixes ahead of release 2019-08-21 18:39:57 +12:00
Odin Dutton
b5b8e4c8b0 Fix warnings 2019-08-19 19:59:41 +10:00
Yehuda Katz
5bfb96447a Reduce unwraps
Remove a number of unwraps. In some cases, a `?` just worked as is. I also made it possible to use `?` to go from Result<OutputStream, ShellError> to OutputStream. Finally, started updating PerItemCommand to be able to use the signature deserialization logic, which substantially reduces unwraps.

This is still in-progress work, but tests pass and it should be clear to merge and keep iterating on master.
2019-08-16 20:53:39 -07:00
Yehuda Katz
0dc4b2b686 Add support for external escape valve (^dir)
This commit makes it possible to force nu to treat a command as an external command by prefixing it with `^`. For example `^dir` will force `dir` to run an external command, even if `dir` is also a registered nu command.

This ensures that users don't need to leave nu just because we happened to use a command they need.

This commit adds a new token type for external commands, which, among other things, makes it pretty straight forward to syntax highlight external commands uniquely, and generally to treat them as special.
2019-08-15 15:18:18 -07:00
Jonathan Turner
efd9631a90 All tests pass 2019-08-15 17:46:19 +12:00
Jonathan Turner
dd18122a24 WIP 2019-08-15 17:02:02 +12:00
Jonathan Turner
aadacc2d36 Merge master 2019-08-09 16:51:21 +12:00
Yehuda Katz
14a52bc282 WIP - more streamlining 2019-08-06 09:26:33 -07:00
Jonathan Turner
99671b8ffc Move more parts to tags and away from spans 2019-08-05 20:54:29 +12:00
Yehuda Katz
586aa6bae1 WIP - types check 2019-08-02 19:17:28 -07:00
Yehuda Katz
fc173c46d8 Restructuring 2019-08-02 12:15:07 -07:00
Jonathan Turner
a966e88424 Add question mark parsing 2019-08-02 15:15:04 +12:00
Jonathan Turner
8de50ae565 Allow wildcard globs to be used in a bare word 2019-08-02 12:03:28 +12:00