What is the difference between: and :: and ::: in Javascript grammar

advertisements

In the ECMAScript grammar specification for Javascript, there are blocks defined with a double colon like this:

Literal ::
    NullLiteral
    BooleanLiteral
    NumericLiteral
    StringLiteral
    RegularExpressionLiteral

And blocks defined with a single colon like this:

PrimaryExpression :
    this
    Identifier
    Literal
    ArrayLiteral
    ObjectLiteral
    ( Expression )

And, even blocks with a triple colon:

uriCharacter :::
    uriReserved
    uriUnescaped
    uriEscaped

What is the difference between the single and double and triple colons?


The JSON lexical grammar is used to translate character sequences into tokens and is similar to parts of the ECMAScript lexical grammar. The JSON syntactic grammar describes how sequences of tokens from the JSON lexical grammar can form syntactically correct JSON object descriptions.

Lexical rules ("::") for tokens mean "what the parts of the language look like". It defines rules like "5.5 is a number".

Syntactic rules (":") for expressions mean "how the parts interact with eachother". It defines rules like "5.5 abc doesn't make sense".

The triple-colon (":::") seems to be reserved specifically to define rules for converting strings to numbers. The string " 0x1235 " (with whitespace) is a valid number. The triple-colon rules define that.

The triple-colon (":::") also seems to be used for uri string grammar. Most commonly used like this: "f%20o%20o" decodes to "f o o". These rules define the structure of the "numerical" part of the strings.