B.1 Additional Syntax

B.1.1 Numeric Literals

The syntax and semantics of 12.8.3 is extended as follows except that this extension is not allowed for strict mode code:

Syntax

NumericLiteral :: DecimalLiteral DecimalBigIntegerLiteral NonDecimalIntegerLiteral[+Sep] NonDecimalIntegerLiteral[+Sep] BigIntLiteralSuffix LegacyOctalIntegerLiteral LegacyOctalIntegerLiteral :: 0 OctalDigit LegacyOctalIntegerLiteral OctalDigit DecimalIntegerLiteral :: 0 NonZeroDigit NonZeroDigit NumericLiteralSeparatoropt DecimalDigits[+Sep] NonOctalDecimalIntegerLiteral NonOctalDecimalIntegerLiteral :: 0 NonOctalDigit LegacyOctalLikeDecimalIntegerLiteral NonOctalDigit NonOctalDecimalIntegerLiteral DecimalDigit LegacyOctalLikeDecimalIntegerLiteral :: 0 OctalDigit LegacyOctalLikeDecimalIntegerLiteral OctalDigit NonOctalDigit :: one of 8 9

B.1.1.1 Static Semantics

B.1.2 String Literals

The syntax and semantics of 12.8.4 is extended as follows except that this extension is not allowed for strict mode code:

Syntax

EscapeSequence :: CharacterEscapeSequence LegacyOctalEscapeSequence NonOctalDecimalEscapeSequence HexEscapeSequence UnicodeEscapeSequence LegacyOctalEscapeSequence :: OctalDigit [lookahead ∉ OctalDigit] ZeroToThree OctalDigit [lookahead ∉ OctalDigit] FourToSeven OctalDigit ZeroToThree OctalDigit OctalDigit ZeroToThree :: one of 0 1 2 3 FourToSeven :: one of 4 5 6 7 NonOctalDecimalEscapeSequence :: one of 8 9

This definition of EscapeSequence is not used in strict mode or when parsing TemplateCharacter.

Note

It is possible for string literals to precede a Use Strict Directive that places the enclosing code in strict mode, and implementations must take care to not use this extended definition of EscapeSequence with such literals. For example, attempting to parse the following source text must fail:

function invalid() { "\7"; "use strict"; }

B.1.2.1 Static Semantics

B.1.3 HTML-like Comments

The syntax and semantics of 12.4 is extended as follows except that this extension is not allowed when parsing source code using the goal symbol Module:

Syntax

Comment :: MultiLineComment SingleLineComment SingleLineHTMLOpenComment SingleLineHTMLCloseComment SingleLineDelimitedComment MultiLineComment :: /* FirstCommentLineopt LineTerminator MultiLineCommentCharsopt */ HTMLCloseCommentopt FirstCommentLine :: SingleLineDelimitedCommentChars SingleLineHTMLOpenComment :: <!-- SingleLineCommentCharsopt SingleLineHTMLCloseComment :: LineTerminatorSequence HTMLCloseComment SingleLineDelimitedComment :: /* SingleLineDelimitedCommentCharsopt */ HTMLCloseComment :: WhiteSpaceSequenceopt SingleLineDelimitedCommentSequenceopt --> SingleLineCommentCharsopt SingleLineDelimitedCommentChars :: SingleLineNotAsteriskChar SingleLineDelimitedCommentCharsopt * SingleLinePostAsteriskCommentCharsopt SingleLineNotAsteriskChar :: SourceCharacter but not one of * or LineTerminator SingleLinePostAsteriskCommentChars :: SingleLineNotForwardSlashOrAsteriskChar SingleLineDelimitedCommentCharsopt * SingleLinePostAsteriskCommentCharsopt SingleLineNotForwardSlashOrAsteriskChar :: SourceCharacter but not one of / or * or LineTerminator WhiteSpaceSequence :: WhiteSpace WhiteSpaceSequenceopt SingleLineDelimitedCommentSequence :: SingleLineDelimitedComment WhiteSpaceSequenceopt SingleLineDelimitedCommentSequenceopt

Similar to a MultiLineComment that contains a line terminator code point, a SingleLineHTMLCloseComment is considered to be a LineTerminator for purposes of parsing by the syntactic grammar.

B.1.4 Regular Expressions Patterns

The syntax of 22.2.1 is modified and extended as follows. These changes introduce ambiguities that are broken by the ordering of grammar productions and by contextual information. When parsing using the following grammar, each alternative is considered only if previous production alternatives do not match.

