Commit Graph

1534 Commits

Author SHA1 Message Date
Thomas Hartmann
5ec6bac7d9 Removes redundant parens. 2019-10-11 21:39:11 +02:00
Thomas Hartmann
af2ec60980 Shell.nix cleanup. 2019-10-11 21:13:00 +02:00
Thomas Hartmann
f0ca0312f3 Adds racer, formats shell.nix 2019-10-11 19:06:24 +02:00
Jonathan Turner
3317b137e5
Merge pull request #728 from nushell/better-pseudo-blocks
[DON'T MERGE] Overhaul the expansion system
2019-10-11 17:28:33 +13:00
Yehuda Katz
c2c10e2bc0 Overhaul the coloring system
This commit replaces the previous naive coloring system with a coloring
system that is more aligned with the parser.

The main benefit of this change is that it allows us to use parsing
rules to decide how to color tokens.

For example, consider the following syntax:

```
$ ps | where cpu > 10
```

Ideally, we could color `cpu` like a column name and not a string,
because `cpu > 10` is a shorthand block syntax that expands to
`{ $it.cpu > 10 }`.

The way that we know that it's a shorthand block is that the `where`
command declares that its first parameter is a `SyntaxShape::Block`,
which allows the shorthand block form.

In order to accomplish this, we need to color the tokens in a way that
corresponds to their expanded semantics, which means that high-fidelity
coloring requires expansion.

This commit adds a `ColorSyntax` trait that corresponds to the
`ExpandExpression` trait. The semantics are fairly similar, with a few
differences.

First `ExpandExpression` consumes N tokens and returns a single
`hir::Expression`. `ColorSyntax` consumes N tokens and writes M
`FlatShape` tokens to the output.

Concretely, for syntax like `[1 2 3]`

- `ExpandExpression` takes a single token node and produces a single
  `hir::Expression`
- `ColorSyntax` takes the same token node and emits 7 `FlatShape`s
  (open delimiter, int, whitespace, int, whitespace, int, close
  delimiter)

Second, `ColorSyntax` is more willing to plow through failures than
`ExpandExpression`.

In particular, consider syntax like

```
$ ps | where cpu >
```

In this case

- `ExpandExpression` will see that the `where` command is expecting a
  block, see that it's not a literal block and try to parse it as a
  shorthand block. It will successfully find a member followed by an
  infix operator, but not a following expression. That means that the
  entire pipeline part fails to parse and is a syntax error.
- `ColorSyntax` will also try to parse it as a shorthand block and
  ultimately fail, but it will fall back to "backoff coloring mode",
  which parsing any unidentified tokens in an unfallible, simple way. In
  this case, `cpu` will color as a string and `>` will color as an
  operator.

Finally, it's very important that coloring a pipeline infallibly colors
the entire string, doesn't fail, and doesn't get stuck in an infinite
loop.

In order to accomplish this, this PR separates `ColorSyntax`, which is
infallible from `FallibleColorSyntax`, which might fail. This allows the
type system to let us know if our coloring rules bottom out at at an
infallible rule.

It's not perfect: it's still possible for the coloring process to get
stuck or consume tokens non-atomically. I intend to reduce the
opportunity for those problems in a future commit. In the meantime, the
current system catches a number of mistakes (like trying to use a
fallible coloring rule in a loop without thinking about the possibility
that it will never terminate).
2019-10-10 19:30:04 -07:00
Thomas Hartmann
d2eb6f6646 Adds .envrc and shell.nix 2019-10-10 21:23:12 +02: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
Andrés N. Robalino
e18892000a
Merge pull request #802 from twe4ked/improve-cd-docs
Improve cd docs
2019-10-08 20:20:28 -05:00
Odin Dutton
4d70255696 Add documentation for cd - 2019-10-08 18:32:42 +11:00
Odin Dutton
77c34acb03 Whitespace 2019-10-08 18:32:42 +11:00
Odin Dutton
e72bc8ea8b Remove unneeded - 2019-10-08 18:32:39 +11:00
Jonathan Turner
a882e640e4
Merge pull request #793 from chhetripradeep/pchhetri/enter
Add documentation for the enter command
2019-10-08 06:02:49 +13:00
Pradeep Chhetri
c09d866a77 Add documentation for the enter command 2019-10-07 23:21:58 +08:00
Jonathan Turner
4467e59122
Merge pull request #792 from chhetripradeep/pchhetri/open
Add documentation for the open command
2019-10-07 11:17:28 +11:00
Jonathan Turner
9c096d320a
Merge pull request #797 from chhetripradeep/pchhetri/fetch
Add documentation for the fetch command
2019-10-07 11:16:36 +11:00
Pradeep Chhetri
9f15017032 Add documentation for the fetch command 2019-10-07 02:17:57 +08:00
Pradeep Chhetri
81fec11f88 Add documentation for the open command 2019-10-07 02:08:20 +08:00
Jonathan Turner
8a6a688131
Merge pull request #795 from chhetripradeep/pchhetri/inc
Add documentation for the inc command
2019-10-07 04:35:08 +11:00
Jonathan Turner
77a4de31fa
Merge pull request #794 from chhetripradeep/pchhetri/sys
Add documentation for the sys command
2019-10-07 04:33:51 +11:00
Jonathan Turner
09e88d127e
Merge pull request #791 from chhetripradeep/pchhetri/trim
Add documentation for the trim command
2019-10-07 04:30:52 +11:00
Pradeep Chhetri
7ff5734d5d Add documentation for the inc command 2019-10-06 23:30:52 +08:00
Pradeep Chhetri
1d19595996 Add documentation for the sys command 2019-10-06 23:20:48 +08:00
Pradeep Chhetri
7d115da782 Add documentation for the trim command 2019-10-06 22:35:38 +08:00
Andrés N. Robalino
b066775630
Merge pull request #789 from cristicismas/patch-1
Update cd.md to look better
2019-10-04 16:24:42 -05:00
Andrés N. Robalino
8bb6bcb6eb
Merge pull request #790 from mfarberbrodsky/add-nth-docs
Add documentation for nth command
2019-10-04 16:24:06 -05:00
Maya Farber Brodsky
20031861b9 Add documentation for nth command 2019-10-04 17:37:11 +03:00
Cristi Cismas
eb297d3b8f
Update cd.md to look better 2019-10-04 15:10:46 +03:00
Andrés N. Robalino
8faa0126eb
Merge pull request #784 from coolshaurya/to-dash-sth-docs
Added docs for most of the to-sth commands
2019-10-03 21:47:00 -05:00
Shaurya Shubham
6aec03708f Fix minor typo 2019-10-04 06:44:45 +05:30
Shaurya Shubham
2f7b1e4282 Added improvements suggested by @andrasio
Added `open file.sth | to-sth` type examples
Also did a format conversion example with `open jonathon.xml | to-json` in to-json.md
2019-10-04 06:40:16 +05:30
Andrés N. Robalino
7492131142
Merge pull request #770 from rnxpyke/master
add regex match plugin
2019-10-03 14:20:41 -05:00
Andrés N. Robalino
3c6ee63e59
Merge pull request #777 from JonnyWalker81/fix-get-panic
Attempt at fixing `get` command panic.
2019-10-03 14:02:51 -05:00
Andrés N. Robalino
45ad18f654
Merge pull request #785 from Charles-Schleich/master
Created Docs for env command
2019-10-03 14:00:51 -05:00
Andrés N. Robalino
01829f04d5
Merge pull request #783 from notryanb/document-last
add documentation for the last command
2019-10-03 13:59:41 -05:00
Andrés N. Robalino
cc1c471877
Merge pull request #779 from pema99/lines-doc
Add documentation for lines
2019-10-03 13:58:30 -05:00
Andrés N. Robalino
de14f9fce8
Merge pull request #781 from coolshaurya/add-command-docs
Create docs for add command
2019-10-03 13:38:11 -05:00
Andrés N. Robalino
6c3ed1dbc2
Merge pull request #782 from coolshaurya/docs-edit-command
Create docs for edit command
2019-10-03 13:37:49 -05:00
Charles Schleich
cf0fa3141a Created Docs for env command 2019-10-03 20:13:22 +02:00
Shaurya Shubham
539e232f3c Added docs for most of the to-sth commands
Partial fix of issue #711
Docs for the following commands were added -
to-csv
to-json
to-toml
to-tsv
to-url
to-yaml

Docs for to-db , to-bson , to-sqlite have not been added as I don't recognize and understand those formats.
2019-10-03 19:07:48 +05:30
Ryan Blecher
9ed889ccbb fix grammar 2019-10-03 08:18:51 -04:00
Ryan Blecher
872e26b524 add documentation for the last command 2019-10-03 08:14:59 -04:00
Shaurya Shubham
5bfff0c39b
Create docs for edit command
Partial fix of issue #711
2019-10-03 16:54:28 +05:30
Shaurya Shubham
0505a9d6f7
Create docs for add command
Partial fix of issue #711
2019-10-03 16:27:04 +05:30
rnxypke
9181a046ec use correct argument for error message 2019-10-03 08:21:24 +02:00
pema99
1b0eaac470 Add documentation for lines 2019-10-03 06:09:01 +02: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 Turner
04854d5d99
Merge pull request #776 from gilesv/where-command
Create where.md
2019-10-03 15:38:59 +13:00
Jonathan Turner
124a814f4d
Merge pull request #775 from JonnyWalker81/vi-textview-scroll
Added Vi support for scrolling in the textview command.
2019-10-03 15:19:11 +13:00
gilesv
2e1670fcb8 Add documentation for where command 2019-10-02 22:49:05 -03:00