Skip to content

Commit

Permalink
[WIP] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wycats committed Oct 22, 2019
1 parent 047736b commit a7a6b40
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
11 changes: 6 additions & 5 deletions src/parser/hir/syntax_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl FallibleColorSyntax for BareShape {
_context: &ExpandContext,
shapes: &mut Vec<Spanned<FlatShape>>,
) -> Result<(), ShellError> {
token_nodes.peek_any_token(|token| match token {
token_nodes.peek_any_token("word", |token| match token {
// If it's a bare token, color it
TokenNode::Token(Spanned {
item: RawToken::Bare,
Expand Down Expand Up @@ -687,7 +687,7 @@ impl FallibleColorSyntax for BareShape {
token_nodes: &'b mut TokensIterator<'a>,
_context: &ExpandContext,
) -> Result<(), ShellError> {
let span = token_nodes.peek_any_token(|token| match token {
let span = token_nodes.peek_any_token("word", |token| match token {
// If it's a bare token, color it
TokenNode::Token(Spanned {
item: RawToken::Bare,
Expand Down Expand Up @@ -794,7 +794,8 @@ impl FallibleColorSyntax for PipelineShape {
shapes: &mut Vec<Spanned<FlatShape>>,
) -> Result<(), ShellError> {
// Make sure we're looking at a pipeline
let Pipeline { parts, .. } = token_nodes.peek_any_token(|node| node.as_pipeline())?;
let Pipeline { parts, .. } =
token_nodes.peek_any_token("pipeline", |node| node.as_pipeline())?;

// Enumerate the pipeline parts
for part in parts {
Expand Down Expand Up @@ -831,7 +832,7 @@ impl FallibleColorSyntax for PipelineShape {
context: &ExpandContext,
) -> Result<(), ShellError> {
// Make sure we're looking at a pipeline
let pipeline = token_nodes.peek_any_token(|node| node.as_pipeline())?;
let pipeline = token_nodes.peek_any_token("pipeline", |node| node.as_pipeline())?;

let parts = &pipeline.parts[..];

Expand Down Expand Up @@ -1273,7 +1274,7 @@ fn parse_single_node<'a, 'b, T>(
expected: &'static str,
callback: impl FnOnce(RawToken, Span, SingleError) -> Result<T, ShellError>,
) -> Result<T, ShellError> {
token_nodes.peek_any_token(|node| match node {
token_nodes.peek_any_token(expected, |node| match node {
TokenNode::Token(token) => callback(
token.item,
token.span,
Expand Down
4 changes: 2 additions & 2 deletions src/parser/hir/tokens_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ impl<'content> TokensIterator<'content> {
pub fn child<'me, T>(
&'me mut self,
tokens: Spanned<&'me [TokenNode]>,
shapes: &mut Vec<Spanned<crate::parser::hir::syntax_shape::FlatShape>>,
block: impl FnOnce(&mut TokensIterator<'me>) -> T,
) -> T {
let mut tracer = Tracer::new();
Expand Down Expand Up @@ -526,10 +525,11 @@ impl<'content> TokensIterator<'content> {
// Peek the next token, including whitespace, but not EOF
pub fn peek_any_token<'me, T>(
&'me mut self,
expected: &'static str,
block: impl FnOnce(&'content TokenNode) -> Result<T, ShellError>,
) -> Result<T, ShellError> {
let peeked = start_next(self, false);
let peeked = peeked.not_eof("invariant");
let peeked = peeked.not_eof(expected);

match peeked {
Err(err) => return Err(err),
Expand Down
12 changes: 6 additions & 6 deletions src/parser/parse_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ pub fn parse_command_tail(
let mut positional = vec![];

for arg in &config.positional {
trace!("Processing positional {:?}", arg);
trace!(target: "nu::parse", "Processing positional {:?}", arg);

match arg {
PositionalType::Mandatory(..) => {
if tail.at_end() {
if tail.at_end_possible_ws() {
return Err(ShellError::argument_error(
config.name.clone(),
ArgumentError::MissingMandatoryPositional(arg.name().to_string()),
Expand All @@ -107,7 +107,7 @@ pub fn parse_command_tail(
}

PositionalType::Optional(..) => {
if tail.at_end() {
if tail.at_end_possible_ws() {
break;
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn parse_command_tail(

trace_remaining("after rest", tail.clone(), context.source());

trace!("Constructed positional={:?} named={:?}", positional, named);
trace!(target: "nu::parse", "Constructed positional={:?} named={:?}", positional, named);

let positional = if positional.len() == 0 {
None
Expand All @@ -154,7 +154,7 @@ pub fn parse_command_tail(
Some(named)
};

trace!("Normalized positional={:?} named={:?}", positional, named);
trace!(target: "nu::parse", "Normalized positional={:?} named={:?}", positional, named);

Ok(Some((positional, named)))
}
Expand Down Expand Up @@ -635,7 +635,7 @@ fn extract_optional(

pub fn trace_remaining(desc: &'static str, tail: hir::TokensIterator<'_>, source: &Text) {
trace!(
target: "nu::expand_args",
target: "nu::parse",
"{} = {:?}",
desc,
itertools::join(
Expand Down
6 changes: 3 additions & 3 deletions tests/commands_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,13 @@ fn it_arg_works_with_many_inputs_to_external_command() {
let (stdout, stderr) = nu_combined!(
cwd: dirs.test(), h::pipeline(
r#"
echo file1 file2
echo hello world
| split-row " "
| cat $it
| ^echo $it
"#
));

assert_eq!("text and more text", stdout);
assert_eq!("hello world", stdout);
assert!(!stderr.contains("No such file or directory"));
})
}
Expand Down

0 comments on commit a7a6b40

Please sign in to comment.