This alternative pattern grammar and semantics only changes the syntax and semantics of BMP patterns. The following grammar extensions include productions parameterized with the [U] parameter. However, none of these extensions change the syntax of Unicode patterns recognized when parsing with the [U] parameter present on the goal symbol.

Syntax

Term[U, N] :: [+U]Assertion[+U, ?N] [+U] Atom[+U, ?N] Quantifier [+U]Atom[+U, ?N] [~U] QuantifiableAssertion[?N] Quantifier [~U]Assertion[~U, ?N] [~U] ExtendedAtom[?N] Quantifier [~U]ExtendedAtom[?N] Assertion[U, N] :: ^ $ \ b \ B [+U] ( ? = Disjunction[+U, ?N] ) [+U] ( ? ! Disjunction[+U, ?N] ) [~U]QuantifiableAssertion[?N] ( ? <= Disjunction[?U, ?N] ) ( ? <! Disjunction[?U, ?N] ) QuantifiableAssertion[N] :: ( ? = Disjunction[~U, ?N] ) ( ? ! Disjunction[~U, ?N] ) ExtendedAtom[N] :: . \ AtomEscape[~U, ?N] \ [lookahead = c] CharacterClass[~U] ( Disjunction[~U, ?N] ) ( ? : Disjunction[~U, ?N] ) InvalidBracedQuantifier ExtendedPatternCharacter InvalidBracedQuantifier :: { DecimalDigits[~Sep] } { DecimalDigits[~Sep] , } { DecimalDigits[~Sep] , DecimalDigits[~Sep] } ExtendedPatternCharacter :: SourceCharacter but not one of ^ $ \ . * + ? ( ) [ | AtomEscape[U, N] :: [+U]DecimalEscape [~U] DecimalEscape but only if the CapturingGroupNumber of DecimalEscape is ≤ NcapturingParens CharacterClassEscape[?U] CharacterEscape[?U, ?N] [+N] k GroupName[?U] CharacterEscape[U, N] :: ControlEscape c ControlLetter 0 [lookahead ∉ DecimalDigit] HexEscapeSequence RegExpUnicodeEscapeSequence[?U] [~U]LegacyOctalEscapeSequence IdentityEscape[?U, ?N] IdentityEscape[U, N] :: [+U]SyntaxCharacter [+U]/ [~U]SourceCharacterIdentityEscape[?N] SourceCharacterIdentityEscape[N] :: [~N]SourceCharacter but not c [+N]SourceCharacter but not one of c or k ClassAtomNoDash[U, N] :: SourceCharacter but not one of \ or ] or - \ ClassEscape[?U, ?N] \ [lookahead = c] ClassEscape[U, N] :: b [+U]- [~U] c ClassControlLetter CharacterClassEscape[?U] CharacterEscape[?U, ?N] ClassControlLetter :: DecimalDigit _ Note

When the same left hand sides occurs with both [+U] and [~U] guards it is to control the disambiguation priority.

B.1.4.1 Static Semantics: Early Errors

The semantics of 22.2.1.1 is extended as follows:

ExtendedAtom :: InvalidBracedQuantifier
  • It is a Syntax Error if any source text matches this rule.

Additionally, the rules for the following productions are modified with the addition of the highlighted text:

NonemptyClassRanges :: ClassAtom - ClassAtom ClassRanges NonemptyClassRangesNoDash :: ClassAtomNoDash - ClassAtom ClassRanges

B.1.4.2 Static Semantics: IsCharacterClass

The semantics of 22.2.1.3 is extended as follows:

ClassAtomNoDash :: \ [lookahead = c]
  1. Return false.

B.1.4.3 Static Semantics: CharacterValue

The semantics of 22.2.1.4 is extended as follows:

ClassAtomNoDash :: \ [lookahead = c]
  1. Return the code point value of U+005C (REVERSE SOLIDUS).
ClassEscape :: c ClassControlLetter
  1. Let ch be the code point matched by ClassControlLetter.
  2. Let i be ch's code point value.
  3. Return the remainder of dividing i by 32.
CharacterEscape :: LegacyOctalEscapeSequence
  1. Return the MV of LegacyOctalEscapeSequence (see B.1.2).

B.1.4.4 Pattern Semantics

The semantics of 22.2.2 is extended as follows:

