nushell/src/lib.rs

38 lines
1007 B
Rust
Raw Normal View History

2019-08-02 21:15:07 +02:00
#![feature(generators)]
#![feature(proc_macro_hygiene)]
#[macro_use]
mod prelude;
2019-06-27 06:56:48 +02:00
mod cli;
mod commands;
mod context;
mod env;
mod errors;
mod evaluate;
mod format;
mod git;
mod object;
mod parser;
2019-07-02 09:56:20 +02:00
mod plugin;
2019-06-27 06:56:48 +02:00
mod shell;
mod stream;
2019-07-24 00:22:11 +02:00
mod traits;
2019-07-24 06:10:48 +02:00
mod utils;
2019-06-27 06:56:48 +02:00
pub use crate::commands::command::{CallInfo, ReturnSuccess, ReturnValue};
2019-07-24 19:14:30 +02:00
pub use crate::context::{SourceMap, SpanSource};
2019-07-04 07:11:56 +02:00
pub use crate::env::host::BasicHost;
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:21:03 +02:00
pub use crate::parser::hir::SyntaxType;
2019-09-02 08:11:05 +02:00
pub use crate::parser::parse::token_tree_builder::TokenTreeBuilder;
2019-07-02 09:56:20 +02:00
pub use crate::plugin::{serve_plugin, Plugin};
pub use crate::utils::{AbsoluteFile, AbsolutePath, RelativePath};
2019-06-27 06:56:48 +02:00
pub use cli::cli;
pub use errors::{CoerceInto, ShellError};
pub use num_traits::cast::ToPrimitive;
2019-06-27 06:56:48 +02:00
pub use object::base::{Primitive, Value};
2019-08-01 03:58:42 +02:00
pub use object::dict::{Dictionary, TaggedDictBuilder};
pub use object::meta::{Span, Tag, Tagged, TaggedItem};
2019-06-27 06:56:48 +02:00
pub use parser::parse::text::Text;
2019-08-02 21:15:07 +02:00
pub use parser::registry::{EvaluatedArgs, NamedType, PositionalType, Signature};