Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

122 - Fix swallowline #123

Merged
merged 2 commits into from
Dec 16, 2023
Merged

122 - Fix swallowline #123

merged 2 commits into from
Dec 16, 2023

Conversation

skx
Copy link
Owner

@skx skx commented Dec 16, 2023

It was reported that the following program fails, due to issues with swallowing newlines:

REM This is a comment
PRINT "OK"

This comes about because the swallowLine implementation we have consumes the newline it uses to stop its search, however the interpreter then goes on to increment the line:

func (e *Interpreter) RunOnce() error {
  ..

case token.REM:
	err = e.swallowLine()
    case token.RETURN:
            ...

  ..

//
// Ready for the next instruction
//
e.offset++

//
// Error?
//
if err != nil {
	return err
}
return nil

As an easy fix for the moment I've updated the swallowLine implementation to actually return with the current token being the newline, not the one after that:

  • The interpreter will already silently NOP an inline newline.
  • This shouldn't break the IF/THEN/ELSE code.

A similar solution would have been to add a break after the token.REM handler, but special-casing that felt wrong.

This closes #122.

It was reported that the following program fails, due to issues
with swallowing newlines:

```
REM This is a comment
PRINT "OK"
```

This comes about because the `swallowLine` implementation we have
consumes the newline it uses to stop its search, however the interpreter
then goes on to increment the line:

    func (e *Interpreter) RunOnce() error {
      ..
	case token.REM:
		err = e.swallowLine()
        case ..

      ..

	//
	// Ready for the next instruction
	//
	e.offset++

	//
	// Error?
	//
	if err != nil {
		return err
	}
	return nil

As an easy fix for the moment I've updated the swallowLine
implementation to actually return with the current token being
the newline, not the one after that:

* The interpreter will already silently NOP an inline newline.
* This shouldn't break the IF/THEN/ELSE code.

A similar solution would have been to add a break after the
token.REM handler, but special-casing that felt wrong.

This closes #122.
@skx skx merged commit c825bcb into master Dec 16, 2023
1 check passed
@skx skx deleted the 122-newline branch December 16, 2023 03:46
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.

swallowline results in a bypass of next token
1 participant