Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PEP 3134, Exception Chaining #120

Merged
merged 1 commit into from
Jan 31, 2019
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
2 changes: 1 addition & 1 deletion baron/formatting_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class UnExpectedSpaceToken(BaronError):
"FOR",
"COLON",
"BACKQUOTE",
"FROM",
)

STRING = (
Expand All @@ -77,7 +78,6 @@ class UnExpectedSpaceToken(BaronError):
) + STRING

GROUP_SPACE_AFTER = BOTH + (
"FROM",
"TILDE",
"RETURN",
"YIELD",
Expand Down
39 changes: 35 additions & 4 deletions baron/grammator_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def raise_stmt_empty(pack):
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": []
"fifth_formatting": [],
"sixth_formatting": [],
"seventh_formatting": [],
"from": None,
}


Expand All @@ -115,7 +118,29 @@ def raise_stmt(pack):
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": []
"fifth_formatting": [],
"sixth_formatting": [],
"seventh_formatting": [],
"from": None,
}


@pg.production("raise_stmt : RAISE test FROM test")
def raise_stmt_from(pack):
(raise_, test, from_, test2) = pack
return {
"type": "raise",
"value": test,
"instance": None,
"traceback": None,
"first_formatting": raise_.hidden_tokens_after,
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": [],
"sixth_formatting": from_.hidden_tokens_before,
"seventh_formatting": from_.hidden_tokens_after,
"from": test2,
}


Expand All @@ -131,7 +156,10 @@ def raise_stmt_instance(pack):
"second_formatting": comma.hidden_tokens_before,
"third_formatting": comma.hidden_tokens_after,
"fourth_formatting": [],
"fifth_formatting": []
"fifth_formatting": [],
"sixth_formatting": [],
"seventh_formatting": [],
"from": None,
}


Expand All @@ -147,7 +175,10 @@ def raise_stmt_instance_traceback(pack):
"second_formatting": comma.hidden_tokens_before,
"third_formatting": comma.hidden_tokens_after,
"fourth_formatting": comma2.hidden_tokens_before,
"fifth_formatting": comma2.hidden_tokens_after
"fifth_formatting": comma2.hidden_tokens_after,
"sixth_formatting": [],
"seventh_formatting": [],
"from": None,
}


Expand Down
1 change: 1 addition & 0 deletions baron/inner_formatting_grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class GroupingError(BaronError):
"OR",
"IF",
"ELSE",
"FROM"
"EQUAL",
"PLUS_EQUAL",
"MINUS_EQUAL",
Expand Down
4 changes: 4 additions & 0 deletions baron/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ def child_by_key(node, key):
("constant", ",", "traceback"),
("formatting", "fifth_formatting", "traceback"),
("key", "traceback", "traceback"),
("formatting", "sixth_formatting", "from"),
("constant", "from", "from"),
("formatting", "seventh_formatting","from"),
("key", "from", "from"),
],

"assert": [
Expand Down
60 changes: 53 additions & 7 deletions tests/test_grammator_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,17 @@ def test_raise_empty():
], [
{
"type": "raise",
"from": None,
"value": None,
"instance": None,
"traceback": None,
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": []
"fifth_formatting": [],
"sixth_formatting": [],
"seventh_formatting": [],
}
])

Expand All @@ -158,14 +161,42 @@ def test_raise():
], [
{
"type": "raise",
"from": None,
"value": {"type": "name", "value": 'a',},
"instance": None,
"traceback": None,
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": []
"fifth_formatting": [],
"sixth_formatting": [],
"seventh_formatting": [],
}
])


def test_raise_from():
"raise a from b"
parse_simple([
('RAISE', 'raise', [], [('SPACE', ' ')]),
('NAME', 'a'),
('FROM', 'from', [('SPACE', ' ')], [('SPACE', ' ')]),
('NAME', 'b'),
], [
{
"type": "raise",
"from": {'type': 'name', 'value': 'b'},
"value": {"type": "name", "value": 'a',},
"instance": None,
"traceback": None,
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [],
"fourth_formatting": [],
"fifth_formatting": [],
"sixth_formatting": [{'type': 'space', 'value': ' '}],
"seventh_formatting": [{'type': 'space', 'value': ' '}],
}
])

Expand All @@ -180,14 +211,17 @@ def test_raise_instance():
], [
{
"type": "raise",
"from": None,
"value": {"type": "name", "value": 'a',},
"instance": {"type": "name", "value": 'b'},
"traceback": None,
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [{"type": "space", "value": " "}],
"fourth_formatting": [],
"fifth_formatting": []
"fifth_formatting": [],
"sixth_formatting": [],
"seventh_formatting": [],
}
])
parse_simple([
Expand All @@ -198,14 +232,17 @@ def test_raise_instance():
], [
{
"type": "raise",
"from": None,
"value": {"type": "name", "value": 'a'},
"instance": {"type": "name", "value": 'b',},
"traceback": None,
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [{"type": "space", "value": " "}],
"fourth_formatting": [],
"fifth_formatting": []
"fifth_formatting": [],
"sixth_formatting": [],
"seventh_formatting": [],
}
])

Expand All @@ -222,14 +259,17 @@ def test_raise_instance_traceback():
], [
{
"type": "raise",
"from": None,
"value": {"type": "name", "value": 'a',},
"instance": {"type": "name", "value": 'b'},
"traceback": {"type": "name", "value": 'c'},
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [{"type": "space", "value": " "}],
"fourth_formatting": [],
"fifth_formatting": [{"type": "space", "value": " "}]
"fifth_formatting": [{"type": "space", "value": " "}],
"sixth_formatting": [],
"seventh_formatting": [],
}
])
parse_simple([
Expand All @@ -242,14 +282,17 @@ def test_raise_instance_traceback():
], [
{
"type": "raise",
"from": None,
"value": {"type": "name", "value": 'a'},
"instance": {"type": "name", "value": 'b',},
"traceback": {"type": "name", "value": 'c'},
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [{"type": "space", "value": " "}],
"fourth_formatting": [],
"fifth_formatting": [{"type": "space", "value": " "}]
"fifth_formatting": [{"type": "space", "value": " "}],
"sixth_formatting": [],
"seventh_formatting": [],
}
])
parse_simple([
Expand All @@ -262,14 +305,17 @@ def test_raise_instance_traceback():
], [
{
"type": "raise",
"from": None,
"value": {"type": "name", "value": 'a'},
"instance": {"type": "name", "value": 'b'},
"traceback": {"type": "name", "value": 'c',},
"first_formatting": [{"type": "space", "value": " "}],
"second_formatting": [],
"third_formatting": [{"type": "space", "value": " "}],
"fourth_formatting": [],
"fifth_formatting": [{"type": "space", "value": " "}]
"fifth_formatting": [{"type": "space", "value": " "}],
"sixth_formatting": [],
"seventh_formatting": [],
}
])

Expand Down