Skip to content

Conversation

@Syuparn
Copy link
Owner

@Syuparn Syuparn commented Feb 21, 2021

Background

REPL should output the evaluated value of the latest input.
But tmplscript REPL required the whole input since interactive mode starts so that it can refer pre-defined variables.
For that reason, it read whole input and put only the output difference with the previous one (outStr[previousOutLen:]).

Problem

When non-idempotent functions are used, output length differs in each evaluation.
Diff algorithm above works wrongly and sometimes causes index out of range.

tmpl:12> {{range until (randInt 1 10)}}{{println .}}{{end}}
7
8

0

0
1
2
3
4
5
6

tmpl:13> {{range until (randInt 1 10)}}{{println .}}{{end}}
panic: runtime error: slice bounds out of range [156:155]

goroutine 1 [running]:
main.runREPLMode(0xc00003e5c0)
        C:/Users/tanot/OneDrive/Documents/tmplscript/main.go:107 +0x53d
main.main()
        C:/Users/tanot/OneDrive/Documents/tmplscript/main.go:26 +0x437

Solution

Instead, separation character is introduced to detect output diff.
It inserts non-printable character "\x034" before parsing and shows output only after "\x034".

@Syuparn Syuparn merged commit 6cf24d2 into main Feb 21, 2021
@Syuparn Syuparn deleted the fix-diff-logic branch February 21, 2021 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants