From bed5ba52d39141781d37e2d905a744006b1a43c6 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Sun, 23 Jun 2019 15:32:26 -0400 Subject: [PATCH] Fixed trailing issues --- src/parser/hir/baseline_parse_tokens.rs | 1 - src/parser/parse2/parser.rs | 24 +++++++++++------------- src/parser/parse2/token_tree.rs | 2 -- src/shell/helper.rs | 1 - 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/parser/hir/baseline_parse_tokens.rs b/src/parser/hir/baseline_parse_tokens.rs index 45826f2076..81222f66f9 100644 --- a/src/parser/hir/baseline_parse_tokens.rs +++ b/src/parser/hir/baseline_parse_tokens.rs @@ -163,7 +163,6 @@ pub fn baseline_parse_semantic_token( TokenNode::Whitespace(_span) => unreachable!(), TokenNode::Error(error) => Err(*error.item.clone()), TokenNode::Path(_path) => unimplemented!(), - TokenNode::EOF(_span) => unimplemented!(), } } diff --git a/src/parser/parse2/parser.rs b/src/parser/parse2/parser.rs index 5260a6fccc..2a069bd552 100644 --- a/src/parser/parse2/parser.rs +++ b/src/parser/parse2/parser.rs @@ -429,17 +429,6 @@ pub fn node(input: NomSpan) -> IResult { ) } -pub fn eof(input: NomSpan) -> IResult { - if input.input_len() == 0 { - Ok((input, TokenNode::EOF(Span::from(input)))) - } else { - Err(Err::Error(error_position!( - input, - nom::error::ErrorKind::Eof - ))) - } -} - pub fn pipeline(input: NomSpan) -> IResult { trace_step(input, "pipeline", |input| { let start = input.offset; @@ -450,13 +439,22 @@ pub fn pipeline(input: NomSpan) -> IResult { many0(tuple((opt(space1), raw_call, opt(space1), opt(tag("|"))))), )?; - let (input, tail) = tuple((opt(space1), eof))(input)?; + let (input, tail) = opt(space1)(input)?; + let (input, newline) = opt(multispace1)(input)?; + + if input.input_len() != 0 { + return Err(Err::Error(error_position!( + input, + nom::error::ErrorKind::Eof + ))); + } + let end = input.offset; Ok(( input, TokenTreeBuilder::spanned_pipeline( - (make_call_list(head, items), tail.0.map(Span::from)), + (make_call_list(head, items), tail.map(Span::from)), (start, end), ), )) diff --git a/src/parser/parse2/token_tree.rs b/src/parser/parse2/token_tree.rs index c0a7778f42..e11295bba4 100644 --- a/src/parser/parse2/token_tree.rs +++ b/src/parser/parse2/token_tree.rs @@ -18,7 +18,6 @@ pub enum TokenNode { #[allow(unused)] Error(Spanned>), Path(Spanned), - EOF(Span), } impl TokenNode { @@ -34,7 +33,6 @@ impl TokenNode { TokenNode::Whitespace(s) => *s, TokenNode::Error(s) => s.span, TokenNode::Path(s) => s.span, - TokenNode::EOF(s) => *s, } } diff --git a/src/shell/helper.rs b/src/shell/helper.rs index 78444cf37d..114fd3a1f5 100644 --- a/src/shell/helper.rs +++ b/src/shell/helper.rs @@ -130,7 +130,6 @@ fn paint_token_node(token_node: &TokenNode, line: &str) -> String { item: RawToken::Bare, .. }) => Color::Green.normal().paint(token_node.span().slice(line)), - TokenNode::EOF(_) => return format!(""), }; styled.to_string()