From efc9edbc1423758d4f80658d313b293089cca646 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Sat, 6 Nov 2021 14:13:17 +0800 Subject: [PATCH] nac3parser: fix decorator and above comments --- nac3parser/src/config_comment_helper.rs | 8 ++++---- nac3parser/src/python.lalrpop | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nac3parser/src/config_comment_helper.rs b/nac3parser/src/config_comment_helper.rs index 588f3e38..a0631c48 100644 --- a/nac3parser/src/config_comment_helper.rs +++ b/nac3parser/src/config_comment_helper.rs @@ -11,13 +11,13 @@ pub fn make_config_comment( nac3com_above: Vec<(Ident, Tok)>, nac3com_end: Option ) -> Result, ParseError> { - if com_loc.column() != stmt_loc.column() { + if com_loc.column() != stmt_loc.column() && !nac3com_above.is_empty() { return Err(ParseError::User { error: LexicalError { location: com_loc, error: LexicalErrorType::OtherError( format!( - "config comment at top must have the same indentation with what it applies, comment at {}, statement at {}", + "config comment at top must have the same indentation with what it applies(comment at {}, statement at {})", com_loc, stmt_loc, ) @@ -35,13 +35,13 @@ pub fn make_config_comment( } pub fn handle_small_stmt(stmts: &mut [Stmt], nac3com_above: Vec<(Ident, Tok)>, nac3com_end: Option, com_above_loc: Location) -> Result<(), ParseError> { - if com_above_loc.column() != stmts[0].location.column() { + if com_above_loc.column() != stmts[0].location.column() && !nac3com_above.is_empty() { return Err(ParseError::User { error: LexicalError { location: com_above_loc, error: LexicalErrorType::OtherError( format!( - "config comment at top must have the same indentation with what it applies, comment at {}, statement at {}", + "config comment at top must have the same indentation with what it applies(comment at {}, statement at {})", com_above_loc, stmts[0].location, ) diff --git a/nac3parser/src/python.lalrpop b/nac3parser/src/python.lalrpop index 5ca7a56b..3a7c6b81 100644 --- a/nac3parser/src/python.lalrpop +++ b/nac3parser/src/python.lalrpop @@ -508,7 +508,7 @@ WithItem: ast::Withitem = { }; FuncDef: ast::Stmt = { - "def" " Test)?> ":" =>? { + "def" " Test)?> ":" =>? { let args = Box::new(args); let returns = r.map(|x| Box::new(x.1)); let type_comment = None; @@ -671,7 +671,7 @@ KwargParameter: Option> = { }; ClassDef: ast::Stmt = { - "class" ":" =>? { + "class" ":" =>? { let (bases, keywords) = match a { Some((_, arg, _)) => (arg.args, arg.keywords), None => (vec![], vec![]),