cfpq_data.grammars.readwrite.regex#

Read (and write) a regular expression from (and to) different sources.

Functions

regex_from_text(text)

Create a regular expression [1] from text.

regex_from_txt(path)

Create a regular expression [1] from TXT file.

regex_to_text(regex)

Turns a regular expression [1] into its text representation.

regex_to_txt(regex, path)

Saves a regular expression [1] text representation into TXT file.

regex_from_text(text: str) → Regex[source]#

Create a regular expression [1] from text.

Parameters:
textstr

The text with which the regular expression will be created.

Returns:
regexRegex

Regular expression.

References

Examples

>>> from cfpq_data import *
>>> regex = regex_from_text("a (bc|d*)")
>>> regex_to_text(regex)
'(a (bc|(d)*))'
regex_from_txt(path: Path | str) → Regex[source]#

Create a regular expression [1] from TXT file.

Parameters:
pathUnion[Path, str]

The path to the TXT file with which the regular expression will be created.

Returns:
regexRegex

Regular expression.

References

Examples

>>> from cfpq_data import *
>>> regex_1 = regex_from_text("a (bc|d*)")
>>> path = regex_to_txt(regex_1, "test.txt")
>>> regex = regex_from_txt(path)
>>> regex_to_text(regex)
'(a (bc|(d)*))'
regex_to_text(regex: Regex) → str[source]#

Turns a regular expression [1] into its text representation.

Parameters:
regexRegex

Regular expression.

Returns:
textstr

Regular expression text representation.

References

Examples

>>> from cfpq_data import *
>>> regex = regex_from_text("a (bc|d*)")
>>> regex_to_text(regex)
'(a (bc|(d)*))'
regex_to_txt(regex: Regex, path: Path | str) → Path[source]#

Saves a regular expression [1] text representation into TXT file.

Parameters:
regexRegex

Regular expression.

pathUnion[Path, str]

The path to the TXT file where regular expression text representation will be saved.

Returns:
pathPath

The path to the TXT file where regular expression text representation will be saved.

References

Examples

>>> from cfpq_data import *
>>> regex = regex_from_text("a (bc|d*)")
>>> path = regex_to_txt(regex, "test.txt")