Commit Graph

32 Commits

Author SHA1 Message Date
Yehuda Katz
f70c6d5d48 Extract nu_source into a crate
This commit extracts Tag, Span, Text, as well as source-related debug
facilities into a new crate called nu_source.

This change is much bigger than one might have expected because the
previous code relied heavily on implementing inherent methods on
`Tagged<T>` and `Spanned<T>`, which is no longer possible.

As a result, this change creates more concrete types instead of using
`Tagged<T>`. One notable example: Tagged<Value> became Value, and Value
became UntaggedValue.

This change clarifies the intent of the code in many places, but it does
make it a big change.
2019-11-25 07:37:33 -08:00
Yehuda Katz
cdb0eeafa2 --no-edit 2019-11-21 14:22:32 -08:00
Andrés N. Robalino
6ea8e42331 Move column paths to support broader value types. 2019-11-03 05:38:47 -05:00
Jonathan Turner
193b00764b
Stream support (#812)
* Moves off of draining between filters. Instead, the sink will pull on the stream, and will drain element-wise. This moves the whole stream to being lazy.
* Adds ctrl-c support and connects it into some of the key points where we pull on the stream. If a ctrl-c is detect, we immediately halt pulling on the stream and return to the prompt.
* Moves away from having a SourceMap where anchor locations are stored. Now AnchorLocation is kept directly in the Tag.
* To make this possible, split tag and span. Span is largely used in the parser and is copyable. Tag is now no longer copyable.
2019-10-13 17:12:43 +13:00
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
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
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
est31
1d3483b590 Add a test 2019-09-09 13:39:43 +02:00
est31
1277bfe0fb Fix setting configuration params
Fixes #627

Fixes a regression caused by #579, specifically commit cc8872b4ee .

The code was intended to perform a comparison between the wanted
output type and "Tagged<Value>" in order to be able to provide a
special-cased path for Tagged<Value>. When I wrote the code, I
used "name" as a variable name and only later realized that it
shadowed the "name" param to the function, so I renamed it to
type_name, but forgot to change the comparison.
This broke the special-casing, as the name param only contains
the name of the struct without generics (like "Tagged"), while
`std::any::type_name` (in the current implementation) contains
the full paths of the struct including all generic params
(like "nu::object::meta::Tagged<nu::object::base::Value>").
2019-09-09 13:22:18 +02:00
Jonathan Turner
dcd97b6346 Move internal terminology to tables/rows 2019-09-06 04:23:42 +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
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
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
Taiki Endo
58a32490c5 Remove usage of in_band_lifetimes feature 2019-08-30 01:32:31 +09:00
est31
8af4713237 Replace type_name intrinsic by stable type_name 2019-08-24 17:52:36 +02: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
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
Yehuda Katz
fc173c46d8 Restructuring 2019-08-02 12:15:07 -07:00