mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-11-01 06:03:00 +00:00 
			
		
		
		
	Update our parse errors to match latest illuaminate
We've been out-of-date for a while now, as we needed to update lua_menhir to work with lrgrep 3. - Better handling of standalone names/expressions - we now correctly handle lists of names. - Handle missing commas in tables in a few more places.
This commit is contained in:
		| @@ -105,6 +105,10 @@ | ||||
|    /projects/core/src/main/resources/data/computercraft/lua/rom/apis/turtle/turtle.lua) | ||||
|   (linters -var:deprecated)) | ||||
|  | ||||
| ;; Suppress unused variable warnings in the parser. | ||||
| (at /projects/core/src/main/resources/data/computercraft/lua/rom/modules/main/cc/internal/syntax/parser.lua | ||||
|   (linters -var:unused)) | ||||
|  | ||||
| (at /projects/core/src/test/resources/test-rom | ||||
|   ; We should still be able to test deprecated members. | ||||
|   (linters -var:deprecated) | ||||
|   | ||||
| @@ -453,32 +453,53 @@ function errors.local_function_dot(local_start, local_end, dot_start, dot_end) | ||||
|     } | ||||
| end | ||||
|  | ||||
| --[[- A statement of the form `x.y z` | ||||
| --[[- A statement of the form `x.y` | ||||
|  | ||||
| @tparam number token The token id. | ||||
| @tparam number pos The position right after this name. | ||||
| @return The resulting parse error. | ||||
| ]] | ||||
| function errors.standalone_name(pos) | ||||
|     expect(1, pos, "number") | ||||
| function errors.standalone_name(token, pos) | ||||
|     expect(1, token, "number") | ||||
|     expect(2, pos, "number") | ||||
|  | ||||
|     return { | ||||
|         "Unexpected symbol after name.", | ||||
|         "Unexpected " .. token_names[token] .. " after name.", | ||||
|         annotate(pos), | ||||
|         "Did you mean to assign this or call it as a function?", | ||||
|     } | ||||
| end | ||||
|  | ||||
| --[[- A statement of the form `x.y, z` | ||||
|  | ||||
| @tparam number token The token id. | ||||
| @tparam number pos The position right after this name. | ||||
| @return The resulting parse error. | ||||
| ]] | ||||
| function errors.standalone_names(token, pos) | ||||
|     expect(1, token, "number") | ||||
|     expect(2, pos, "number") | ||||
|  | ||||
|     return { | ||||
|         "Unexpected " .. token_names[token] .. " after name.", | ||||
|         annotate(pos), | ||||
|         "Did you mean to assign this?", | ||||
|     } | ||||
| end | ||||
|  | ||||
| --[[- A statement of the form `x.y`. This is similar to [`standalone_name`], but | ||||
| when the next token is on another line. | ||||
|  | ||||
| @tparam number token The token id. | ||||
| @tparam number pos The position right after this name. | ||||
| @return The resulting parse error. | ||||
| ]] | ||||
| function errors.standalone_name_call(pos) | ||||
|     expect(1, pos, "number") | ||||
| function errors.standalone_name_call(token, pos) | ||||
|     expect(1, token, "number") | ||||
|     expect(2, pos, "number") | ||||
|  | ||||
|     return { | ||||
|         "Unexpected symbol after variable.", | ||||
|         "Unexpected " .. token_names[token] .. " after name.", | ||||
|         annotate(pos + 1, "Expected something before the end of the line."), | ||||
|         "Tip: Use " .. code("()") .. " to call with no arguments.", | ||||
|     } | ||||
|   | ||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -347,7 +347,7 @@ function ( xyz , while | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected while. | ||||
| Unexpected while. Expected a variable name. | ||||
|    | | ||||
|  1 | function ( xyz , while | ||||
|    |                  ^^^^^ | ||||
| @@ -483,11 +483,11 @@ xyz , xyz while | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected symbol after name. | ||||
| Unexpected while after name. | ||||
|    | | ||||
|  1 | xyz , xyz while | ||||
|    |           ^ | ||||
| Did you mean to assign this or call it as a function? | ||||
| Did you mean to assign this? | ||||
| ``` | ||||
| 
 | ||||
| 
 | ||||
| @@ -831,7 +831,7 @@ xyz while | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected symbol after name. | ||||
| Unexpected while after name. | ||||
|    | | ||||
|  1 | xyz while | ||||
|    |     ^ | ||||
| @@ -858,7 +858,7 @@ xyz while | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected symbol after name. | ||||
| Unexpected while after name. | ||||
|    | | ||||
|  1 | xyz while | ||||
|    |     ^ | ||||
| @@ -1056,7 +1056,7 @@ local while | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected while. | ||||
| Unexpected while. Expected a variable name. | ||||
|    | | ||||
|  1 | local while | ||||
|    |       ^^^^^ | ||||
| @@ -1272,7 +1272,7 @@ repeat --[[eof]] | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected end of file. Expected a statement. | ||||
| Unexpected end of file. Expected a variable name. | ||||
|    | | ||||
|  2 | -- Line 1: 'until' expected near <eof> (program) | ||||
|    |                                                 ^ | ||||
| @@ -1389,7 +1389,7 @@ while | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected while. | ||||
| Unexpected while. Expected an expression. | ||||
|    | | ||||
|  1 | while | ||||
|    | ^^^^^ | ||||
|   | ||||
| @@ -38,6 +38,20 @@ Unexpected = in expression. | ||||
| Tip: Wrap the preceding expression in [ and ] to use it as a table key. | ||||
| ``` | ||||
| 
 | ||||
| and also | ||||
| 
 | ||||
| ```lua | ||||
| return { x + 1 = 1 } | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected = in expression. | ||||
|    | | ||||
|  1 | return { x + 1 = 1 } | ||||
|    |                ^ | ||||
| Tip: Wrap the preceding expression in [ and ] to use it as a table key. | ||||
| ``` | ||||
| 
 | ||||
| Note this doesn't occur if this there's already a table key here: | ||||
| 
 | ||||
| ```lua | ||||
| @@ -102,6 +116,7 @@ Unexpected end of file. Are you missing a closing bracket? | ||||
| ``` | ||||
| 
 | ||||
| ## Missing commas in tables | ||||
| We try to detect missing commas in tables, and print an appropriate error message. | ||||
| 
 | ||||
| ```lua | ||||
| return { 1 2 } | ||||
| @@ -129,6 +144,39 @@ Unexpected number in table. | ||||
|  1 | return { 1, 2 3 } | ||||
|    |              ^ Are you missing a comma here? | ||||
| ``` | ||||
| 
 | ||||
| This also works with table keys. | ||||
| 
 | ||||
| ```lua | ||||
| print({ x = 1 y = 2 }) | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected identifier in table. | ||||
|    | | ||||
|  1 | print({ x = 1 y = 2 }) | ||||
|    |               ^ | ||||
|    | | ||||
|  1 | print({ x = 1 y = 2 }) | ||||
|    |              ^ Are you missing a comma here? | ||||
| ``` | ||||
| 
 | ||||
| ```lua | ||||
| print({ ["x"] = 1 ["y"] = 2 }) | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected [ in table. | ||||
|    | | ||||
|  1 | print({ ["x"] = 1 ["y"] = 2 }) | ||||
|    |                   ^ | ||||
|    | | ||||
|  1 | print({ ["x"] = 1 ["y"] = 2 }) | ||||
|    |                  ^ Are you missing a comma here? | ||||
| ``` | ||||
| 
 | ||||
| We gracefully handle the case where we are actually missing a closing brace. | ||||
| 
 | ||||
| ```lua | ||||
| print({ 1, ) | ||||
| ``` | ||||
| @@ -172,7 +220,7 @@ local _ = 1 | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected symbol after variable. | ||||
| Unexpected local after name. | ||||
|    | | ||||
|  1 | term.clear | ||||
|    |           ^ Expected something before the end of the line. | ||||
| @@ -186,7 +234,7 @@ x 1 | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected symbol after name. | ||||
| Unexpected number after name. | ||||
|    | | ||||
|  1 | x 1 | ||||
|    |   ^ | ||||
| @@ -200,13 +248,41 @@ term.clear | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected symbol after variable. | ||||
| Unexpected end of file after name. | ||||
|    | | ||||
|  1 | term.clear | ||||
|    |           ^ Expected something before the end of the line. | ||||
| Tip: Use () to call with no arguments. | ||||
| ``` | ||||
| 
 | ||||
| When we've got a list of variables, we only suggest assigning it. | ||||
| 
 | ||||
| ```lua | ||||
| term.clear, foo | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected end of file after name. | ||||
|    | | ||||
|  1 | term.clear, foo | ||||
|    |                ^ | ||||
| Did you mean to assign this? | ||||
| ``` | ||||
| 
 | ||||
| And when we've got a partial expression, we only suggest calling it. | ||||
| 
 | ||||
| ```lua | ||||
| (a + b) | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected end of file after name. | ||||
|    | | ||||
|  1 | (a + b) | ||||
|    |        ^ Expected something before the end of the line. | ||||
| Tip: Use () to call with no arguments. | ||||
| ``` | ||||
| 
 | ||||
| ## If statements | ||||
| For if statements, we say when we expected the `then` keyword. | ||||
| 
 | ||||
| @@ -425,7 +501,7 @@ goto 2 | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected symbol after name. | ||||
| Unexpected number after name. | ||||
|    | | ||||
|  1 | goto 2 | ||||
|    |      ^ | ||||
| @@ -460,6 +536,31 @@ Unexpected end of file. | ||||
|    |   ^ | ||||
| ``` | ||||
| 
 | ||||
| ## Missing function arguments | ||||
| We provide an error message for missing arguments in function definitions: | ||||
| 
 | ||||
| ```lua | ||||
| function f | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected end of file. Expected ( to start function arguments. | ||||
|    | | ||||
|  1 | function f | ||||
|    |           ^ | ||||
| ``` | ||||
| 
 | ||||
| ```lua | ||||
| return function | ||||
| ``` | ||||
| 
 | ||||
| ```txt | ||||
| Unexpected end of file. Expected ( to start function arguments. | ||||
|    | | ||||
|  1 | return function | ||||
|    |                ^ | ||||
| ``` | ||||
| 
 | ||||
| # Function calls | ||||
| 
 | ||||
| ## Additional commas | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates