mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #462 from adrian17/lambda_parsing
Change lambda parsing to be closer to Python official grammar. Fixes #427
This commit is contained in:
@@ -663,7 +663,7 @@ Test: ast::Expression = {
|
||||
};
|
||||
|
||||
LambdaDef: ast::Expression = {
|
||||
"lambda" <p:TypedArgsList?> ":" <b:Expression> =>
|
||||
"lambda" <p:TypedArgsList?> ":" <b:Test> =>
|
||||
ast::Expression::Lambda {
|
||||
args: p.unwrap_or(Default::default()),
|
||||
body:Box::new(b)
|
||||
|
||||
@@ -5,4 +5,10 @@ assert b == 6
|
||||
c = 2 + 4 if a > 5 else 'boe'
|
||||
assert c == 'boe'
|
||||
|
||||
d = lambda x, y: x > y
|
||||
assert d(5, 4)
|
||||
|
||||
e = lambda x: 1 if x else 0
|
||||
assert e(True) == 1
|
||||
assert e(False) == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user