Skip to content
Merged
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
5 changes: 3 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ impl Parser {
Tok::Eq | Tok::Colon if depth == 0 => {
let mut shape = vec!["let".to_string(), name.clone()];
if parenthesized && params.is_empty() {
// `def greet():` takes no arguments, which Pyfun spells `()`.
params.push("()".to_string());
// `def greet():` takes no arguments: Pyfun gives it one it
// ignores (`let greet _ = …`), called as `greet ()`.
params.push("_".to_string());
}
shape.extend(params);
return Some(ParseError {
Expand Down
5 changes: 4 additions & 1 deletion tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ fn def_is_answered_with_the_let_spelling() {
"def area(w: int, h: int) -> int:\n w * h",
"write `let area w h = …`",
),
("def greet():\n print \"hi\"", "write `let greet () = …`"),
("def greet():\n print \"hi\"", "write `let greet _ = …`"),
("let f x =\n def g y = y + 1\n g x", "write `let g y = …`"),
] {
let err = parse(source).unwrap_err();
Expand All @@ -791,6 +791,9 @@ fn def_is_answered_with_the_let_spelling() {
err.message()
);
}
// Every suggested spelling parses.
assert!(parse("let area w h = w * h").is_ok());
assert!(parse("let greet _ =\n print \"hi\"").is_ok());
// `def` is still an ordinary identifier: a function the program calls `def`.
assert!(parse("let def x = x + 1\nprint (def 2)").is_ok());
}
Expand Down
Loading