Skip to content

Re method does not use the input custom ctx argument #111

@Qiuye-Ali

Description

@Qiuye-Ali

in cvc5_pythonic.py, the Re function is used to construct a regular expression term from string:

def Re(s, ctx=None):
    """The regular expression that accepts the string s

    >>> re = Re('a')
    >>> simplify(InRe('a',re))
    True
    >>> simplify(InRe('b',re))
    False
    """
    s = _py2expr(s)
    return ReRef(s.ctx.tm.mkTerm(Kind.STRING_TO_REGEXP, s.ast), s.ctx)

However, there is a problem here. Although this function allows users to provide optional ctx argument, it did not use it in the _py2expr step, which means even if a user provides a custom ctx, the global main_ctx is used nonetheless.

A quick fix is to just pass the input ctx argument:

def Re(s, ctx=None):
    """The regular expression that accepts the string s

    >>> re = Re('a')
    >>> simplify(InRe('a',re))
    True
    >>> simplify(InRe('b',re))
    False
    """
    s = _py2expr(s, ctx)
    return ReRef(s.ctx.tm.mkTerm(Kind.STRING_TO_REGEXP, s.ast), s.ctx)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions