# token_nav

URL: /patitas/api/parsing/token_nav/
Section: parsing
Description: Token navigation utilities for Patitas parser.

Provides mixin for token stream navigation and basic parsing operations.

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/parsing/token_nav/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Ftoken_nav%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Ftoken_nav%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Ftoken_nav%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Fparsing%2Ftoken_nav%2Findex.txt)

Module

#
`parsing.token_nav`

Token navigation utilities for Patitas parser.

Provides mixin for token stream navigation and basic parsing operations.

1Class

## Classes

`TokenNavigationMixin`

12

▼

Mixin providing token stream navigation methods.

Required Host Attributes:
- _tokens: list[Tok…

Mixin providing token stream navigation methods.

Required Host Attributes:

- _tokens: list[Token]

- _tokens_len: int (cached len(_tokens) for hot loops)

- _pos: int

- _current: Token | None

- _source: str

- _line_starts: list[int] | None (lazy line index for O(log n) boundary lookup)

#### Attributes

Name
Type
Description

`_tokens`

`list[Token (/patitas/api/tokens/#Token)]`

—

`_tokens_len`

`int`

—

`_pos`

`int`

—

`_current`

`Token (/patitas/api/tokens/#Token) | None`

—

`_source`

`str`

—

`_line_starts`

`list[int] | None`

—

#### Methods

Internal Methods
6

▼

`_at_end`

0

`bool`

▼

Check if at end of token stream.

`def _at_end(self) -> bool`

##### Returns

`bool`

`_advance`

0

`Token (/patitas/api/tokens/#Token) | None`

▼

Advance to next token and return it.

`def _advance(self) -> Token | None`

##### Returns

`Token (/patitas/api/tokens/#Token) | None`

`_peek`

1

`Token (/patitas/api/tokens/#Token) | None`

▼

Peek at token at offset from current position.

`def _peek(self, offset: int = 1) -> Token | None`

##### Parameters

Name
Type
Description

`offset`
`—`

Default:`1`

##### Returns

`Token (/patitas/api/tokens/#Token) | None`

`_line_start_for_offset`

1

`int`

▼

Get start offset of line containing offset. O(log n) with lazy line index.

`def _line_start_for_offset(self, offset: int) -> int`

##### Parameters

Name
Type
Description

`offset`
`—`

##### Returns

`int`

`_get_line_at`

1

`str`

▼

Get the full line content containing the given source offset.

`def _get_line_at(self, offset: int) -> str`

##### Parameters

Name
Type
Description

`offset`
`—`

##### Returns

`str`

`_strip_columns`

2

`str`

▼

Strip up to 'count' columns of whitespace/tabs from start of text.

`def _strip_columns(self, text: str, count: int) -> str`

##### Parameters

Name
Type
Description

`text`
`—`

`count`
`—`

##### Returns

`str`
