@@ -15,7 +15,7 @@ func parseExpressionList(p *Parser, first ast.Expression) ast.ExpressionList {
1515 next := parseExpression (p )
1616 if next == nil {
1717 token := p .peek ()
18- p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& token .Start , & token .End ), "Expected expression after comma" , report .PARSING_PHASE )
18+ p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& token .Start , & token .End ), "expected expression after comma" , report .PARSING_PHASE )
1919 break
2020 }
2121 exprs = append (exprs , next )
@@ -40,7 +40,7 @@ func parseExpressionStatement(p *Parser, first ast.Expression) ast.Statement {
4040
4141// parseBlock parses a block of statements
4242func parseBlock (p * Parser ) * ast.Block {
43- start := p .consume (lexer .OPEN_CURLY , report . EXPECTED_OPEN_BRACE ).Start
43+ start := p .consume (lexer .OPEN_CURLY , "expected '{' before block" ).Start
4444
4545 nodes := make ([]ast.Node , 0 )
4646
@@ -51,7 +51,7 @@ func parseBlock(p *Parser) *ast.Block {
5151 }
5252 }
5353
54- end := p .consume (lexer .CLOSE_CURLY , report . EXPECTED_CLOSE_BRACE ).End
54+ end := p .consume (lexer .CLOSE_CURLY , "expected '}' after block" ).End
5555
5656 return & ast.Block {
5757 Nodes : nodes ,
@@ -60,7 +60,9 @@ func parseBlock(p *Parser) *ast.Block {
6060}
6161
6262func parseReturnStmt (p * Parser ) ast.Statement {
63- start := p .consume (lexer .RETURN_TOKEN , report .EXPECTED_RETURN_KEYWORD ).Start
63+
64+ start := p .advance ().Start // consume 'return' and get start position
65+
6466 end := start
6567
6668 // Return immediately if there's a semicolon (no return value)
@@ -78,7 +80,7 @@ func parseReturnStmt(p *Parser) ast.Statement {
7880 p .ctx .Reports .AddSyntaxError (
7981 p .fullPath ,
8082 source .NewLocation (& token .Start , & token .End ),
81- report . INVALID_EXPRESSION ,
83+ "invalid expression after return keyword" ,
8284 report .PARSING_PHASE ,
8385 ).AddHint ("add an expression after the return keyword" )
8486
@@ -96,7 +98,7 @@ func parseReturnStmt(p *Parser) ast.Statement {
9698 p .ctx .Reports .AddSyntaxError (
9799 p .fullPath ,
98100 source .NewLocation (& comma .Start , & comma .End ),
99- "Multiple return values are not supported" ,
101+ "multiple return values are not supported" ,
100102 report .PARSING_PHASE ,
101103 ).AddHint ("functions can only return a single value" )
102104
@@ -281,26 +283,26 @@ func handlePlusMinus(p *Parser) ast.Expression {
281283 operator := p .advance ()
282284 // Check for consecutive operators
283285 if p .match (lexer .PLUS_PLUS_TOKEN , lexer .MINUS_MINUS_TOKEN ) {
284- errMsg := report . INVALID_CONSECUTIVE_INCREMENT
286+ errMsg := "invalid consecutive increment operators"
285287 if operator .Kind == lexer .MINUS_MINUS_TOKEN {
286- errMsg = report . INVALID_CONSECUTIVE_DECREMENT
288+ errMsg = "invalid consecutive decrement operators"
287289 }
288290 p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& operator .Start , & operator .End ), errMsg , report .PARSING_PHASE )
289291 return nil
290292 }
291293 operand := parseUnary (p )
292294 if operand == nil {
293- errMsg := report . INVALID_INCREMENT_OPERAND
295+ errMsg := "invalid operand for increment operator"
294296 if operator .Kind == lexer .MINUS_MINUS_TOKEN {
295- errMsg = report . INVALID_DECREMENT_OPERAND
297+ errMsg = "invalid operand for decrement operator"
296298 }
297299 p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& operator .Start , & operator .End ), errMsg , report .PARSING_PHASE )
298300 return nil
299301 }
300302
301303 // Check if operand already has a postfix operator
302304 if _ , ok := operand .(* ast.PostfixExpr ); ok {
303- p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& operator .Start , & operator .End ), "Cannot mix prefix and postfix operators" , report .PARSING_PHASE )
305+ p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& operator .Start , & operator .End ), "cannot mix prefix and postfix operators" , report .PARSING_PHASE )
304306 return nil
305307 }
306308
@@ -316,7 +318,7 @@ func handleSpread(p *Parser) ast.Expression {
316318 operator := p .advance ()
317319 right := parseUnary (p )
318320 if right == nil {
319- p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& operator .Start , & operator .End ), "Expected expression after spread operator" , report .PARSING_PHASE )
321+ p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& operator .Start , & operator .End ), "expected expression after spread operator" , report .PARSING_PHASE )
320322 return nil
321323 }
322324
@@ -334,7 +336,7 @@ func parseCast(p *Parser) ast.Expression {
334336 asToken := p .advance ()
335337 targetType , ok := parseType (p )
336338 if ! ok || targetType == nil {
337- p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& asToken .Start , & asToken .End ), "Expected type after 'as' keyword" , report .PARSING_PHASE )
339+ p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& asToken .Start , & asToken .End ), "expected type after 'as' keyword" , report .PARSING_PHASE )
338340 return expr
339341 }
340342
@@ -356,11 +358,11 @@ func parseIndexing(p *Parser, expr ast.Expression) (ast.Expression, bool) {
356358 index := parseExpression (p )
357359 if index == nil {
358360 token := p .peek ()
359- p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& token .Start , & token .End ), report . MISSING_INDEX_EXPRESSION , report .PARSING_PHASE )
361+ p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& token .Start , & token .End ), "expected valid indexing expression" , report .PARSING_PHASE )
360362 return nil , false
361363 }
362364
363- end := p .consume (lexer .CLOSE_BRACKET , report . EXPECTED_CLOSE_BRACKET )
365+ end := p .consume (lexer .CLOSE_BRACKET , "expected ']' after index expression" )
364366 return & ast.IndexableExpr {
365367 Indexable : & expr ,
366368 Index : & index ,
@@ -372,9 +374,9 @@ func parseIndexing(p *Parser, expr ast.Expression) (ast.Expression, bool) {
372374func parseIncDec (p * Parser , expr ast.Expression ) (ast.Expression , bool ) {
373375 operator := p .advance ()
374376 if p .match (lexer .PLUS_PLUS_TOKEN , lexer .MINUS_MINUS_TOKEN ) {
375- errMsg := report . INVALID_CONSECUTIVE_INCREMENT
377+ errMsg := "invalid consecutive increment operators"
376378 if operator .Kind == lexer .MINUS_MINUS_TOKEN {
377- errMsg = report . INVALID_CONSECUTIVE_DECREMENT
379+ errMsg = "invalid consecutive decrement operators"
378380 }
379381 p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& operator .Start , & operator .End ), errMsg , report .PARSING_PHASE )
380382 return nil , false
@@ -391,7 +393,7 @@ func handlePostfixOperator(p *Parser, expr ast.Expression) (ast.Expression, bool
391393 if p .match (lexer .PLUS_PLUS_TOKEN , lexer .MINUS_MINUS_TOKEN ) {
392394 if _ , ok := expr .(* ast.PrefixExpr ); ok {
393395 current := p .peek ()
394- p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& current .Start , & current .End ), "Cannot mix prefix and postfix operators" , report .PARSING_PHASE )
396+ p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& current .Start , & current .End ), "cannot mix prefix and postfix operators" , report .PARSING_PHASE )
395397 return nil , false
396398 }
397399 return parseIncDec (p , expr )
@@ -441,7 +443,7 @@ func parsePostfix(p *Parser) ast.Expression {
441443func parseGrouping (p * Parser ) ast.Expression {
442444 p .advance () // consume '('
443445 expr := parseExpression (p )
444- p .consume (lexer .CLOSE_PAREN , "Expected ')' after expression" )
446+ p .consume (lexer .CLOSE_PAREN , "expected ')' after expression" )
445447 return expr
446448}
447449
@@ -456,23 +458,23 @@ func parseFunctionCall(p *Parser, caller ast.Expression) (ast.Expression, bool)
456458 arg := parseExpression (p )
457459 if arg == nil {
458460 token := p .peek ()
459- p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& token .Start , & token .End ), "Expected function argument" , report .PARSING_PHASE )
461+ p .ctx .Reports .AddSyntaxError (p .fullPath , source .NewLocation (& token .Start , & token .End ), "expected function argument" , report .PARSING_PHASE )
460462 return nil , false
461463 }
462464 arguments = append (arguments , arg )
463465
464466 if p .match (lexer .CLOSE_PAREN ) {
465467 break
466468 } else {
467- comma := p .consume (lexer .COMMA_TOKEN , report . EXPECTED_COMMA_OR_CLOSE_PAREN )
469+ comma := p .consume (lexer .COMMA_TOKEN , "expected ',' or ')' after parameter" )
468470 if p .match (lexer .CLOSE_PAREN ) {
469- p .ctx .Reports .AddWarning (p .fullPath , source .NewLocation (& comma .Start , & comma .End ), report . TRAILING_COMMA_NOT_ALLOWED , report .PARSING_PHASE ).AddHint ("remove the trailing comma" )
471+ p .ctx .Reports .AddWarning (p .fullPath , source .NewLocation (& comma .Start , & comma .End ), "unnecessary trailing comma after last argument" , report .PARSING_PHASE ).AddHint ("remove the trailing comma" )
470472 break
471473 }
472474 }
473475 }
474476
475- end := p .consume (lexer .CLOSE_PAREN , report . EXPECTED_CLOSE_PAREN )
477+ end := p .consume (lexer .CLOSE_PAREN , "expected ')' after function arguments" )
476478
477479 return & ast.FunctionCallExpr {
478480 Caller : & caller ,
0 commit comments