diff --git a/nac3parser/src/config_comment_helper.rs b/nac3parser/src/config_comment_helper.rs index 588f3e3..a0631c4 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 5ca7a56..3a7c6b8 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![]),