rksm / paredit.js

Generic reader and editor for s-expressions.
MIT License
107 stars 21 forks source link

Create Error if a String Ends Without a Closing Quote #21

Closed neil-lindquist closed 5 years ago

neil-lindquist commented 5 years ago

Currently, if a string doesn't have a closing quote, doesn't create any errors. sjlevine/atom-slime#81 uses paredit errors to detect when a line is incomplete, so this would allow it to behave correctly when a user is typing just a string (its a corner case, since most of the time there will be a missing closing paren as the string goes until eof). The fix checks whether the next character is an double quote (instead of assuming it is and discarding it) and, if it isn't, an error is created instead of a string.

For example calling parse with just the string ", paredit produces (when output in chromimum dev tools) image This PR modifies paredit to provide an error instead: image

I couldn't get the tests running on my machine, so there isn't any change to the test suite. If you want a test in the suite, the following should work:

it("unmatched string quote", function() {
  var actual = readSeq('"a'),
      expected = [
        "a",
        {error: "Expected '\"' but reached end of input at line 1 column 2"}]
  console.log(diff(actual,expected));
  expect(actual).to.containSubset(expected);
});
rksm commented 5 years ago

Thank you!