Commit Graph

81 Commits

Author SHA1 Message Date
Yehuda Katz
1ad9d6f199 Overhaul the expansion system
The main thrust of this (very large) commit is an overhaul of the
expansion system.

The parsing pipeline is:

- Lightly parse the source file for atoms, basic delimiters and pipeline
  structure into a token tree
- Expand the token tree into a HIR (high-level intermediate
  representation) based upon the baseline syntax rules for expressions
  and the syntactic shape of commands.

Somewhat non-traditionally, nu doesn't have an AST at all. It goes
directly from the token tree, which doesn't represent many important
distinctions (like the difference between `hello` and `5KB`) directly
into a high-level representation that doesn't have a direct
correspondence to the source code.

At a high level, nu commands work like macros, in the sense that the
syntactic shape of the invocation of a command depends on the
definition of a command.

However, commands do not have the ability to perform unrestricted
expansions of the token tree. Instead, they describe their arguments in
terms of syntactic shapes, and the expander expands the token tree into
HIR based upon that definition.

For example, the `where` command says that it takes a block as its first
required argument, and the description of the block syntactic shape
expands the syntax `cpu > 10` into HIR that represents
`{ $it.cpu > 10 }`.

This commit overhauls that system so that the syntactic shapes are
described in terms of a few new traits (`ExpandSyntax` and
`ExpandExpression` are the primary ones) that are more composable than
the previous system.

The first big win of this new system is the addition of the `ColumnPath`
shape, which looks like `cpu."max ghz"` or `package.version`.
Previously, while a variable path could look like `$it.cpu."max ghz"`,
the tail of a variable path could not be easily reused in other
contexts. Now, that tail is its own syntactic shape, and it can be used
as part of a command's signature.

This cleans up commands like `inc`, `add` and `edit` as well as
shorthand blocks, which can now look like `| where cpu."max ghz" > 10`
2019-10-10 08:27:51 -07:00
Jonathan Turner
ce947d70b0 Rename SpanSource to AnchorLocation 2019-09-29 18:18:59 +13:00
Jonathan Turner
caed87c125 Rename origin to anchor 2019-09-29 18:13:56 +13:00
est31
9891e5ab81 Use async-stream crate to replace most async_stream_block invocations 2019-09-26 02:39:20 +02:00
Jonathan Turner
72e6222992 Switch to using Uuid::nil() and fix test 2019-09-18 19:05:33 +12:00
Jonathan Turner
2cf7249794 Fix autoview breakage 2019-09-18 18:37:04 +12:00
Jonathan Turner
7fbd6ce232 Fix internal paths 2019-09-17 14:09:15 +12:00
Yehuda Katz
ab915f1c44 Revert "Revert "Migrate most uses of the Span concept to Tag""
This reverts commit bee7c5639c.
2019-09-14 11:30:24 -05:00
Jonathan Turner
189877e4dd Improve help and make binary a primitive 2019-09-13 06:29:16 +12:00
Jonathan Turner
bee7c5639c
Revert "Migrate most uses of the Span concept to Tag" 2019-09-11 19:53:05 +12:00
Yehuda Katz
58b7800172 Migrate most uses of the Span concept to Tag
Also migrate mv, rm and commands like that to taking a
SyntaxType::Pattern instead of a SyntaxType::Path for their first
argument.
2019-09-10 20:41:03 -07:00
Jonathan Turner
dcd97b6346 Move internal terminology to tables/rows 2019-09-06 04:23:42 +12:00
Jonathan Turner
8a9cdcab17 Split fetch command away from open 2019-09-03 18:04:46 +12:00
Jonathan Turner
abfd417430 Fix unwrap in open 2019-09-02 11:55:33 +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
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
Jonathan Turner
1a67ac6102 Random fixes 2019-09-01 09:19:59 +12:00
Jonathan Turner
2cde4da43f Partially fix list support 2019-08-31 13:35:53 +12: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
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
Andrés N. Robalino
0e14ba86ae [from|to]csv additions/refactoring.
Introduced flag to tell `from-to` / `to-csv` whether we want headers parsed and/or written.
2019-08-25 12:32:08 -05:00
Patrick Meredith
a75c90cc42 Rebase on master 2019-08-25 10:16:22 -04:00
Patrick Meredith
a0f0372839 Add mostly working BSON support (missing some types) 2019-08-25 09:50:25 -04:00
Patrick Meredith
93a1a0604e Update how extensions are set to default to path when no extension can be determined from mime 2019-08-25 09:50:25 -04:00
Jonathan Turner
721a7b159d switch from reqwest to surf 2019-08-25 07:36:19 +12: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
6cf3dc92fc Add support for utf16 files 2019-08-12 16:11:42 +12:00
Jonathan Turner
d07a3928b2 Fix test failure 2019-08-11 08:33:22 +12:00
Jonathan Turner
8f78995014 Improve enter and fix bugs 2019-08-11 08:18:14 +12:00
Jonathan Turner
eeed31837f cleanup 2019-08-10 08:49:43 +12:00
Jonathan Turner
aadacc2d36 Merge master 2019-08-09 16:51:21 +12:00
Jonathan Turner
c231dd32cd
Multi shells (#254)
Add multi-shells
2019-08-08 05:49:11 +12:00
Jonathan Turner
ae5b781159 More touchups to errors 2019-08-06 15:03:13 +12: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
462f783fac initial change to Tagged<Value> 2019-08-01 13:58:42 +12:00
Jonathan Turner
8ac70e7408 Various open improvements 2019-07-30 15:48:02 +12:00
Yehuda Katz
73deeb69db Clean up lint errors 2019-07-23 21:10:48 -07:00
Yehuda Katz
5a8e041a48 Tests pass! 2019-07-23 15:22:11 -07:00
Andrés N. Robalino
191dacdd8b Introduced conversion to csv command. 2019-07-21 02:08:05 -05:00
Jonathan Turner
c36c2a7b50 Switch from_csv to output rows 2019-07-20 18:44:21 +12:00
Jonathan Turner
15507f00fc Introduce CallInfo, which abstracts args, name_span, and source_map 2019-07-20 14:27:10 +12:00
Jonathan Turner
1e6a9b9b34 Merge branch 'master' into source_spans 2019-07-20 13:14:05 +12:00
Andrés N. Robalino
895a1b2d72 Introduced ability to open csv documents. 2019-07-19 15:48:42 -05:00
Jonathan Turner
d5d4da0bf8 Add first step of uuid generation and bookkeeping 2019-07-20 07:48:14 +12:00
Jonathan Turner
be69df86a9 Add more formats 2019-07-18 07:05:20 +12:00
Jonathan Turner
00b3106f05 Improve open URL. Format and remove warning in tests 2019-07-18 06:56:15 +12:00