JSON parser grammar

John Cowan cowan at ccil.org
Fri Jun 5 15:22:07 PDT 2009


David-Sarah Hopwood scripsit:

> var escapable =
> /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g

Just to spell these out, they mean:

C0 control characters, including DEL
C1 control characters
SOFT HYPHEN
ARABIC NUMBER SIGN
ARABIC SIGN SANAH
ARABIC FOOTNOTE MARKER
ARABIC SIGN SAFHA
(unassigned U+0604)
SYRIAC ABBREVIATION MARK
KHMER VOWEL INHERENT AQ
KHMER VOWEL INHERENT AA
ZERO WIDTH NON-JOINER
ZERO WIDTH JOINER
LEFT-TO-RIGHT MARK
RIGHT-TO-LEFT MARK
LINE SEPARATOR
PARAGRAPH SEPARATOR
LEFT-TO-RIGHT EMBEDDING
RIGHT-TO-LEFT EMBEDDING
POP DIRECTIONAL FORMATTING
LEFT-TO-RIGHT OVERRIDE
RIGHT-TO-LEFT OVERRIDE
NARROW NO-BREAK SPACE
WORD JOINER
FUNCTION APPLICATION
INVISIBLE TIMES
INVISIBLE SEPARATOR
INVISIBLE PLUS
INHIBIT SYMMETRIC SWAPPING
ACTIVATE SYMMETRIC SWAPPING
INHIBIT ARABIC FORM SHAPING
ACTIVATE ARABIC FORM SHAPING
NATIONAL DIGIT SHAPES
NOMINAL DIGIT SHAPES
ZERO WIDTH NO-BREAK SPACE
(unassigned specials FFF0-FFF8)
INTERLINEAR ANNOTATION ANCHOR
INTERLINEAR ANNOTATION SEPARATOR
INTERLINEAR ANNOTATION TERMINATOR
OBJECT REPLACEMENT CHARACTER
REPLACEMENT CHARACTER
(permanently reserved reversed-BOM FFFE)
(permanently reserved sentinel FFFF)

> Incidentally, the format-control characters \u06FF and \u200B and the
> the noncharacters \uFDD0..FDEF should probably be added to the above
> set of escapable characters.

Agree on U+200B and the non-characters.  U+06FF is a letter,
ARABIC LETTER HEH WITH INVERTED V; I assume you don't mean that one.

> (The surrogate codes should not be added,
> since JSON is not tied to UTF-16.)

Presumably, ES5 strings with unpaired surrogates cannot be JSONized, since
unpaired surrogates don't represent Unicode characters.

> Note that \u0604 is unassigned, and
> probably doesn't need to be in this set.

+1

-- 
Is not a patron, my Lord [Chesterfield],        John Cowan
one who looks with unconcern on a man           http://www.ccil.org/~cowan
struggling for life in the water, and when      cowan at ccil.org
he has reached ground encumbers him with help?
        --Samuel Johnson


More information about the es5-discuss mailing list