1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Bump CC:T to 1.103.1

Woops!

 - Fix the REPL not printing values, as exception.try didn't return
   values. It did originally, and then I tried to simplify it >_>

 - Change repl_exprs to run an expression and program parser in
   parallel, rather than handling the parallelism on the grammar side -
   that has a few shift/reduce conflicts which result in bad parse
   errors.
This commit is contained in:
Jonathan Coates 2023-02-09 21:42:57 +00:00
parent 9e6e0c8b88
commit 6a116aadb8
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
7 changed files with 170 additions and 134 deletions

View File

@ -6,7 +6,7 @@ kotlin.jvm.target.validation.mode=error
# Mod properties
isUnstable=false
modVersion=1.103.0
modVersion=1.103.1
# Minecraft properties: We want to configure this here so we can read it in settings.gradle
mcVersion=1.19.3

View File

@ -1,3 +1,9 @@
# New features in CC: Tweaked 1.103.1
Several bug fixes:
* Fix values not being printed in the REPL
* Fix `function f()` providing suboptimal parse errors in the REPL.
# New features in CC: Tweaked 1.103.0
* The shell now supports hashbangs (`#!`) (emmachase).

View File

@ -1,17 +1,7 @@
New features in CC: Tweaked 1.103.0
* The shell now supports hashbangs (`#!`) (emmachase).
* Error messages in `edit` are now displayed in red on advanced computers.
* `turtle.getItemDetail` now always includes the `nbt` hash.
* Improvements to the display of errors in the shell and REPL.
* Turtles, pocket computers, and disks can be undyed by careful application (i.e. crafting) of a sponge.
* Turtles can no longer be dyed/undyed by right clicking.
New features in CC: Tweaked 1.103.1
Several bug fixes:
* Several documentation improvements and fixes (ouroborus, LelouBil)
* Fix rednet queueing the wrong message when sending a message to the current computer.
* Fix the Lua VM crashing when a `__len` metamethod yields.
* `pocket.{un,}equipBack` now correctly copies the stack when unequipping an upgrade.
* Fix `key` events not being queued while pressing computer shortcuts.
* Fix values not being printed in the REPL
* Fix `function f()` providing suboptimal parse errors in the REPL.
Type "help changelog" to see the full version history.

View File

@ -29,6 +29,7 @@ end
@param ... Arguments to this function.
@treturn[1] true If the function ran successfully.
@return[1] ... The return values of the function.
@treturn[2] false If the function failed.
@return[2] The error message
@ -38,17 +39,17 @@ local function try(func, ...)
expect(1, func, "function")
local co = coroutine.create(func)
local ok, result = coroutine.resume(co, ...)
local result = table.pack(coroutine.resume(co, ...))
while coroutine.status(co) ~= "dead" do
local event = table.pack(os.pullEventRaw(result))
if result == nil or event[1] == result or event[1] == "terminate" then
ok, result = coroutine.resume(co, table.unpack(event, 1, event.n))
local event = table.pack(os.pullEventRaw(result[2]))
if result[2] == nil or event[1] == result[2] or event[1] == "terminate" then
result = table.pack(coroutine.resume(co, table.unpack(event, 1, event.n)))
end
end
if not ok then return false, result, co end
return true
if not result[1] then return false, result[2], co end
return table.unpack(result, 1, result.n)
end
--[[- Report additional context about an error.

View File

@ -14,15 +14,9 @@ local lex_one = require "cc.internal.syntax.lexer".lex_one
local parser = require "cc.internal.syntax.parser"
local error_printer = require "cc.internal.error_printer"
local function parse(input, start_symbol)
expect(1, input, "string")
expect(2, start_symbol, "number")
-- Lazy-load the parser.
local parse, tokens, last_token = parser.parse, parser.tokens, parser.tokens.COMMENT
local error_sentinel = {}
local error_sentinel = {}
local function make_context(input)
local context = {}
local lines = { 1 }
@ -48,14 +42,13 @@ local function parse(input, start_symbol)
error("Position is <= 0", 2)
end
function context.report(msg)
expect(1, msg, "table")
error_printer(context, msg)
error(error_sentinel)
end
return context
end
local function make_lexer(input, context)
local tokens, last_token = parser.tokens, parser.tokens.COMMENT
local pos = 1
local ok, err = pcall(parse, context, function()
return function()
while true do
local token, start, finish = lex_one(context, input, pos)
if not token then return tokens.EOF, #input + 1, #input + 1 end
@ -68,7 +61,21 @@ local function parse(input, start_symbol)
error(error_sentinel)
end
end
end, start_symbol)
end
end
local function parse(input, start_symbol)
expect(1, input, "string")
expect(2, start_symbol, "number")
local context = make_context(input)
function context.report(msg)
expect(1, msg, "table")
error_printer(context, msg)
error(error_sentinel)
end
local ok, err = pcall(parser.parse, context, make_lexer(input, context), start_symbol)
if ok then
return true
@ -92,7 +99,55 @@ syntax errors to the terminal.
@tparam string input The string to parse.
@treturn boolean Whether the string was successfully parsed.
]]
local function parse_repl(input) return parse(input, parser.repl_exprs) end
local function parse_repl(input)
expect(1, input, "string")
local context = make_context(input)
local last_error = nil
function context.report(msg)
expect(1, msg, "table")
last_error = msg
error(error_sentinel)
end
local lexer = make_lexer(input, context)
local parsers = {}
for i, start_code in ipairs { parser.repl_exprs, parser.program } do
parsers[i] = coroutine.create(parser.parse)
assert(coroutine.resume(parsers[i], context, coroutine.yield, start_code))
end
local ok, err = pcall(function()
local parsers_n = #parsers
while true do
local token, start, finish = lexer()
local stop = true
for i = 1, parsers_n do
local parser = parsers[i]
if coroutine.status(parser) ~= "dead" then
stop = false
local ok, err = coroutine.resume(parser, token, start, finish)
if not ok and err ~= error_sentinel then error(err, 0) end
end
end
if stop then error(error_sentinel) end
end
end)
if ok then
return true
elseif err == error_sentinel then
error_printer(context, last_error)
return false
else
error(err, 0)
end
end
return {
parse_program = parse_program,

View File

@ -2,19 +2,6 @@
generate for each one. This is _not_ a complete collection of all possible
errors, but is a useful guide for where we might be providing terrible messages.
```lua {repl_exprs}
break until
-- Line 1: <eof> expected near 'until' (repl_exprs)
```
```txt
Unexpected until. Expected a statement.
|
1 | break until
| ^^^^^
```
```lua
break while
-- Line 1: unexpected symbol near <eof> (program)
@ -1257,16 +1244,15 @@ # while
```lua
repeat end
-- Line 1: 'until' expected near 'end' (program)
repeat --[[eof]]
-- Line 1: 'until' expected near <eof> (program)
```
```txt
Unexpected end.
Unexpected end of file. Expected a statement.
|
1 | repeat end
| ^^^
Your program contains more ends than needed. Check each block (if, for, function, ...) only has one end.
2 | -- Line 1: 'until' expected near <eof> (program)
| ^
```
@ -1375,14 +1361,14 @@ # while
```lua {repl_exprs}
until
-- Line 1: <eof> expected near 'until' (repl_exprs)
while
-- Line 1: unexpected symbol near 'while' (repl_exprs)
```
```txt
Unexpected until. Expected a statement.
Unexpected while.
|
1 | until
1 | while
| ^^^^^
```