Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

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.

skx added 2 commits December 16, 2023 05:31
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
@skx skx deleted the 122-newline branch December 16, 2023 03:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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