Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/emmylua_parser/locales/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ expected 'end' to close while statement:
en: expected 'end' to close while statement
zh_CN: 期望 'end' 来关闭while语句
zh_HK: 期望 'end' 來關閉while語句
expected end of block after return:
en: expected end of block after return
Comment on lines +258 to +259

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To maintain complete localization support for Chinese users (which is a major user base for EmmyLua), let's add the zh_CN and zh_HK translations for the new error message.

expected end of block after return:
  en: expected end of block after return
  zh_CN: 期望在 'return' 后结束块
  zh_HK: 期望在 'return' 後結束塊

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me realize I probably want to change it to expected end of block after return statement
Because 'return' feels misleading as if it's after the return keyword, when an expression or multiple can and will be there.

I need to go to bed, so I'll do that after someone chimes in with feedback on these translations.

expected 'function', variable name, or attribute after 'local':
en: expected 'function', variable name, or attribute after 'local'
zh_CN: 期望在 'local' 后有 'function'、变量名或属性
Expand Down
33 changes: 33 additions & 0 deletions crates/emmylua_parser/src/grammar/doc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3724,4 +3724,37 @@ Syntax(Chunk)@0..47
assert!(errors[0].range.is_empty());
assert_eq!(u32::from(errors[0].range.start()) as usize, code.len());
}

#[test]
fn test_statement_after_return() {
let code = "return 1, 2 x = 1";
let tree = LuaParser::parse(code, ParserConfig::default());
let errors = tree.get_errors();

assert_eq!(errors.len(), 1);
assert_eq!(errors[0].kind, LuaParseErrorKind::SyntaxError);
assert_eq!(errors[0].message, "expected end of block after return");
assert_eq!(u32::from(errors[0].range.start()) as usize, 12);
}

#[test]
fn test_statement_after_blank_return() {
let code = "return; x = 1";
let tree = LuaParser::parse(code, ParserConfig::default());
let errors = tree.get_errors();

assert_eq!(errors.len(), 1);
assert_eq!(errors[0].kind, LuaParseErrorKind::SyntaxError);
assert_eq!(errors[0].message, "expected end of block after return");
assert_eq!(u32::from(errors[0].range.start()) as usize, 8);
}

#[test]
fn test_do_return_end() {
let code = "do return end";
let tree = LuaParser::parse(code, ParserConfig::default());
let errors = tree.get_errors();

assert!(errors.is_empty());
}
Comment thread
PennyJim marked this conversation as resolved.
}
8 changes: 8 additions & 0 deletions crates/emmylua_parser/src/grammar/lua/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,14 @@ fn parse_return(p: &mut LuaParser) -> ParseResult {
}

if_token_bump(p, LuaTokenKind::TkSemicolon);

if !block_follow(p) {
p.push_error(LuaParseError::syntax_error_from(
&t!("expected end of block after return"),
p.current_token_range(),
));
}

Ok(m.complete(p))
}

Expand Down
Loading