Skip to content

Commit a4fce3e

Browse files
committed
Update parsing API docs based on comments. See robotframework#3791.
1 parent a964d82 commit a4fce3e

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/robot/api/parsing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ class attributes.
5858
Data can be parsed to tokens by using
5959
:func:`~.lexer.lexer.get_tokens`,
6060
:func:`~.lexer.lexer.get_resource_tokens` or
61-
:func:`~.lexer.lexer.get_init_tokens` functions depending on does the data
61+
:func:`~.lexer.lexer.get_init_tokens` functions depending on whether the data
6262
represent a test case (or task) file, a resource file, or a suite
6363
initialization file. In practice the difference between these functions is
6464
what settings and sections are valid.
6565
6666
Typically the data is easier to inspect and modify by using the higher level
67-
model discussed in the next section, but in some cases the token stream can
68-
be enough. Tokens returned by the aforementioned functions are
67+
model discussed in the next section, but in some cases having just the tokens
68+
can be enough. Tokens returned by the aforementioned functions are
6969
:class:`~.lexer.tokens.Token` instances and they have the token type, value,
7070
and position easily available as their attributes. Tokens also have useful
7171
string representation used by the example below::

src/robot/parsing/lexer/tokens.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ class Token(object):
2626
and :attr:`end_col_offset` attributes, respectively. Tokens representing
2727
error also have their error message in :attr:`error` attribute.
2828
29-
If :attr:`value` is not given when :class:`Token` is initialized and
30-
:attr:`type` is ``IF``, ``ELSE_IF``, ``ELSE``, ``FOR``, ``END``, or
31-
``CONTINUATION`` the value is automatically set to the correct marker value.
32-
If :attr:`type` is ``EOL`` in this case, the value is set to ``\\n``.
29+
Token types are declared as class attributes such as :attr:`SETTING_HEADER`
30+
and :attr:`EOL`. Values of these constants have changed slightly in Robot
31+
Framework 4.0 and they may change again in the future. It is thus safer
32+
to use the constants, not their values, when types are needed. For example,
33+
use ``Token(Token.EOL)`` instead of ``Token('EOL')`` and
34+
``token.type == Token.EOL`` instead of ``token.type == 'EOL'``.
3335
34-
Token types are declared as class attributes.
36+
If :attr:`value` is not given when :class:`Token` is initialized and
37+
:attr:`type` is :attr:`IF`, :attr:`ELSE_IF`, :attr:`ELSE`, :attr:`FOR`,
38+
:attr:`END` or :attr:`CONTINUATION`, the value is automatically set
39+
to the correct marker value like ``'IF'`` or ``'ELSE IF'``. If :attr:`type`
40+
is :attr:`EOL` in this case, the value is set to ``'\\n'``.
3541
"""
3642

3743
SETTING_HEADER = 'SETTING HEADER'

0 commit comments

Comments
 (0)