Skip to content

Commit cc7bbfd

Browse files
authored
Use position instead of line to describe arguments for traverse functions (#148)
* Use `position` instead of `line` to describe arguments for traverse functions * Fix english in comment
1 parent 7b99f6e commit cc7bbfd

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/nimble_parsec.ex

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,13 @@ defmodule NimbleParsec do
10191019
10201020
The function given in `call` will receive 5 additional arguments.
10211021
The rest of the parsed binary, the parser results to be post_traversed,
1022-
the parser context, the current line and the current offset will
1022+
the parser context, the current position and the current offset will
10231023
be prepended to the given `args`. The `args` will be injected at
10241024
the compile site and therefore must be escapable via `Macro.escape/1`.
1025+
The position is represented as a tuple `{line, column}`
1026+
(with column relative to the line in question).
10251027
1026-
The line and offset will represent the location after the combinators.
1028+
The position and offset will represent the location after the combinators.
10271029
To retrieve the position before the combinators, use `pre_traverse/3`.
10281030
10291031
The `call` must return a tuple `{rest, acc, context}` with list of
@@ -1054,7 +1056,7 @@ defmodule NimbleParsec do
10541056
|> ascii_char([?a..?z])
10551057
|> post_traverse({:join_and_wrap, ["-"]})
10561058
1057-
defp join_and_wrap(rest, args, context, _line, _offset, joiner) do
1059+
defp join_and_wrap(rest, args, context, _position, _offset, joiner) do
10581060
{rest, args |> Enum.join(joiner) |> List.wrap(), context}
10591061
end
10601062
end
@@ -1072,12 +1074,12 @@ defmodule NimbleParsec do
10721074
end
10731075

10741076
@doc """
1075-
The same as `post_traverse/3` but receives the line and offset
1077+
The same as `post_traverse/3` but receives the position and offset
10761078
from before the wrapped combinators.
10771079
10781080
`post_traverse/3` should be preferred as it keeps less stack
10791081
information. Use `pre_traverse/3` only if you have to access
1080-
the line and offset from before the given combinators.
1082+
the position and offset from before the given combinators.
10811083
"""
10821084
@spec pre_traverse(t, call) :: t
10831085
@spec pre_traverse(t, t, call) :: t
@@ -1197,11 +1199,11 @@ defmodule NimbleParsec do
11971199
11981200
`call` is a `{module, function, args}` and it will receive 5
11991201
additional arguments. The AST representation of the rest of the
1200-
parsed binary, the parser results, context, line and offset will
1202+
parsed binary, the parser results, context, position and offset will
12011203
be prepended to `args`. `call` is invoked at compile time and is
12021204
useful in combinators that avoid injecting runtime dependencies.
12031205
1204-
The line and offset will represent the location after the combinators.
1206+
The position and offset will represent the location after the combinators.
12051207
To retrieve the position before the combinators, use `quoted_pre_traverse/3`.
12061208
12071209
This function must be used only when you want to emit code that
@@ -1217,12 +1219,12 @@ defmodule NimbleParsec do
12171219
end
12181220

12191221
@doc """
1220-
The same as `quoted_post_traverse/3` but receives the line and offset
1222+
The same as `quoted_post_traverse/3` but receives the position and offset
12211223
from before the wrapped combinators.
12221224
12231225
`quoted_post_traverse/3` should be preferred as it keeps less stack
12241226
information. Use `quoted_pre_traverse/3` only if you have to access
1225-
the line and offset from before the given combinators.
1227+
the position and offset from before the given combinators.
12261228
"""
12271229
@spec quoted_pre_traverse(t, mfargs) :: t
12281230
@spec quoted_pre_traverse(t, t, mfargs) :: t
@@ -1566,9 +1568,11 @@ defmodule NimbleParsec do
15661568
15671569
The function given in `while` will receive 4 additional arguments.
15681570
The `rest` of the binary to be parsed, the parser context, the
1569-
current line and the current offset will be prepended to the
1571+
current position and the current offset will be prepended to the
15701572
given `args`. The `args` will be injected at the compile site
15711573
and therefore must be escapable via `Macro.escape/1`.
1574+
The position is represented as a tuple `{line, column}`
1575+
(with column relative to the line in question).
15721576
15731577
## Examples
15741578
@@ -1639,8 +1643,8 @@ defmodule NimbleParsec do
16391643
16401644
`while` is a `{module, function, args}` and it will receive 4
16411645
additional arguments. The AST representations of the binary to be
1642-
parsed, context, line and offset will be prepended to `args`. `while`
1643-
is invoked at compile time and is useful in combinators that avoid
1646+
parsed, context, position (`{line, column}`) and offset will be prepended to `args`.
1647+
`while` is invoked at compile time and is useful in combinators that avoid
16441648
injecting runtime dependencies.
16451649
"""
16461650
@spec quoted_repeat_while(t, mfargs) :: t

0 commit comments

Comments
 (0)