Within 22.2.2.5 reference to “ Atom :: ( GroupSpecifier Disjunction ) ” are to be interpreted as meaning “ Atom :: ( GroupSpecifier Disjunction ) ” or “ ExtendedAtom :: ( Disjunction ) ”.

Term (22.2.2.5) includes the following additional evaluation rules:

The production Term :: QuantifiableAssertion Quantifier evaluates the same as the production Term :: Atom Quantifier but with QuantifiableAssertion substituted for Atom.

The production Term :: ExtendedAtom Quantifier evaluates the same as the production Term :: Atom Quantifier but with ExtendedAtom substituted for Atom.

The production Term :: ExtendedAtom evaluates the same as the production Term :: Atom but with ExtendedAtom substituted for Atom.

Assertion (22.2.2.6) includes the following additional evaluation rule:

The production Assertion :: QuantifiableAssertion evaluates as follows:

  1. Evaluate QuantifiableAssertion to obtain a Matcher m.
  2. Return m.

Assertion (22.2.2.6) evaluation rules for the Assertion :: ( ? = Disjunction ) and Assertion :: ( ? ! Disjunction ) productions are also used for the QuantifiableAssertion productions, but with QuantifiableAssertion substituted for Assertion.

Atom (22.2.2.8) evaluation rules for the Atom productions except for Atom :: PatternCharacter are also used for the ExtendedAtom productions, but with ExtendedAtom substituted for Atom. The following evaluation rules, with parameter direction, are also added:

The production ExtendedAtom :: \ [lookahead = c] evaluates as follows:

  1. Let A be the CharSet containing the single character \ U+005C (REVERSE SOLIDUS).
  2. Return ! CharacterSetMatcher(A, false, direction).

The production ExtendedAtom :: ExtendedPatternCharacter evaluates as follows:

  1. Let ch be the character represented by ExtendedPatternCharacter.
  2. Let A be a one-element CharSet containing the character ch.
  3. Return ! CharacterSetMatcher(A, false, direction).

CharacterEscape (22.2.2.10) includes the following additional evaluation rule:

The production CharacterEscape :: LegacyOctalEscapeSequence evaluates as follows:

  1. Let cv be the CharacterValue of this CharacterEscape.
  2. Return the character whose character value is cv.

NonemptyClassRanges (22.2.2.15) modifies the following evaluation rule:

The production NonemptyClassRanges :: ClassAtom - ClassAtom ClassRanges evaluates as follows:

  1. Evaluate the first ClassAtom to obtain a CharSet A.
  2. Evaluate the second ClassAtom to obtain a CharSet B.
  3. Evaluate ClassRanges to obtain a CharSet C.
  4. Let D be ! CharacterRangeOrUnion(A, B).
  5. Return the union of D and C.

NonemptyClassRangesNoDash (22.2.2.16) modifies the following evaluation rule:

The production NonemptyClassRangesNoDash :: ClassAtomNoDash - ClassAtom ClassRanges evaluates as follows:

  1. Evaluate ClassAtomNoDash to obtain a CharSet A.
  2. Evaluate ClassAtom to obtain a CharSet B.
  3. Evaluate ClassRanges to obtain a CharSet C.
  4. Let D be ! CharacterRangeOrUnion(A, B).
  5. Return the union of D and C.

ClassEscape (22.2.2.19) includes the following additional evaluation rule:

The production ClassEscape :: c ClassControlLetter evaluates as follows:

  1. Let cv be the CharacterValue of this ClassEscape.
  2. Let c be the character whose character value is cv.
  3. Return the CharSet containing the single character c.

ClassAtomNoDash (22.2.2.18) includes the following additional evaluation rule:

The production ClassAtomNoDash :: \ [lookahead = c] evaluates as follows:

  1. Return the CharSet containing the single character \ U+005C (REVERSE SOLIDUS).
Note
This production can only be reached from the sequence \c within a character class where it is not followed by an acceptable control character.

B.1.4.4.1 CharacterRangeOrUnion ( A, B )

The abstract operation CharacterRangeOrUnion takes arguments A (a CharSet) and B (a CharSet). It performs the following steps when called:

  1. If Unicode is false, then
    1. If A does not contain exactly one character or B does not contain exactly one character, then
      1. Let C be the CharSet containing the single character - U+002D (HYPHEN-MINUS).
      2. Return the union of CharSets A, B and C.
  2. Return ! CharacterRange(A, B).