Commit Graph

424 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 Rothberg
e54cd98a9c Put code into None case of last match. 2019-10-02 20:41:53 -07:00
Jonathan Rothberg
f3eb4fb24e Attempt at fixing get command panic.
If possible matches are not found then check if the passed in `obj`
parameter is a `string` or a `path`, if so then return it.  I am not
sure this is the right fix, but I figured I would make an attempt and
get a conversation started about it.
2019-10-02 20:16:27 -07:00
Jonathan Rothberg
093b9c1c5b Fixed last command crash
When the last command has an input value larger than the data its
operating on it would crash.  Added a check to ensure there are enough
elements to take.
2019-09-29 20:20:18 -07:00
Jonathan Turner
348d75112f
Merge pull request #736 from pizzafox/fix/https-links
Use HTTPS where possible
2019-09-30 14:43:15 +13:00
Jonathan Turner
3c7b1ba854
Merge pull request #735 from rnxpyke/master
remove trailing newline after external command
2019-09-30 12:16:36 +13:00
rnxypke
3812037e2a remove trailing newline after external command 2019-09-30 00:43:23 +02:00
Jonathan Rothberg
83d82a09b2 Better handling of unexpected error case. 2019-09-29 14:43:39 -07:00
Jonah Snider
9c23d78513 docs: use HTTPS where possible
Signed-off-by: Jonah Snider <me@jonahsnider.ninja>
2019-09-29 09:03:51 -10:00
Jonathan Rothberg
ff92123d93 Merge remote-tracking branch 'upstream/master' into post-headers 2019-09-29 01:33:21 -07:00
Jonathan Rothberg
e1357a9541 Handle unexpected input and some cleanup. 2019-09-29 01:29:43 -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
Jonathan Rothberg
e12ba5be8f Added support for more post headers. 2019-09-28 19:03:10 -07:00
est31
1183d28b15 Remove uses of async_stream_block 2019-09-28 02:05:18 +02:00
est31
6aad0b8443 Remove async_stream_block from the prelude
... to indicate deprecation of its use
2019-09-26 02:39:59 +02:00
est31
9891e5ab81 Use async-stream crate to replace most async_stream_block invocations 2019-09-26 02:39:20 +02:00
Piotr Szczygieł
85cd03f899 Fix typo in echo usage message 2019-09-25 00:15:53 +02:00
Jonathan Turner
15481b7be1 Fix nth regression 2019-09-24 19:56:03 +12:00
Jonathan Turner
60b7da8ea7 Fix help regression 2019-09-24 19:45:41 +12:00
Pirmin Kalberer
9623a255c4 Include history path in env command 2019-09-20 10:37:05 +02:00
Pirmin Kalberer
112e5d096f Include config path in env command 2019-09-19 23:07:09 +02:00
Pirmin Kalberer
484d8c26ac Save history when leaving with Ctrl-C 2019-09-19 22:55:53 +02:00
Jonathan Turner
5ff94004c6 Add urlencode/urldecode 2019-09-19 16:25:29 +12: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
f6b82e4c0c Replace vtable with pivot command 2019-09-17 19:07:11 +12:00
Jonathan Turner
7fbd6ce232 Fix internal paths 2019-09-17 14:09:15 +12:00
Jonathan Turner
17855d37a4 Add env command 2019-09-16 19:52:58 +12:00
Yehuda Katz
19767ad551 Taking another stab at replacing Span with Tag 2019-09-14 11:48:45 -05: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
9382a7e64a Detach externals so they don't freeze while buffering 2019-09-14 05:51:40 +12:00
Jonathan Turner
53cb40d8f6 Add basic 'did you mean' support 2019-09-13 15:44:21 +12:00
Jonathan Turner
d629686a4b Merge master 2019-09-13 06:33:52 +12:00
Jonathan Turner
189877e4dd Improve help and make binary a primitive 2019-09-13 06:29:16 +12:00
Andrés N. Robalino
c2eefece0e Remove warnings. 2019-09-12 06:12:19 -05:00
Andrés N. Robalino
7838dac689 first and get coverage. 2019-09-12 05:22:58 -05:00
Maximilian Roos
3c9a0e0e1a
Merge branch 'master' into fmt 2019-09-11 10:36:54 -04:00
Maximilian Roos
127381497c
run rustfmt 2019-09-11 10:36:50 -04:00
Jonathan Turner
bee7c5639c
Revert "Migrate most uses of the Span concept to Tag" 2019-09-11 19:53:05 +12:00
Jonathan Turner
f05c7d6792
Merge pull request #628 from max-sixty/build-warnings
Fix build warnings & add CI
2019-09-11 18:40:03 +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
Andrés N. Robalino
f47349c1a0
Merge pull request #632 from nushell/improve-external-words
Close a bunch of holes in external command args
2019-09-10 12:37:43 -05:00
Andrés N. Robalino
540e93aa3a question mark character can also be in glob patterns. 2019-09-10 12:26:56 -05:00
Yehuda Katz
b15bb2c667 Added glob patterns to the syntax shapes
Bare words now represent literal file names, and globs are a different
syntax shape called "Pattern". This allows commands like `cp` to ask for
a pattern as a source and a literal file as a target.

