Commit Graph

192 Commits

Author SHA1 Message Date
Yehuda Katz
57af9b5040 Add Range and start Signature support
This commit contains two improvements:

- Support for a Range syntax (and a corresponding Range value)
- Work towards a signature syntax

Implementing the Range syntax resulted in cleaning up how operators in
the core syntax works. There are now two kinds of infix operators

- tight operators (`.` and `..`)
- loose operators

Tight operators may not be interspersed (`$it.left..$it.right` is a
syntax error). Loose operators require whitespace on both sides of the
operator, and can be arbitrarily interspersed. Precedence is left to
right in the core syntax.

Note that delimited syntax (like `( ... )` or `[ ... ]`) is a single
token node in the core syntax. A single token node can be parsed from
beginning to end in a context-free manner.

The rule for `.` is `<token node>.<member>`. The rule for `..` is
`<token node>..<token node>`.

Loose operators all have the same syntactic rule: `<token
node><space><loose op><space><token node>`.

The second aspect of this pull request is the beginning of support for a
signature syntax. Before implementing signatures, a necessary
prerequisite is for the core syntax to support multi-line programs.

That work establishes a few things:

- `;` and newlines are handled in the core grammar, and both count as
  "separators"
- line comments begin with `#` and continue until the end of the line

In this commit, multi-token productions in the core grammar can use
separators interchangably with spaces. However, I think we will
ultimately want a different rule preventing separators from occurring
before an infix operator, so that the end of a line is always
unambiguous. This would avoid gratuitous differences between modules and
repl usage.

We already effectively have this rule, because otherwise `x<newline> |
y` would be a single pipeline, but of course that wouldn't work.
2019-12-11 16:41:07 -08:00
Jonathan Turner
1dcbd89a89 Trying this as a workaround to the [[bin]] issue 2019-12-10 16:57:55 +13:00
Jonathan Turner
e2a95c3e1d Move str and inc to core plugins 2019-12-10 13:59:13 +13:00
Jonathan Turner
88f899d341 Move some plugins back to being core shippable plugins 2019-12-10 13:05:40 +13:00
Jonathan Turner
9f702fe01a Move the remainder of the plugins to crates 2019-12-10 07:39:51 +13:00
Jonathan Turner
91784218c0 Upgrade some dependencies 2019-12-09 06:56:21 +13:00
Jonathan Turner
8833969e4a Remove some unused deps 2019-12-07 20:23:29 +13:00
Jonathan Turner
38b7a3e32b WIP move post/fetch to plugins 2019-12-07 16:46:05 +13:00
Jonathan Turner
d12c16a331 Extract ps and sys subcrates. Move helper methods to UntaggedValue 2019-12-05 08:52:31 +13:00
Jonathan Turner
a4bb5d4ff5 Move binaryview to a sub-crate 2019-12-05 06:51:20 +13:00
Jonathan Turner
cfda67ff82 Finish making the textview plugin optional 2019-12-05 05:28:48 +13:00
Jonathan Turner
1fcf671ca4 Re-enable the textview plugin, now its own crate 2019-12-04 19:38:40 +13:00
Jonathan Turner
efc879b955 Add new line primitive, bump version, allow bare filepaths 2019-12-03 19:44:59 +13:00
Yehuda Katz
24bad78607 Clean up expansion of external words
Previously, external words accidentally used
ExpansionRule::new().allow_external_command(), when it should have been
ExpansionRule::new().allow_external_word().

External words are the broadest category in the parser, and are the
appropriate category for external arguments. This was just a mistake.
2019-12-02 16:34:33 -08:00
Yehuda Katz
87dbd3d5ac Extract build.rs 2019-12-02 13:14:51 -08:00
est31
d6a6e16d21 Switch to the new Cargo.lock format
This was achieved by deleting Cargo.lock
and letting a recent Cargo nightly re-create
it. Support for the format was already
introduced in Rust 1.38, but currently,
stable releases of Cargo only retain it
if encountered but don't generate such
files by default.

The new format is smaller, better suited to
prevent merge conflicts and generates smaller
diffs at dependency updates, leading to
smaller git history.

You can read more about it in this PR: https://github.com/rust-lang/cargo/pull/7070
2019-12-02 11:02:59 -08:00
Jonathan Turner
388ce738e3 expand tilde in externals 2019-12-02 11:02:58 -08:00
Jonathan Turner
80941ace37 Add 0.6.1 release 2019-12-02 11:02:58 -08:00
Jonathan Turner
1fb5a419a7 Bump the release version 2019-12-02 11:02:57 -08:00
Yehuda Katz
e4226def16 Extract core stuff into own crates
This commit extracts five new crates:

- nu-source, which contains the core source-code handling logic in Nu,
  including Text, Span, and also the pretty.rs-based debug logic
- nu-parser, which is the parser and expander logic
- nu-protocol, which is the bulk of the types and basic conveniences
  used by plugins
- nu-errors, which contains ShellError, ParseError and error handling
  conveniences
- nu-textview, which is the textview plugin extracted into a crate

One of the major consequences of this refactor is that it's no longer
possible to `impl X for Spanned<Y>` outside of the `nu-source` crate, so
a lot of types became more concrete (Value became a concrete type
instead of Spanned<Value>, for example).

