Skip to content

Parsers

This module offers parsers that can be used in your code to speed up development.

The StringParser offers useful methods to navigate and parse strings using tokens.

botcity.utils.parser.string.StringParser

current_position: int property readonly

The current parser cursor position

__init__(self, content) special

String Parser

Parameters:

Name Type Description Default
content str

The string content to be parsed.

required

back_to_tag_end(self, tag)

Move the current cursor position to the end of the search tag.

Parameters:

Name Type Description Default
tag str

The tag to search for.

required

Returns:

Type Description
bool

Whether or not it was possible to move the cursor.

back_to_tag_start(self, tag)

Move the current cursor position to the beginning of the search tag.

Parameters:

Name Type Description Default
tag str

The tag to search for.

required

Returns:

Type Description
bool

Whether or not it was possible to move the cursor.

backward_contains(self, tag)

Whether or not the content contains the tag starting from the beginning until the current cursor position.

Parameters:

Name Type Description Default
tag str

The tag to search for.

required

Returns:

Type Description
bool

True in case the tag is found, False otherwise.

get_next_chars(self, chars)

Reads and return the content starting from the current position with the addition of chars more characters.

Parameters:

Name Type Description Default
chars int

Number of characters to read.

required

Returns:

Type Description
str

The sliced content.

goto_next_line(self, linesep=None)

Move the cursor to the next line found starting from the current position.

Parameters:

Name Type Description Default
linesep str

The line separator. If not specified the system line separator is used.

None

Returns:

Type Description
StringParser

this object.

goto_tag_end(self, tag)

Move the parser cursor to the end of the tag.

Parameters:

Name Type Description Default
tag str

The tag to search for.

required

Returns:

Type Description
StringParser

this object.

goto_tag_start(self, tag)

Move the parser cursor to the beginning of the tag.

Parameters:

Name Type Description Default
tag str

The tag to search for.

required

Returns:

Type Description
StringParser

this object.

next_contains(self, tag)

Whether or not the content contains the tag starting from the current cursor position.

Parameters:

Name Type Description Default
tag str

The tag to search for.

required

Returns:

Type Description
bool

True in case the tag is found, False otherwise.

read(self)

Reads the remaining content starting at the current cursor positon.

Returns:

Type Description
str

the remaining content.

read_next_lines(self, lines, linesep=None)

Reads the next lines lines from the content starting at the current position.

Parameters:

Name Type Description Default
lines int

Number of lines to read

required
linesep str

The line separator. If not specified the system line separator is used.

None

Returns:

Type Description
List

List of lines found.

read_next_lines_until(self, tag_end, linesep=None)

Reads lines until a tag is found.

Parameters:

Name Type Description Default
tag_end str

The tag to search for.

required
linesep str

The line separator. If not specified the system line separator is used.

None

Returns:

Type Description
List

List of lines found.

read_until(self, end)

Read the content from the current cursor position until the position given by the end tag.

Parameters:

Name Type Description Default
end str

The tag to search for.

required

Returns:

Type Description
str

The sliced content between current position and end tag location.

Back to top