Skip to content

Commit 2f22a7d

Browse files
committed
Doctests for syntax_tools
1 parent 31491c2 commit 2f22a7d

3 files changed

Lines changed: 1007 additions & 2 deletions

File tree

lib/syntax_tools/src/erl_comment_scan.erl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ column of the comment. `Line` and `Column` are always positive integers, and
7070
Evaluation exits with reason `{read, Reason}` if a read error occurred, where
7171
`Reason` is an atom corresponding to a Posix error code; see the module
7272
[`//kernel/file`](`m:file`) for details.
73+
74+
## Examples
75+
76+
```erlang
77+
1> File = "./erl_comment_scan_doctest.erl".
78+
2> file:write_file(File, "%% module note\nf() -> ok. % trailing\n").
79+
3> Comments = erl_comment_scan:file(File).
80+
[{1,1,0,["% module note"]},{2,12,1,[" trailing"]}]
81+
4> file:delete(File).
82+
```
7383
""".
7484
-spec file(file:filename()) -> [comment()].
7585

@@ -121,6 +131,13 @@ Except for reading directly from a string, the behavior is the same
121131
as for `file/1`.
122132

123133
_See also: _`file/1`.
134+
135+
## Examples
136+
137+
```erlang
138+
1> erl_comment_scan:string("%% module note\nf() -> ok. % trailing\n").
139+
[{1,1,0,["% module note"]},{2,12,1,[" trailing"]}]
140+
```
124141
""".
125142
-spec string(string()) -> [comment()].
126143

@@ -138,6 +155,13 @@ all characters following (but not including) the first
138155
comment-introducing `%` character on the line, up to (but not
139156
including) the line-terminating newline. For details on `Line`,
140157
`Column` and `Indent`, see `file/1`.
158+
159+
## Examples
160+
161+
```erlang
162+
1> erl_comment_scan:scan_lines("A = \"not % a comment\". % real\n% next\n").
163+
[{2,1,0," next"},{1,24,1," real"}]
164+
```
141165
""".
142166
-spec scan_lines(string()) -> [commentLine()].
143167

@@ -248,6 +272,13 @@ where for each entry, `Text` is a list of consecutive comment lines in
248272
order of _increasing_ line-numbers (that is, top-down).
249273

250274
_See also: _`scan_lines/1`.
275+
276+
## Examples
277+
278+
```erlang
279+
1> erl_comment_scan:join_lines([{2,1,0," second"},{1,1,0," first"}]).
280+
[{1,1,0,[" first"," second"]}]
281+
```
251282
""".
252283
-spec join_lines([commentLine()]) -> [comment()].
253284

0 commit comments

Comments
 (0)