Skip to content

Commit b5722d0

Browse files
author
hungtu
committed
aichaos#87 Enlarge syntax check coverage to cover empty pipes
1 parent fe503b2 commit b5722d0

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

rivescript/parser.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ def check_syntax(self, cmd, line):
549549
# - Entirely lowercase
550550
# - No symbols except: ( | ) [ ] * _ # @ { } < > =
551551
# - All brackets should be matched
552+
# - No empty option with pipe such as ||, [|, |], (|, |) and whitespace between
552553
parens = 0 # Open parenthesis
553554
square = 0 # Open square brackets
554555
curly = 0 # Open curly brackets
@@ -583,6 +584,11 @@ def check_syntax(self, cmd, line):
583584
elif angle != 0:
584585
return "Unmatched angle brackets"
585586

587+
# Check for empty pipe
588+
search = re.search(RE.empty_pipe, line)
589+
if search:
590+
return "Piped arrays can't include blank entries"
591+
586592
# In UTF-8 mode, most symbols are allowed.
587593
if self.utf8:
588594
search = re.search(RE.utf8_trig, line)

rivescript/regexp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ class RE(object):
4848
placeholder = re.compile(r'\x00(\d+)\x00')
4949
zero_star = re.compile(r'^\*$')
5050
optionals = re.compile(r'\[(.+?)\]')
51+
empty_pipe = re.compile(r'\|\s*\||\[\s*\||\|\s*\]|\(\s*\||\|\s*\)') # ||, [|, |], (|, |)

0 commit comments

Comments
 (0)