Skip to content

Commit e604ff3

Browse files
author
hungtu
committed
aichaos#82 Allow uppercase at object and minor indent fix
1 parent 9488582 commit e604ff3

3 files changed

Lines changed: 25 additions & 18 deletions

File tree

rivescript/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ def check_syntax(self, cmd, line):
539539
if search:
540540
return "Topics should be lowercased and contain only numbers and letters"
541541
elif parts[0] == "object":
542-
search = re.search(RE.name_syntax, line)
542+
search = re.search(RE.obj_syntax, line) # Upper case is allowed
543543
if search:
544-
return "Objects can only contain numbers and letters" # TODO Acceptance of uppercase letter?
544+
return "Objects can only contain numbers and letters"
545545
elif cmd == '+' or cmd == '%' or cmd == '@':
546546
# + Trigger, % Previous, @ Redirect
547547
# This one is strict. The triggers are to be run through the regexp engine,

rivescript/regexp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class RE(object):
2424
array = re.compile(r'\@(.+?)\b')
2525
def_syntax = re.compile(r'^.+(?:\s+.+|)\s*=\s*.+?$')
2626
name_syntax = re.compile(r'[^a-z0-9_\-\s]')
27+
obj_syntax = re.compile(r'[^A-Za-z0-9_\-\s]')
2728
utf8_trig = re.compile(r'[A-Z\\.]')
2829
trig_syntax = re.compile(r'[^a-z0-9(\|)\[\]*_#@{}<>=\s]')
2930
cond_syntax = re.compile(r'^.+?\s*(?:==|eq|!=|ne|<>|<|<=|>|>=)\s*.+?=>.+?$')

tests/test_format_message.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,28 @@ def test_format_triggers(self):
3232

3333
def test_invalid_character_raise_exception(self):
3434
self.assertRaises(Exception, self.new, """
35-
+ $hello
36-
- hi
37-
""") # This test passes with `match`, which only check at the beginning
35+
+ $hello
36+
- hi
37+
""") # This test passes with `match`, which only check at the beginning
3838
self.assertRaises(Exception, self.new, """
39-
+ hello$
40-
- hi
41-
""") # This test does not pass because the beginning is good, no $
39+
+ hello$
40+
- hi
41+
""") # This test does not pass because the beginning is good, no $
4242
self.assertRaises(Exception, self.new, """
43-
> topic Greetings
44-
+ hello
45-
- hi
46-
<topics
47-
""")
43+
> topic Greetings
44+
+ hello
45+
- hi
46+
<topics
47+
""")
4848
self.assertRaises(Exception, self.new, """
49-
> object hash %perl
50-
my ($rs, $args) = @_;
51-
my $method = shift @{$args};
52-
<object
53-
""") # Test for character violation in object, no %
49+
> object hash %perl
50+
my ($rs, $args) = @_;
51+
my $method = shift @{$args};
52+
<object
53+
""") # Test for character violation in object, no %
54+
self.new("""
55+
> object hash Perl
56+
my ($rs, $args) = @_;
57+
my $method = shift @{$args};
58+
<object
59+
""") # No exception raised for uppercase character in object

0 commit comments

Comments
 (0)