summaryrefslogtreecommitdiff
path: root/yarp
diff options
context:
space:
mode:
authorJemma Issroff <[email protected]>2023-09-22 12:05:47 -0400
committerGitHub <[email protected]>2023-09-22 12:05:47 -0400
commit9abaf392b1dd7d91392c2a35541ab1838b0b9e2f (patch)
treee1fed368c5ad2e2ba46435fb86652f197da94f69 /yarp
parentc54e225f34957967709dee59c0d66b265fd30e05 (diff)
Resync yarp (#8498)
* [YARP] Reject numbered parameters in block parameters * [YARP] Do not allow BEGIN except the toplevel --------- Co-authored-by: Haldun Bayhantopcu <[email protected]>
Diffstat (limited to 'yarp')
-rw-r--r--yarp/diagnostic.c1
-rw-r--r--yarp/diagnostic.h1
-rw-r--r--yarp/yarp.c19
3 files changed, 16 insertions, 5 deletions
diff --git a/yarp/diagnostic.c b/yarp/diagnostic.c
index cade793cfe..60a80ece17 100644
--- a/yarp/diagnostic.c
+++ b/yarp/diagnostic.c
@@ -77,6 +77,7 @@ static const char* const diagnostic_messages[YP_DIAGNOSTIC_ID_LEN] = {
[YP_ERR_BEGIN_TERM] = "Expected an `end` to close the `begin` statement",
[YP_ERR_BEGIN_UPCASE_BRACE] = "Expected a `{` after `BEGIN`",
[YP_ERR_BEGIN_UPCASE_TERM] = "Expected a `}` to close the `BEGIN` statement",
+ [YP_ERR_BEGIN_UPCASE_TOPLEVEL] = "BEGIN is permitted only at toplevel",
[YP_ERR_BLOCK_PARAM_LOCAL_VARIABLE] = "Expected a local variable name in the block parameters",
[YP_ERR_BLOCK_PARAM_PIPE_TERM] = "Expected the block parameters to end with `|`",
[YP_ERR_BLOCK_TERM_BRACE] = "Expected a block beginning with `{` to end with `}`",
diff --git a/yarp/diagnostic.h b/yarp/diagnostic.h
index 250c53cad5..39ae9e7157 100644
--- a/yarp/diagnostic.h
+++ b/yarp/diagnostic.h
@@ -42,6 +42,7 @@ typedef enum {
YP_ERR_BEGIN_TERM,
YP_ERR_BEGIN_UPCASE_BRACE,
YP_ERR_BEGIN_UPCASE_TERM,
+ YP_ERR_BEGIN_UPCASE_TOPLEVEL,
YP_ERR_BLOCK_PARAM_LOCAL_VARIABLE,
YP_ERR_BLOCK_PARAM_PIPE_TERM,
YP_ERR_BLOCK_TERM_BRACE,
diff --git a/yarp/yarp.c b/yarp/yarp.c
index b641521be5..8fd5392693 100644
--- a/yarp/yarp.c
+++ b/yarp/yarp.c
@@ -4818,10 +4818,20 @@ yp_parser_local_add_owned(yp_parser_t *parser, const uint8_t *start, size_t leng
if (constant_id != 0) yp_parser_local_add(parser, constant_id);
}
+static inline bool
+token_is_numbered_parameter(const uint8_t *start, const uint8_t *end) {
+ return (end - start == 2) && (start[0] == '_') && (start[1] != '0') && (yp_char_is_decimal_digit(start[1]));
+}
+
// Add a parameter name to the current scope and check whether the name of the
// parameter is unique or not.
static void
yp_parser_parameter_name_check(yp_parser_t *parser, yp_token_t *name) {
+ // We want to check whether the parameter name is a numbered parameter or not.
+ if (token_is_numbered_parameter(name->start, name->end)) {
+ yp_diagnostic_list_append(&parser->error_list, name->start, name->end, YP_ERR_PARAMETER_NUMBERED_RESERVED);
+ }
+
// We want to ignore any parameter name that starts with an underscore.
if ((*name->start == '_')) return;
@@ -4903,11 +4913,6 @@ char_is_global_name_punctuation(const uint8_t b) {
}
static inline bool
-token_is_numbered_parameter(const uint8_t *start, const uint8_t *end) {
- return (end - start == 2) && (start[0] == '_') && (start[1] != '0') && (yp_char_is_decimal_digit(start[1]));
-}
-
-static inline bool
token_is_setter_name(yp_token_t *token) {
return (
(token->type == YP_TOKEN_IDENTIFIER) &&
@@ -12155,6 +12160,10 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
yp_statements_node_t *statements = parse_statements(parser, YP_CONTEXT_PREEXE);
expect1(parser, YP_TOKEN_BRACE_RIGHT, YP_ERR_BEGIN_UPCASE_TERM);
+ yp_context_t context = parser->current_context->context;
+ if ((context != YP_CONTEXT_MAIN) && (context != YP_CONTEXT_PREEXE)) {
+ yp_diagnostic_list_append(&parser->error_list, keyword.start, keyword.end, YP_ERR_BEGIN_UPCASE_TOPLEVEL);
+ }
return (yp_node_t *) yp_pre_execution_node_create(parser, &keyword, &opening, statements, &parser->previous);
}
case YP_TOKEN_KEYWORD_BREAK: