Skip to content

"unbalanced parenthesis" error Python 3.8 #134

Open

Description

@bicmane

I've got a couple of .rive files that have quite a few triggers. And they work. But sometimes this error appears instead of giving me the reply. And I can't find the solution, I'm not really sure what's going on.

I leave the message that I figure:

File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rivescript\rivescript.py", line 947, in reply
return self._brain.reply(user, msg, errors_as_replies)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rivescript\brain.py", line 68, in reply
reply = self._getreply(user, msg, ignore_object_errors=errors_as_replies)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rivescript\brain.py", line 269, in _getreply
regexp = self.reply_regexp(user, pattern)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\rivescript\brain.py", line 505, in reply_regexp
return re.compile(r'^' + regexp.lower() + r'$', re.UNICODE)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 250, in compile
return _compile(pattern, flags)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\re.py", line 302, in _compile
p = sre_compile.compile(pattern, flags)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\sre_parse.py", line 962, in parse
raise source.error("unbalanced parenthesis")
re.error: unbalanced parenthesis at position 60

I am testing and There is no criterion by which this appears, usually when trigger change (not always)
Any solution?

Activity

  1. bicmane commented on Nov 30, 2019

    @bicmane
    Author

    I think I found the solution.

    It seems to generate a conflict between the ! array and the parentheses.

    For example,

    ! array genero = hombre|mujer|persona de (género|sexo) (masculino|femenino)|persona masculina|persona femenina

    I had to do it like this.

    ! array genero = hombre|mujer|persona de género masculino|persona de género femenino|persona de sexo masculino|persona de sexo femenino|persona masculina|persona femenina

    Another detail to keep in mind,
    also conflicts with wildcards (*, #, _) in the ! array

    I publish this because in rivescript tutorial does not clarify in the Array section, as far as I know. Maybe it will help someone.

    Greetings!

  2. kirsle commented on Dec 3, 2019

    @kirsle
    Member

    Yeah, using parenthesis inside of ! array values isn't supported behavior.

    RiveScript is heavily powered by regular expressions under the hood, but the user-facing language uses "simplified regular expressions" for triggers, which makes it easy to program a bot without the overwhelming complexity of raw regexps.

    In this case, the ! array command is parsed by splitting at pipe "|" symbols to get the array items; since you have parenthesis with their own pipes inside, one array item looks like "persona de (género" and the other "sexo) (masculino" and so on. When these array fragments get put into the trigger matching regexp, unbalanced parenthesis is the result.

    Probably the RiveScript syntax checker should look for parenthesis in an array definition and consider it a syntax error at parse time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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