module documentation

Parser for Nebius field mask strings.

This module tokenizes and parses the compact mask syntax into a nebius.base.fieldmask.Mask tree. It supports dotted paths, comma separation, nested sub-masks using parentheses, and the wildcard *.

Grammar overview

  • Paths are dot-separated (spec.max_size_bytes).
  • Multiple paths are comma-separated.
  • Parentheses group a sub-mask (spec.(a,b)).
  • * denotes a wildcard branch at the current level.

Examples

Parse a simple mask:

from nebius.base.fieldmask_parser import parse

mask = parse("spec.max_size_bytes,labels")
assert mask.marshal() == "labels,spec.max_size_bytes"

Parse a nested mask:

mask = parse("spec.(limits,max_size_bytes)")
assert mask.marshal() == "spec.(limits,max_size_bytes)"
Class Level Parser helper tracking mask branches within a parenthesized level.
Class Lexer Tokenizer for the field mask grammar.
Class State Parser state machine states.
Class Token Single token with type, string value, and source position.
Class TokenType Token kinds produced by Lexer.
Exception ContextedParseError Parse error that includes source context.
Exception ParseError Raised when parsing fails.
Function parse Parse a mask string into a Mask tree.
Variable context_back Number of characters to show before the error position.
Variable error_mark Combining enclosing square to mark error position in context.
Variable max_context Maximum length of context to show in error messages.
Variable simple_string_token Regex for full simple (unquoted) token strings.
Variable simple_string_token_set Regex for simple (unquoted) token strings.
Variable simple_string_token_start Regex for the start of simple (unquoted) token strings.
Variable space_chars Whitespace characters recognized by the lexer.
Variable space_set Set of whitespace characters recognized by the lexer.
Function _context_around Build a human-friendly context string around a parse error.
Function _possible_ellipsis Return a truncated string with an ellipsis when needed.
def parse(source: str) -> Mask: (source)

Parse a mask string into a Mask tree.

Parameters
source:strMask string to parse.
Returns
MaskParsed Mask. Empty or whitespace-only strings yield an empty mask.
Raises
ParseErrorIf the input is malformed.
context_back: int = (source)

Number of characters to show before the error position.

error_mark: str = (source)

Combining enclosing square to mark error position in context.

max_context: int = (source)

Maximum length of context to show in error messages.

simple_string_token = (source)

Regex for full simple (unquoted) token strings.

simple_string_token_set: str = (source)

Regex for simple (unquoted) token strings.

simple_string_token_start = (source)

Regex for the start of simple (unquoted) token strings.

space_chars: str = (source)

Whitespace characters recognized by the lexer.

space_set = (source)

Set of whitespace characters recognized by the lexer.

def _context_around(s: str, pos: int) -> str: (source)

Build a human-friendly context string around a parse error.

Parameters
s:strSource string.
pos:intError position within s.
Returns
strContext string with an error mark.
def _possible_ellipsis(s: str, max_context: int) -> str: (source)

Return a truncated string with an ellipsis when needed.

Parameters
s:strSource string.
max_context:intMaximum length to return.
Returns
strPossibly truncated string.