njs_function_lambda_t *lambda, uint32_t line);
-static void njs_generate_syntax_error(njs_vm_t *vm, uint32_t token_line,
- const char* fmt, ...);
+static void njs_generate_syntax_error(njs_vm_t *vm, njs_parser_node_t *node,
+ const char *fmt, ...);
#define njs_generate_code(generator, type, code) \
syntax_error:
- njs_generate_syntax_error(vm, node->token_line,
- "Illegal continue statement");
+ njs_generate_syntax_error(vm, node, "Illegal continue statement");
return NXT_ERROR;
}
syntax_error:
- njs_generate_syntax_error(vm, node->token_line, "Illegal break statement");
+ njs_generate_syntax_error(vm, node, "Illegal break statement");
return NXT_ERROR;
}
static void
-njs_generate_syntax_error(njs_vm_t *vm, uint32_t token_line,
- const char* fmt, ...)
+njs_generate_syntax_error(njs_vm_t *vm, njs_parser_node_t *node,
+ const char *fmt, ...)
{
- va_list args;
- u_char buf[256], *end;
+ size_t width;
+ u_char msg[NXT_MAX_ERROR_STR];
+ u_char *p, *end;
+ va_list args;
+ njs_parser_scope_t *scope;
+
+ p = msg;
+ end = msg + NXT_MAX_ERROR_STR;
va_start(args, fmt);
- end = nxt_vsprintf(buf, buf + sizeof(buf), fmt, args);
+ p = nxt_vsprintf(p, end, fmt, args);
va_end(args);
- njs_syntax_error(vm, "%*s in %uD", end - buf, buf, token_line);
+ scope = node->scope;
+
+ width = nxt_length(" in ") + scope->file.length + NXT_INT_T_LEN;
+
+ if (p > end - width) {
+ p = end - width;
+ }
+
+ if (scope->file.start != NULL) {
+ p = nxt_sprintf(p, end, " in %V:%uD", &scope->file, node->token_line);
+
+ } else {
+ p = nxt_sprintf(p, end, " in %uD", node->token_line);
+ }
+
+ njs_error_new(vm, NJS_OBJECT_SYNTAX_ERROR, msg, p - msg);
}
static njs_ret_t
njs_parser_scope_begin(njs_vm_t *vm, njs_parser_t *parser, njs_scope_t type)
{
+ nxt_int_t ret;
nxt_uint_t nesting;
nxt_array_t *values;
njs_parser_scope_t *scope, *parent;
}
}
- scope = nxt_mp_alloc(vm->mem_pool, sizeof(njs_parser_scope_t));
+ scope = nxt_mp_zalloc(vm->mem_pool, sizeof(njs_parser_scope_t));
if (nxt_slow_path(scope == NULL)) {
return NXT_ERROR;
}
scope->type = type;
- scope->top = NULL;
if (type == NJS_SCOPE_FUNCTION) {
scope->next_index[0] = type;
scope->values[0] = values;
scope->values[1] = NULL;
+ if (parser->lexer->file.start != NULL) {
+ ret = njs_name_copy(vm, &scope->file, &parser->lexer->file);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return NXT_ERROR;
+ }
+ }
+
parent = parser->scope;
scope->parent = parent;
parser->scope = scope;
void
njs_parser_error(njs_vm_t *vm, njs_parser_t *parser, njs_value_type_t type,
const char *fmt, ...)
- {
+{
size_t width;
u_char *p, *end;
u_char msg[NXT_MAX_ERROR_STR];