Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
# If the repeat is used as a duplication we can use the duplication
# which is supported by libcleri
if hasattr(self._element, 'name') \
and self._min == 1 \
and self._max == 1:
return 'cleri_dup({}, {})'.format(
gid,
self._element.name)
return 'cleri_repeat({}, {}, {}, {})'.format(
gid,
self._element._export_c(c_indent, indent, enums),
self._min,
self._max or 'undefined')
@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
return 'cleri_tokens({}, "{}")'.format(
gid,
' '.join(self._tokens))
@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
return 'cleri_optional({}, {})'.format(
gid,
self._element._export_c(c_indent, indent, enums))
@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
return 'cleri_list({}, {}, {}, {}, {}, {})'.format(
gid,
self._element._export_c(c_indent, indent, enums),
self._delimiter._export_c(c_indent, indent, enums),
self._min,
self._max or '0',
'1' if self._opt else '0')
@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
assert not(self._compiled.flags & re.IGNORECASE), \
'libcleri has currently no support for the re.IGNORECASE flag'
return 'cleri_regex({}, "{}")'.format(
gid,
self._compiled.pattern
.replace('\\', '\\\\')
.replace('\'', '\\\'')
.replace('\\"', '"')
.replace('"', '\\"'))
@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
return 'cleri_keyword({}, "{}", {})'.format(
gid,
self._keyword,
'CLERI_CASE_INSENSITIVE'
if self._ign_case else 'CLERI_CASE_SENSITIVE')
@c_export
def _run_export_c(self, js_indent, indent, enums, gid):
return 'cleri_token({}, "{}")'.format(
gid,
self._token)
@c_export
def _run_export_c(self, c_indent, indent, enums, gid):
new_indent = indent + 1
value = ',\n'.join(['{indent}{elem}'.format(
indent=c_indent * new_indent,
elem=elem._export_c(
c_indent,
new_indent,
enums)) for elem in self._elements])
return 'cleri_choice(\n{gid},\n{mg},\n{num},\n{val}\n{indent})'.format(
gid='{indent}{gid}'.format(
indent=c_indent * (indent + 1),
gid=gid),
mg='{indent}{mg}'.format(
indent=c_indent * (indent + 1),
mg=('CLERI_FIRST_MATCH', 'CLERI_MOST_GREEDY')[
self._get_node_result == self._most_greedy_result]),