This also turned a number of inherent methods in the main nu crate into
plain functions (impl Value {} became a bunch of functions in the
`value` namespace in `crate::data::value`).
2019-12-02 10:54:12 -08:00
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
Jonathan Turner
111fcf188e Add umask to unix --full list 2019-11-19 18:46:47 +13:00
Jonathan Turner
90aeb700ea Add from_xlsx for importing excel files 2019-11-17 16:18:41 +13:00
Jonathan Turner
db218e06dc Give rustyline non-ansi to begin with. Fixes Windows 2019-11-17 09:02:26 +13:00
Jonathan Turner
07db14f72e Merge master 2019-11-17 06:17:05 +13:00
Andrés N. Robalino
87d58535ff Downgrade futures-codec. 2019-11-12 14:04:53 -05:00
Jonathan Turner
0f405f24c7 Bump dep versions 2019-11-11 06:48:49 +13:00
Jonathan Turner
df302d4bac Bump Nu version and change plugin load logic for debug 2019-11-10 16:44:05 +13:00
Jonathan Turner
4cb399ed70 Bump version to 0.5.0 2019-11-06 18:24:04 +13:00
Yehuda Katz
4be88ff572 Modernize external parse and improve trace
The original purpose of this PR was to modernize the external parser to
use the new Shape system.

This commit does include some of that change, but a more important
aspect of this change is an improvement to the expansion trace.

Previous commit 6a7c00ea adding trace infrastructure to the syntax coloring
feature. This commit adds tracing to the expander.

The bulk of that work, in addition to the tree builder logic, was an
overhaul of the formatter traits to make them more general purpose, and
more structured.

Some highlights:

- `ToDebug` was split into two traits (`ToDebug` and `DebugFormat`)
  because implementations needed to become objects, but a convenience
  method on `ToDebug` didn't qualify
- `DebugFormat`'s `fmt_debug` method now takes a `DebugFormatter` rather
  than a standard formatter, and `DebugFormatter` has a new (but still
  limited) facility for structured formatting.
- Implementations of `ExpandSyntax` need to produce output that
  implements `DebugFormat`.

Unlike the highlighter changes, these changes are fairly focused in the
trace output, so these changes aren't behind a flag.
2019-11-01 08:45:45 -07:00
Jonathan Turner
d160e834eb rustyline git and add plus for filenames 2019-10-26 05:43:31 +13:00
jdvr
fc1301c92d #194 Added trash crate and send files to the trash using a flag 2019-10-19 00:41:24 +02:00
Jonathan Turner
d91b735442 Update cargo.lock 2019-10-16 15:09:47 +13:00
Jonathan Turner
2716bb020f
Fix #811 (#813) 2019-10-13 17:53:58 +13: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
439889dcef Feature flagging infrastructure
This commit adds the ability to work on features behind a feature flag
that won't be included in normal builds of nu.

These features are not exposed as Cargo features, as they reflect
incomplete features that are not yet stable.

To create a feature, add it to `features.toml`:

```toml
[hintsv1]

description = "Adding hints based on error states in the highlighter"
enabled = false
```

Each feature in `features.toml` becomes a feature flag accessible to `cfg`:

```rs
println!("hintsv1 is enabled");
```

By default, features are enabled based on the value of the `enabled` field.

You can also enable a feature from the command line via the
`NUSHELL_ENABLE_FLAGS` environment variable:

```sh
$ NUSHELL_ENABLE_FLAGS=hintsv1 cargo run
```

You can enable all flags via `NUSHELL_ENABLE_ALL_FLAGS`.

This commit also updates the CI setup to run the build with all flags off and
with all flags on. It also extracts the linting test into its own
parallelizable test, which means it doesn't need to run together with every
other test anymore.

When working on a feature, you should also add tests behind the same flag. A
commit is mergable if all tests pass with and without the flag, allowing
incomplete commits to land on master as long as the incomplete code builds and
passes tests.
2019-10-11 17:19:44 -07: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
Barnaby Keene
47150efc14 chore: switch starship dependency back to the main one 2019-10-09 08:36:55 +01:00
Barnaby Keene
ef3e8eb778 fix: update Cargo.lock with correct hash for starship fork 2019-10-08 21:16:52 +01:00
Barnaby Keene
fb8cfeb70d feat: starship prompt
Kind of touches on #356 by integrating the Starship prompt directly into the shell.

Not finished yet and has surfaced a potential bug in rustyline anyway. It depends on https://github.com/starship/starship/pull/509 being merged so the Starship prompt can be used as a library.

I could have tackled #356 completely and implemented a full custom prompt feature but I felt this was a simpler approach given that Starship is both written in Rust so shelling out isn't necessary and it already has a bunch of useful features built in.

However, I would understand if it would be preferable to just scrap integrating Starship directly and instead implement a custom prompt system which would facilitate simply shelling out to Starship.
2019-10-08 16:25:12 +01:00
rnxypke
9fb9adb6b4 add regex match plugin 2019-10-02 20:56:43 +02:00
est31
02d6614ae2 Use language-reporting from git as it supports Rust stable 2019-09-28 03:11:01 +02:00
est31
1801c006ec Remove futures-async-stream dependency 2019-09-28 02:07:28 +02:00
est31
9891e5ab81 Use async-stream crate to replace most async_stream_block invocations 2019-09-26 02:39:20 +02:00
Jonathan Turner
ffa536bea3 Add Cargo.lock 2019-09-25 07:02:35 +12:00
Jonathan Turner
2de7792939 Bump version to 0.3.0 for release 2019-09-24 19:29:23 +12:00
Pirmin Kalberer
1e3549571c Bind fuzzy history search to Ctrl-R 2019-09-19 20:18:39 +02:00
Jonathan Turner
5ff94004c6 Add urlencode/urldecode 2019-09-19 16:25:29 +12:00
Jonathan Turner
7fbd6ce232 Fix internal paths 2019-09-17 14:09:15 +12:00