Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • That is a great articulation of the merits that method and one that I would say I'm inclined toward. I guess where I've been butting against a problem is where I try in the first pass to identify where an escape sequence appears valid, yet would resolve to an error/warning (in order to bind the error/warning to its location in the source). Using JSON again as an example: ["\uD800"] In order to catch that in the first pass, I'd run the same resolution code as in the second thereby repeating what could potentially be a costly process. Commented Sep 10, 2017 at 20:14
  • @rgchris Handling surrogate pairs is the most difficult part of JSON. It would be feasible to handle Unicode in a second pass after escape processing, though as you've noted that makes good error messages difficult. Alternatively, you can check whether an escape is part of a surrogate pair, then expect (as part of your grammar) that it must be followed immediately by the second part of the pair, as another \uXXXX escape. Everything else can be treated as a syntax error. Commented Sep 10, 2017 at 21:15