Skip to content

[syntax_tools + doctest] Add some (a lot of) examples to exported functions - #11393

Open
kvakvs wants to merge 1 commit into
erlang:masterfrom
kvakvs:doctest/syntax_tools
Open

[syntax_tools + doctest] Add some (a lot of) examples to exported functions#11393
kvakvs wants to merge 1 commit into
erlang:masterfrom
kvakvs:doctest/syntax_tools

Conversation

@kvakvs

@kvakvs kvakvs commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Changes

  • Exported functions in erl_syntax.erl have been visited and some sort of doctest example was added where reasonable.
  • Doctest invocation was added to syntax_tools_SUITE

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

  2 files   13 suites   3m 16s ⏱️
122 tests 118 ✅ 4 💤 0 ❌
138 runs  134 ✅ 4 💤 0 ❌

Results for commit 113ae34.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@kvakvs
kvakvs force-pushed the doctest/syntax_tools branch from 3adf605 to 5dcc119 Compare July 26, 2026 14:21
@lucioleKi lucioleKi added the team:VM Assigned to OTP team VM label Jul 27, 2026
@jhogberg jhogberg self-assigned this Aug 3, 2026
@jhogberg

jhogberg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR!

I don't think we want this as-is, the vast majority of the added examples don't add anything of value. Can you try to condense them down to the ones you thought were useful? The size makes the PR difficult to review.

@kvakvs

kvakvs commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the PR!

I don't think we want this as-is, the vast majority of the added examples don't add anything of value. Can you try to condense them down to the ones you thought were useful? The size makes the PR difficult to review.

In my opinion, those examples, which build language constructs from pieces and demonstrate how they fit together, bring value, and that's at least 3/4 of the examples. Intended for people who didn't work with erl_syntax before to understand how it works, to try and construct something, inviting them to build language tools.

The remaining examples, e.g. setters and getters and debug info, line info, annotations, might have small value, and can be removed.

@jhogberg

jhogberg commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

In my opinion, those examples, which build language constructs from pieces and demonstrate how they fit together, bring value, and that's at least 3/4 of the examples.

Please pick one as an example.

@kvakvs

kvakvs commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

For example, constructing types (record type)

RTF = erl_syntax:record_type_field(erl_syntax:atom(name), erl_syntax:atom(string)).
RT = erl_syntax:record_type(erl_syntax:atom(person), [RTF]).

or constructing comprehensions with binaries and binary fields

V = erl_syntax:variable("Byte").
BG = erl_syntax:binary_generator(V, erl_syntax:binary([erl_syntax:binary_field(erl_syntax:integer(65))])).
BC = erl_syntax:binary_comp(erl_syntax:binary_field(V), [BG]).

@jhogberg

jhogberg commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Yes, so keep those, and skip the ones that are trivial (e.g. erl_syntax:float/1, erl_syntax:type_application_name/1, or the likes). Showing the result of erl_syntax:type(...) also doesn't bring much value as it's a tautology.

@kvakvs
kvakvs force-pushed the doctest/syntax_tools branch 5 times, most recently from 2f22a7d to c0bdef5 Compare August 9, 2026 05:46
@kvakvs
kvakvs force-pushed the doctest/syntax_tools branch from c0bdef5 to 113ae34 Compare August 9, 2026 05:47
@@ -3435,6 +3598,7 @@ arity_qualifier(Body, Arity) ->
Returns the body subtree of an `arity_qualifier` node.

_See also: _`arity_qualifier/2`.
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```

"B <- [2]"
5> ZG = erl_syntax:zip_generator([G1, G2]).
6> erl_prettypr:format(ZG).
"A <- [1]&& B <- [2]"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erl_prettypr should really be fixed to insert a space before the &&...

@@ -8165,6 +8917,7 @@ it does not necessarily have the same data representation as `Node`.

_See also: _`copy_attrs/2`, `is_leaf/1`, `subtrees/1`, `type/1`,
`update_tree/2`.
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```

Comment on lines +9251 to +9252
1> T = erl_syntax:tree(example, [erl_syntax:atom(ok)]).
2> D = erl_syntax:data(T).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1> T = erl_syntax:tree(example, [erl_syntax:atom(ok)]).
2> D = erl_syntax:data(T).
1> Data = [erl_syntax:atom(ok)].
2> Tree = erl_syntax:tree(example, Data).
3> Data =:= erl_syntax:data(Tree).
true

maybe something like this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants