goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

Goby stops responding when quotation marks are not paired #137

Closed hachi8833 closed 7 years ago

hachi8833 commented 7 years ago

Happened to find that the following code makes Goby stop responding:

a = "abcxyz
puts(a)

Just to create the test code for the error cases:

func TestStringErrorCase(t *testing.T) {
    tests := []struct {
        input    string
        expected interface{}
    }{
        {`"abc`, `unterminated string meets end of file`},
        {`'abc`, `unterminated string meets end of file`},
        {`abc"`, `unterminated string meets end of file`},
        {`abc'`, `unterminated string meets end of file`},
    }

    for _, tt := range tests {
        evaluated := testEval(t, tt.input)
        if !isError(evaluated) {
            t.Fatalf("Should return an error for %s", tt.input)
        }

        if evaluated.(*Error).Message != tt.expected {
            t.Fatalf("Error message should be '%s'\n result %s", tt.expected, evaluated)
        }

    }
}
st0012 commented 7 years ago

This will be fixed after we introduce finite state machine in #131

st0012 commented 7 years ago

@hachi8833 I just fixed this in a very naive way, see https://github.com/goby-lang/goby/commit/3204bce2ab429d4c3e2e0570fc700289f6313ce4. And actually this can't be tested since this issue should be reported when lexing, and currently lexer doesn't have any error report mechanism so I can only use panic.

st0012 commented 7 years ago

I'm going to close this one because the requirement for lexer's error report is another new issue.