openpectus.lang.exec.regex

Attributes

REGEX_DURATION

Regex that parses a duration, ie. a number with a time unit to groups 'number' and 'number_unit'

REGEX_DURATION_OPTIONAL

Regex that parses an optional duration, i.e. optional number with time unit to groups 'number' and 'number_unit'

REGEX_INT

Regex that parses an integer to groups 'number'

REGEX_TEXT

Regex that parses text input the group 'text'

REGEX_BASE_ARG

Functions

RegexNumber(units[, non_negative, int_only])

Create a regex that parses a number with optional unit to arguments number and optionally number_unit.

RegexNumberOptional(units[, non_negative, int_only])

Create a regex that parses an optional number with optional unit to arguments number and optionally number_unit.

RegexCategorical([exclusive_options, additive_options])

Create a regex that parses categorical text into an argument named option.

RegexText([allow_empty])

Parses text into an argument named text.

get_duration_end(tick_time, time, unit)

Helper to obtain duration from REGEX_DURATION value.

Module Contents

openpectus.lang.exec.regex.RegexNumber(units, non_negative=False, int_only=False)

Create a regex that parses a number with optional unit to arguments number and optionally number_unit.

number_unit is only matched if one or more units are given.

Parameters:
  • units (list[str] | None)

  • non_negative (bool)

  • int_only (bool)

Return type:

str

openpectus.lang.exec.regex.RegexNumberOptional(units, non_negative=False, int_only=False)

Create a regex that parses an optional number with optional unit to arguments number and optionally number_unit.

number_unit is only matched if one or more units are given.

Parameters:
  • units (list[str] | None)

  • non_negative (bool)

  • int_only (bool)

Return type:

str

openpectus.lang.exec.regex.RegexCategorical(exclusive_options=None, additive_options=None)

Create a regex that parses categorical text into an argument named option.

Examples - exclusive:

regex = RegexCategorical(exclusive_options=["Open", "Closed"])

self.assertEqual(re.search(regex, "Closed").groupdict(), dict(option="Closed"))

self.assertEqual(re.search(regex, "VA01"), None)

self.assertEqual(re.search(regex, "Open").groupdict(), dict(option="Open"))

self.assertEqual(re.search(regex, "Open+Closed"), None)

Examples - exclusive and additive:

regex = RegexCategorical(exclusive_options=['Closed'], additive_options=['VA01', 'VA02', 'VA03'])

self.assertEqual(re.search(regex, "Closed").groupdict(), dict(option="Closed"))

self.assertEqual(re.search(regex, "Closed+VA01"), None)

self.assertEqual(re.search(regex, "VA01").groupdict(), dict(option="VA01"))

self.assertEqual(re.search(regex, "VA01+VA02").groupdict(), dict(option="VA01+VA02"))

self.assertEqual(re.search(regex, "Open+Closed"), None)
Parameters:
  • exclusive_options (list[str] | None)

  • additive_options (list[str] | None)

Return type:

str

openpectus.lang.exec.regex.RegexText(allow_empty=False)

Parses text into an argument named text.

Parameters:

allow_empty (bool)

Return type:

str

openpectus.lang.exec.regex.REGEX_DURATION = '^\\s*(?P<number>[0-9]+?|[0-9]+)\\s* ?(?P<number_unit>)\\s*$'

Regex that parses a duration, ie. a number with a time unit to groups ‘number’ and ‘number_unit’

openpectus.lang.exec.regex.REGEX_DURATION_OPTIONAL = '(^\\s*(?P<number>-?[0-9]+?|-?[0-9]+)\\s* ?(?P<number_unit>)\\s*$)|^\\s*$'

Regex that parses an optional duration, i.e. optional number with time unit to groups ‘number’ and ‘number_unit’

openpectus.lang.exec.regex.REGEX_INT = '^\\s*(?P<number>[0-9]+?|[0-9]+)\\s*\\s*$'

Regex that parses an integer to groups ‘number’

openpectus.lang.exec.regex.REGEX_TEXT = '^(?P<text>.*)$'

Regex that parses text input the group ‘text’

openpectus.lang.exec.regex.REGEX_BASE_ARG = '^\\s*()\\s*$'
openpectus.lang.exec.regex.get_duration_end(tick_time, time, unit)

Helper to obtain duration from REGEX_DURATION value.

Parameters:
  • tick_time (float)

  • time (float)

  • unit (str)

Return type:

float