Skip to content

Commit

Permalink
Treat match and case as soft keywords in lambda assignments (RustPyth…
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Mar 4, 2023
1 parent 4e19be7 commit 1871a16
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ match match:
case 1: pass
case 2:
pass
match = lambda query: query == event
print(match(12))
"#,
"<test>",
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion compiler/parser/src/soft_keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ where
let mut nesting = 0;
let mut first = true;
let mut seen_colon = false;
let mut seen_lambda = false;
while let Some(Ok((_, tok, _))) = self.underlying.peek() {
match tok {
Tok::Newline => break,
Tok::Lambda if nesting == 0 => seen_lambda = true,
Tok::Colon if nesting == 0 => {
if !first {
if seen_lambda {
seen_lambda = false;
} else if !first {
seen_colon = true;
}
}
Expand Down

0 comments on commit 1871a16

Please sign in to comment.