From c448ee1248056889cd440fb16f196a75da2e1276 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Mon, 25 Sep 2023 20:13:34 -0400 Subject: [PATCH] Normative: Correctly capture a number negation prefix Fixes #44 --- spec.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spec.html b/spec.html index 6a0a69e..1b07905 100644 --- a/spec.html +++ b/spec.html @@ -258,14 +258,23 @@

1. Let _F_ be the active function object. 1. Assert: _F_ is a `JSON.parse` built-in function object (see JSON.parse). - 1. Let _types_ be « |NullLiteral|, |BooleanLiteral|, |NumericLiteral|, |StringLiteral|, |ArrayLiteral|, |ObjectLiteral| ». + 1. Let _types_ be « |NullLiteral|, |BooleanLiteral|, |NumericLiteral|, |StringLiteral|, |ArrayLiteral|, |ObjectLiteral|, |UnaryExpression| ». + 1. Let _unaryExpression_ be ~empty~. 1. Let _queue_ be « this Parse Node ». 1. Repeat, while _queue_ is not empty, 1. Let _candidate_ be the first element of _queue_. 1. Remove the first element from _queue_. 1. Let _queuedChildren_ be *false*. 1. For each nonterminal _type_ of _types_, do - 1. If _candidate_ is an instance of _type_, return _candidate_. + 1. If _candidate_ is an instance of _type_, then + 1. NOTE: In the JSON grammar, a number token may represent a negative value. In ECMAScript, negation is represented as a unary operation. + 1. If _type_ is |UnaryExpression|, then + 1. Set _unaryExpression_ to _candidate_. + 1. Else if _type_ is |NumericLiteral|, then + 1. Assert: _unaryExpression_ Contains _candidate_ is *true*. + 1. Return _unaryExpression_. + 1. Else, + 1. Return _candidate_. 1. If _queuedChildren_ is *false* and _candidate_ is an instance of a nonterminal and _candidate_ Contains _type_ is *true*, then 1. Let _children_ be a List containing each child node of _candidate_, in order. 1. Set _queue_ to the list-concatenation of _queue_ and _children_.