Skip to content

Commit

Permalink
disallow operators starting with a closing bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
billhails committed Oct 20, 2024
1 parent 3b3d756 commit cbf856c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/pratt_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ static void validateOperator(PrattParser *parser, PrattUTF8 *operator) {
parserError(parser, "operator cannot start with a numeric digit");
} else if (utf8_isopen(operator->entries)) {
parserError(parser, "operator cannot start with an opening bracket");
} else if (utf8_isclose(operator->entries)) {
parserError(parser, "operator cannot start with a closing bracket");
} else {
for (Index i = 0; i < operator->size; i++) {
if (isspace(operator->entries[i])) {
Expand Down
4 changes: 4 additions & 0 deletions src/unicode.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ bool unicode_isopen(Character c) {
return unicode_isvalid(c) && (category[c] == GC_Ps);
}

bool unicode_isclose(Character c) {
return unicode_isvalid(c) && (category[c] == GC_Pe);
}

bool unicode_issymbol(Character c) {
return unicode_isvalid(c) && ((category[c] & GC_MASK) == GC_S);
}
Expand Down
1 change: 1 addition & 0 deletions src/unicode.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ bool unicode_isalnum(Character c);
bool unicode_isalpha(Character c);
bool unicode_isascii(Character c);
bool unicode_isblank(Character c);
bool unicode_isclose(Character c);
bool unicode_iscntrl(Character c);
bool unicode_isdigit(Character c);
bool unicode_isgraph(Character c);
Expand Down
6 changes: 6 additions & 0 deletions src/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,9 @@ bool utf8_isopen(unsigned char *s) {
return unicode_isopen(c);
}

bool utf8_isclose(unsigned char *s) {
Character c = 0;
utf8Sgetc(s, &c);
return unicode_isclose(c);
}

1 change: 1 addition & 0 deletions src/utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ bool utf8_isalnum(unsigned char *s);
bool utf8_isalpha(unsigned char *s);
bool utf8_isascii(unsigned char *s);
bool utf8_isblank(unsigned char *s);
bool utf8_isclose(unsigned char *s);
bool utf8_iscntrl(unsigned char *s);
bool utf8_isdigit(unsigned char *s);
bool utf8_isgraph(unsigned char *s);
Expand Down

0 comments on commit cbf856c

Please sign in to comment.