-
Notifications
You must be signed in to change notification settings - Fork 3k
Refactored erl_prettypr.erl #4570
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
Open
matyasmarkovics
wants to merge
17
commits into
erlang:master
Choose a base branch
from
matyasmarkovics:erl_prettypr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
98e580b
Refactored erl_prettypr
matyasmarkovics 1732a20
Fix function layout and macros in type-applications
matyasmarkovics a1d5395
fix some test-cases in CT-suite for syntax_tools
matyasmarkovics 4d81ce9
Skip eof_marker when splitting forms
matyasmarkovics de7dc6d
Fix arithmetic format in bit-syntax; Test record format; Add test_fil…
matyasmarkovics 2737f94
Clean-up copied epp_dodger code
matyasmarkovics 88a75df
Make use of empty-lines
matyasmarkovics 08c8916
Fix separator type-spec
matyasmarkovics 7f92e30
Fix fun. signitures mismatch (dialyzer)
matyasmarkovics 0575f02
type-specs for layout_hook
matyasmarkovics 9615514
Split sequence layout from tree layout to call hook on every item
matyasmarkovics 32ccce7
Fix ctxt.clause type; Fix clause and attribute format
matyasmarkovics 8c61dda
Layout clause directly instead of creating clause node, same for pare…
matyasmarkovics 5ff989f
Remove unmatched guard and unnecessary set_clause
matyasmarkovics 474d2d1
Add node-types to set_clause signiture; fix clause_layout spec
matyasmarkovics b935946
Drop none from items before rendering it
matyasmarkovics d2635de
Stick spec and function together, group similar forms, split them oth…
matyasmarkovics File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ | |
parse_form/3, quick_parse_form/2, quick_parse_form/3, | ||
format_error/1, tokens_to_string/1]). | ||
|
||
-export([scan_form/2, rewrite_form/1]). | ||
|
||
%% The following should be: 1) pseudo-uniquely identifiable, and 2) | ||
%% cause nice looking error messages when the parser has to give up. | ||
|
@@ -796,36 +797,69 @@ rewrite(Node) -> | |
_ -> | ||
Node | ||
end; | ||
application -> | ||
F = erl_syntax:application_operator(Node), | ||
case erl_syntax:type(F) of | ||
atom -> | ||
case erl_syntax:atom_value(F) of | ||
?macro_call -> | ||
[A | As] = erl_syntax:application_arguments(Node), | ||
M = erl_syntax:macro(A, rewrite_list(As)), | ||
erl_syntax:copy_pos(Node, M); | ||
_ -> | ||
rewrite_1(Node) | ||
end; | ||
_ -> | ||
rewrite_1(Node) | ||
end; | ||
_ -> | ||
rewrite_1(Node) | ||
application -> | ||
rewrite_application( | ||
Node, | ||
fun erl_syntax:application_operator/1, | ||
fun erl_syntax:application_arguments/1); | ||
type_application -> | ||
rewrite_application( | ||
Node, | ||
fun erl_syntax:type_application_name/1, | ||
fun erl_syntax:type_application_arguments/1); | ||
user_type_application -> | ||
rewrite_application( | ||
Node, | ||
fun erl_syntax:user_type_application_name/1, | ||
fun erl_syntax:user_type_application_arguments/1); | ||
attribute -> | ||
Name = erl_syntax:attribute_name(Node), | ||
case catch erl_syntax:concrete(Name) of | ||
spec -> | ||
[SpecTuple] = erl_syntax:attribute_arguments(Node), | ||
[FuncName, FuncTypes] = erl_syntax:tuple_elements(SpecTuple), | ||
Clauses = erl_syntax:concrete(FuncTypes), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the trick with |
||
erl_syntax:copy_pos( | ||
Node, | ||
erl_syntax:attribute( | ||
rewrite(Name), | ||
[erl_syntax:tuple([rewrite(FuncName), | ||
erl_syntax:abstract(rewrite_list(Clauses)) | ||
])] | ||
)); | ||
_ -> | ||
rewrite_subtrees(Node) | ||
end; | ||
Type when Type == nil; Type == string; Type == integer; | ||
Type == variable; Type == eof_marker -> | ||
Node; | ||
_ -> | ||
rewrite_subtrees(Node) | ||
end. | ||
|
||
rewrite_1(Node) -> | ||
case erl_syntax:subtrees(Node) of | ||
[] -> | ||
Node; | ||
Gs -> | ||
Node1 = erl_syntax:make_tree(erl_syntax:type(Node), | ||
[[rewrite(T) || T <- Ts] | ||
|| Ts <- Gs]), | ||
erl_syntax:copy_pos(Node, Node1) | ||
rewrite_application(Node, OpGetter, ArgGetter) -> | ||
F = OpGetter(Node), | ||
case erl_syntax:type(F) of | ||
atom -> | ||
case erl_syntax:atom_value(F) of | ||
?macro_call -> | ||
[A | As] = ArgGetter(Node), | ||
M = erl_syntax:macro(A, rewrite_list(As)), | ||
erl_syntax:copy_pos(Node, M); | ||
_ -> | ||
rewrite_subtrees(Node) | ||
end; | ||
_ -> | ||
rewrite_subtrees(Node) | ||
end. | ||
|
||
rewrite_subtrees(Node) -> | ||
erl_syntax_lib:map_subtrees( | ||
fun(ST) when is_list(ST) -> rewrite_list(ST); | ||
(ST) -> rewrite(ST) | ||
end, | ||
Node). | ||
|
||
%% attempting a rescue operation on a token sequence for a single form | ||
%% if it could not be parsed after the normal treatment | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be simplified a bit to both avoid an unnecessary
catch
and make it clear what kind of node are allowed as the attribute name, i.e. an atom node.