File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1042,6 +1042,24 @@ Stmt* parser_parse(Parser* parser) {
10421042 while (parser -> current_token .type != TOKEN_EOF ) {
10431043 Stmt * stmt = parse_statement (parser );
10441044 if (stmt ) {
1045+ /* Enforce specification: top-level expression statements and
1046+ * assignments must occupy their own logical line. If we parsed
1047+ * such a statement but the next token is not a logical newline
1048+ * (TOKEN_NEWLINE) or EOF, report a parse error and synthesize
1049+ * a THROW so runtime TRY/CATCH can observe it. Then
1050+ * synchronize to the next logical newline. */
1051+ if ((stmt -> type == STMT_EXPR || stmt -> type == STMT_ASSIGN ) &&
1052+ parser -> current_token .type != TOKEN_NEWLINE &&
1053+ parser -> current_token .type != TOKEN_EOF ) {
1054+ report_error (parser , "Expression statement or assignment must occupy its own logical line" );
1055+ append_parse_error_throw_stmt (parser , program );
1056+ while (parser -> current_token .type != TOKEN_EOF && parser -> current_token .type != TOKEN_NEWLINE ) {
1057+ advance (parser );
1058+ }
1059+ skip_newlines (parser );
1060+ continue ;
1061+ }
1062+
10451063 char * line_text = lexer_get_line (parser -> lexer , stmt -> line );
10461064 stmt_set_src (stmt , line_text );
10471065 free (line_text );
You can’t perform that action at this time.
0 commit comments