This also means that attempting to pass a glob to a command that expects
a literal path will produce an error.
2019-09-10 09:00:50 -07:00
Andrés N. Robalino
ba8383ae2f to-[csv/tsv] fixes. 2019-09-10 07:00:25 -05:00
Maximilian Roos
ae74ba5bb0
Merge branch 'master' into build-warnings
# Conflicts:
#	src/commands/config.rs
2019-09-10 07:08:15 -04:00
Andrés N. Robalino
11ef007491 Paths can be displayed as strings. 2019-09-10 05:28:15 -05:00
Andrés N. Robalino
f61144006f config test harness. 2019-09-10 05:08:01 -05:00
Jonathan Turner
d1167151fc Add support for light tables 2019-09-10 05:10:52 +12:00
Maximilian Roos
cf2c19706e
fix build warnings & add CI 2019-09-09 06:03:01 -04:00
Jonathan Turner
448b1a4848 Make some plugins optional, move ps to plugin 2019-09-08 19:06:15 +12:00
Jonathan Turner
07151b8360
Merge pull request #615 from jonathandturner/echo
Fix exec::shell and add echo command
2019-09-08 14:30:24 +12:00
Jonathan Turner
9da896ad4e Attempt so simplify classified 2019-09-08 14:00:04 +12:00
Jonathan Turner
84628f298d Finish fixing failing tests. 2019-09-08 13:35:02 +12:00
Jonathan Turner
4cdaed1ad4 Add echo command 2019-09-08 11:43:53 +12:00
Jonathan Rothberg
7427ea51df Removed commented out code. 2019-09-07 15:43:30 -07:00
Jonathan Rothberg
7913ae76f8 Expand pwd command
Expand functionality of the pwd command to better handle the different
types of shells (e.g. FilesystemShell, ValueShell, etc.).
2019-09-07 15:31:16 -07:00
Jonathan Turner
90b358d60b
Merge pull request #612 from chhetripradeep/pchhetri/add-pwd-command
Adds pwd command
2019-09-08 06:02:38 +12:00
Pradeep Chhetri
ee301f9f54 Adds pwd command 2019-09-07 23:53:56 +08:00
Jonathan Turner
8be14a891d
Merge pull request #611 from jonathandturner/autoview_plugin
Protect autoview against missing plugins
2019-09-07 20:09:58 +12:00
Jonathan Turner
28fe31d565 Protect autoview against missing plugins 2019-09-07 19:32:07 +12:00
Jonathan Turner
e2b9370f10
Attempt to fix issue with ^C in Windows
This fixes the error case if we ^C during running an external command.  This needs testing across platforms before it lands.
2019-09-07 16:59:13 +12:00
Jonathan Turner
dcd97b6346 Move internal terminology to tables/rows 2019-09-06 04:23:42 +12:00
Jonathan Turner
0a9897c5ca Move us away from mixing OOP and spreadsheet to just spreadsheet 2019-09-05 04:29:49 +12:00
Jonathan Turner
479f0a566e Covert to_* commands to work on whole table 2019-09-04 18:48:40 +12:00
Patrick Meredith
1f05e98965 Refactor to make save.rs readable 2019-09-03 22:21:37 -04:00
Patrick Meredith
ab48d3a3f2 Support binary save 2019-09-03 21:50:23 -04:00
Andrés N. Robalino
b031d4cd77 can view list of commands for details. 2019-09-03 04:36:23 -05:00
Andrés N. Robalino
030d73147e can view help for a given command by entering a command. 2019-09-03 04:05:52 -05:00
Jonathan Turner
8a9cdcab17 Split fetch command away from open 2019-09-03 18:04:46 +12:00
Yehuda Katz
7fa09f59c2 Remove unused code
Closes #467
2019-09-01 23:11:05 -07:00
Yehuda Katz
ca0183a136 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 22:14:41 -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
Jonathan Turner
abfd417430 Fix unwrap in open 2019-09-02 11:55:33 +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
Jonathan Turner
7d46f9e860 Another attempt to fix the zombie processes 2019-09-02 04:45:30 +12:00
Jonathan Turner
a7e378d1c9 Fix unwraps in post 2019-09-01 18:44:56 +12: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
est31
5b7940b88c Update bson to 0.14 2019-08-31 18:47:14 +02:00
Jonathan Turner
0d6b85b5bf
Merge branch 'master' into post 2019-08-31 16:39:24 +12:00
Jonathan Turner
ad18c7f61a Finish magic post and magic receive 2019-08-31 16:08:59 +12: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
1d77595576 Merge branch 'master' into post 2019-08-31 15:12:03 +12:00
Jonathan Turner
f274df6753
Merge pull request #547 from jonathandturner/expand_list_sqlite
Expand lists loaded from sqlite
2019-08-31 14:49:07 +12:00
Jonathan Turner
2470e6dc24 Expand lists loaded from sqlite 2019-08-31 14:23:29 +12:00
Jonathan Turner
2cde4da43f Partially fix list support 2019-08-31 13:35:53 +12:00
Jonathan Turner
2cec8168c7 Merge master 2019-08-31 13:30:41 +12:00
Jonathan Turner
761cc3db14 Finish up enter and save 2019-08-31 12:59:21 +12:00
Patrick Meredith
3d147d1143 Add SQLite support 2019-08-30 20:54:45 -04:00
Jonathan Turner
fa2c6ec227 Merge master 2019-08-31 10:13:09 +12:00
Patrick Meredith
481722b80a Fix from_json to use Nothing 2019-08-30 17:34:35 -04:00
Jonathan Turner
c3abb3b687 Fix unwrap 2019-08-31 07:28:10 +12:00
Jonathan Turner
60bfa277d0 Experiment with async/await-enabled ps 2019-08-31 07:07:07 +12:00
Jonathan Turner
9e167713b3 Add post command 2019-08-31 06:27:15 +12:00
Jonathan Turner
729051fdd2
Merge pull request #407 from iamcodemaker/vi
WIP: add support for vi mode
2019-08-30 15:54:30 +12:00