Skip to content

Commit

Permalink
[giowt] (0) Simplification in the microsyntax parsing rules, which ma…
Browse files Browse the repository at this point in the history
…kes non-negative integers accept leading - and + characters (- only for -0 of course).

Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=14234

git-svn-id: http://svn.whatwg.org/webapps@6717 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Oct 20, 2011
1 parent abc0fb8 commit ec18727
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 178 deletions.
97 changes: 40 additions & 57 deletions complete.html
Expand Up @@ -324,8 +324,8 @@ <h2 class="no-num no-toc">Living Standard &mdash; Last Updated 20 October 2011</
<li><a href=#keywords-and-enumerated-attributes><span class=secno>2.5.3 </span>Keywords and enumerated attributes</a></li>
<li><a href=#numbers><span class=secno>2.5.4 </span>Numbers</a>
<ol>
<li><a href=#non-negative-integers><span class=secno>2.5.4.1 </span>Non-negative integers</a></li>
<li><a href=#signed-integers><span class=secno>2.5.4.2 </span>Signed integers</a></li>
<li><a href=#signed-integers><span class=secno>2.5.4.1 </span>Signed integers</a></li>
<li><a href=#non-negative-integers><span class=secno>2.5.4.2 </span>Non-negative integers</a></li>
<li><a href=#floating-point-numbers><span class=secno>2.5.4.3 </span>Floating-point numbers</a></li>
<li><a href=#percentages-and-dimensions><span class=secno>2.5.4.4 </span>Percentages and lengths</a></li>
<li><a href=#lists-of-integers><span class=secno>2.5.4.5 </span>Lists of integers</a></li>
Expand Down Expand Up @@ -4618,56 +4618,7 @@ <h4 id=keywords-and-enumerated-attributes><span class=secno>2.5.3 </span>Keyword

<h4 id=numbers><span class=secno>2.5.4 </span>Numbers</h4>

<h5 id=non-negative-integers><span class=secno>2.5.4.1 </span>Non-negative integers</h5>

<p>A string is a <dfn id=valid-non-negative-integer>valid non-negative integer</dfn> if it
consists of one or more characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9).</p>

<p>A <a href=#valid-non-negative-integer>valid non-negative integer</a> represents the number
that is represented in base ten by that string of digits.</p>

<div class=impl>

<p>The <dfn id=rules-for-parsing-non-negative-integers>rules for parsing non-negative integers</dfn> are as
given in the following algorithm. When invoked, the steps must be
followed in the order given, aborting at the first step that returns
a value. This algorithm will return either zero, a positive integer,
or an error.</p>

<ol><li><p>Let <var title="">input</var> be the string being
parsed.</li>

<li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>, initially pointing at the start of the
string.</li>

<li><p><a href=#skip-whitespace>Skip whitespace</a>.</li>

<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, return an error.</li>

<li><p>If the character indicated by <var title="">position</var>
is a U+002B PLUS SIGN character (+), advance <var title="">position</var> to the next character. (The "<code title="">+</code>" is ignored, but it is not conforming.)</li>

<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, return an error.</li>

<li><p>If the character indicated by <var title="">position</var>
is not one of U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then
return an error.</li>

<!-- Ok. At this point we know we have a number. It might have
trailing garbage which we'll ignore, but it's a number, and we
won't return an error. -->

<li><p><a href=#collect-a-sequence-of-characters>Collect a sequence of characters</a> in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), and interpret the
resulting sequence as a base-ten integer. Let <var title="">value</var> be that integer.</li>

<li><p>Return <var title="">value</var>.</li>

</ol></div>


<h5 id=signed-integers><span class=secno>2.5.4.2 </span>Signed integers</h5>
<h5 id=signed-integers><span class=secno>2.5.4.1 </span>Signed integers</h5>

<p>A string is a <dfn id=valid-integer>valid integer</dfn> if it consists of one or
more characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
Expand All @@ -4683,11 +4634,9 @@ <h5 id=signed-integers><span class=secno>2.5.4.2 </span>Signed integers</h5>

<div class=impl>

<p>The <dfn id=rules-for-parsing-integers>rules for parsing integers</dfn> are similar to the
<a href=#rules-for-parsing-non-negative-integers title="rules for parsing non-negative integers">rules for
non-negative integers</a>, and are as given in the following
algorithm. When invoked, the steps must be followed in the order
given, aborting at the first step that returns a value. This
<p>The <dfn id=rules-for-parsing-integers>rules for parsing integers</dfn> are as given in the
following algorithm. When invoked, the steps must be followed in the
order given, aborting at the first step that returns a value. This
algorithm will return either an integer or an error.</p>

<ol><li><p>Let <var title="">input</var> be the string being
Expand Down Expand Up @@ -4744,6 +4693,40 @@ <h5 id=signed-integers><span class=secno>2.5.4.2 </span>Signed integers</h5>
</ol></div>


<h5 id=non-negative-integers><span class=secno>2.5.4.2 </span>Non-negative integers</h5>

<p>A string is a <dfn id=valid-non-negative-integer>valid non-negative integer</dfn> if it
consists of one or more characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9).</p>

<p>A <a href=#valid-non-negative-integer>valid non-negative integer</a> represents the number
that is represented in base ten by that string of digits.</p>

<div class=impl>

<p>The <dfn id=rules-for-parsing-non-negative-integers>rules for parsing non-negative integers</dfn> are as
given in the following algorithm. When invoked, the steps must be
followed in the order given, aborting at the first step that returns
a value. This algorithm will return either zero, a positive integer,
or an error.</p>

<ol><li><p>Let <var title="">input</var> be the string being
parsed.</li>

<li><p>Let <var title="">value</var> be the result of parsing <var title="">input</var> using the <a href=#rules-for-parsing-integers>rules for parsing
integers</a>.</li>

<li><p>If <var title="">value</var> is an error, return an
error.</li>

<li><p>If <var title="">value</var> is less than zero, return an
error.</li>

<li><p>Return <var title="">value</var>.</li>

</ol><!-- Implications: A leading + is ignored. A leading - is ignored if the value is zero. --></div>


<h5 id=floating-point-numbers><span class=secno>2.5.4.3 </span>Floating-point numbers</h5>

<p>A string is a <dfn id=valid-floating-point-number>valid floating point number</dfn> if it
Expand Down
97 changes: 40 additions & 57 deletions index
Expand Up @@ -324,8 +324,8 @@
<li><a href=#keywords-and-enumerated-attributes><span class=secno>2.5.3 </span>Keywords and enumerated attributes</a></li>
<li><a href=#numbers><span class=secno>2.5.4 </span>Numbers</a>
<ol>
<li><a href=#non-negative-integers><span class=secno>2.5.4.1 </span>Non-negative integers</a></li>
<li><a href=#signed-integers><span class=secno>2.5.4.2 </span>Signed integers</a></li>
<li><a href=#signed-integers><span class=secno>2.5.4.1 </span>Signed integers</a></li>
<li><a href=#non-negative-integers><span class=secno>2.5.4.2 </span>Non-negative integers</a></li>
<li><a href=#floating-point-numbers><span class=secno>2.5.4.3 </span>Floating-point numbers</a></li>
<li><a href=#percentages-and-dimensions><span class=secno>2.5.4.4 </span>Percentages and lengths</a></li>
<li><a href=#lists-of-integers><span class=secno>2.5.4.5 </span>Lists of integers</a></li>
Expand Down Expand Up @@ -4618,56 +4618,7 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d

<h4 id=numbers><span class=secno>2.5.4 </span>Numbers</h4>

<h5 id=non-negative-integers><span class=secno>2.5.4.1 </span>Non-negative integers</h5>

<p>A string is a <dfn id=valid-non-negative-integer>valid non-negative integer</dfn> if it
consists of one or more characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9).</p>

<p>A <a href=#valid-non-negative-integer>valid non-negative integer</a> represents the number
that is represented in base ten by that string of digits.</p>

<div class=impl>

<p>The <dfn id=rules-for-parsing-non-negative-integers>rules for parsing non-negative integers</dfn> are as
given in the following algorithm. When invoked, the steps must be
followed in the order given, aborting at the first step that returns
a value. This algorithm will return either zero, a positive integer,
or an error.</p>

<ol><li><p>Let <var title="">input</var> be the string being
parsed.</li>

<li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>, initially pointing at the start of the
string.</li>

<li><p><a href=#skip-whitespace>Skip whitespace</a>.</li>

<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, return an error.</li>

<li><p>If the character indicated by <var title="">position</var>
is a U+002B PLUS SIGN character (+), advance <var title="">position</var> to the next character. (The "<code title="">+</code>" is ignored, but it is not conforming.)</li>

<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, return an error.</li>

<li><p>If the character indicated by <var title="">position</var>
is not one of U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then
return an error.</li>

<!-- Ok. At this point we know we have a number. It might have
trailing garbage which we'll ignore, but it's a number, and we
won't return an error. -->

<li><p><a href=#collect-a-sequence-of-characters>Collect a sequence of characters</a> in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), and interpret the
resulting sequence as a base-ten integer. Let <var title="">value</var> be that integer.</li>

<li><p>Return <var title="">value</var>.</li>

</ol></div>


<h5 id=signed-integers><span class=secno>2.5.4.2 </span>Signed integers</h5>
<h5 id=signed-integers><span class=secno>2.5.4.1 </span>Signed integers</h5>

<p>A string is a <dfn id=valid-integer>valid integer</dfn> if it consists of one or
more characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT
Expand All @@ -4683,11 +4634,9 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d

<div class=impl>

<p>The <dfn id=rules-for-parsing-integers>rules for parsing integers</dfn> are similar to the
<a href=#rules-for-parsing-non-negative-integers title="rules for parsing non-negative integers">rules for
non-negative integers</a>, and are as given in the following
algorithm. When invoked, the steps must be followed in the order
given, aborting at the first step that returns a value. This
<p>The <dfn id=rules-for-parsing-integers>rules for parsing integers</dfn> are as given in the
following algorithm. When invoked, the steps must be followed in the
order given, aborting at the first step that returns a value. This
algorithm will return either an integer or an error.</p>

<ol><li><p>Let <var title="">input</var> be the string being
Expand Down Expand Up @@ -4744,6 +4693,40 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
</ol></div>


<h5 id=non-negative-integers><span class=secno>2.5.4.2 </span>Non-negative integers</h5>

<p>A string is a <dfn id=valid-non-negative-integer>valid non-negative integer</dfn> if it
consists of one or more characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9).</p>

<p>A <a href=#valid-non-negative-integer>valid non-negative integer</a> represents the number
that is represented in base ten by that string of digits.</p>

<div class=impl>

<p>The <dfn id=rules-for-parsing-non-negative-integers>rules for parsing non-negative integers</dfn> are as
given in the following algorithm. When invoked, the steps must be
followed in the order given, aborting at the first step that returns
a value. This algorithm will return either zero, a positive integer,
or an error.</p>

<ol><li><p>Let <var title="">input</var> be the string being
parsed.</li>

<li><p>Let <var title="">value</var> be the result of parsing <var title="">input</var> using the <a href=#rules-for-parsing-integers>rules for parsing
integers</a>.</li>

<li><p>If <var title="">value</var> is an error, return an
error.</li>

<li><p>If <var title="">value</var> is less than zero, return an
error.</li>

<li><p>Return <var title="">value</var>.</li>

</ol><!-- Implications: A leading + is ignored. A leading - is ignored if the value is zero. --></div>


<h5 id=floating-point-numbers><span class=secno>2.5.4.3 </span>Floating-point numbers</h5>

<p>A string is a <dfn id=valid-floating-point-number>valid floating point number</dfn> if it
Expand Down
108 changes: 44 additions & 64 deletions source
Expand Up @@ -3703,65 +3703,6 @@ is conforming depends on which specs apply, and leaves it at that. -->

<h4>Numbers</h4>

<h5>Non-negative integers</h5>

<p>A string is a <dfn>valid non-negative integer</dfn> if it
consists of one or more characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9).</p>

<p>A <span>valid non-negative integer</span> represents the number
that is represented in base ten by that string of digits.</p>

<div class="impl">

<p>The <dfn>rules for parsing non-negative integers</dfn> are as
given in the following algorithm. When invoked, the steps must be
followed in the order given, aborting at the first step that returns
a value. This algorithm will return either zero, a positive integer,
or an error.</p>

<ol>

<li><p>Let <var title="">input</var> be the string being
parsed.</p></li>

<li><p>Let <var title="">position</var> be a pointer into <var
title="">input</var>, initially pointing at the start of the
string.</p></li>

<li><p><span>Skip whitespace</span>.</p></li>

<li><p>If <var title="">position</var> is past the end of <var
title="">input</var>, return an error.</p></li>

<li><p>If the character indicated by <var title="">position</var>
is a U+002B PLUS SIGN character (+), advance <var
title="">position</var> to the next character. (The "<code
title="">+</code>" is ignored, but it is not conforming.)</li>

<li><p>If <var title="">position</var> is past the end of <var
title="">input</var>, return an error.</p></li>

<li><p>If the character indicated by <var title="">position</var>
is not one of U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then
return an error.</p></li>

<!-- Ok. At this point we know we have a number. It might have
trailing garbage which we'll ignore, but it's a number, and we
won't return an error. -->

<li><p><span>Collect a sequence of characters</span> in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), and interpret the
resulting sequence as a base-ten integer. Let <var
title="">value</var> be that integer.</p></li>

<li><p>Return <var title="">value</var>.</p></li>

</ol>

</div>


<h5>Signed integers</h5>

<p>A string is a <dfn>valid integer</dfn> if it consists of one or
Expand All @@ -3778,11 +3719,9 @@ is conforming depends on which specs apply, and leaves it at that. -->

<div class="impl">

<p>The <dfn>rules for parsing integers</dfn> are similar to the
<span title="rules for parsing non-negative integers">rules for
non-negative integers</span>, and are as given in the following
algorithm. When invoked, the steps must be followed in the order
given, aborting at the first step that returns a value. This
<p>The <dfn>rules for parsing integers</dfn> are as given in the
following algorithm. When invoked, the steps must be followed in the
order given, aborting at the first step that returns a value. This
algorithm will return either an integer or an error.</p>

<ol>
Expand Down Expand Up @@ -3858,6 +3797,47 @@ is conforming depends on which specs apply, and leaves it at that. -->
</div>


<h5>Non-negative integers</h5>

<p>A string is a <dfn>valid non-negative integer</dfn> if it
consists of one or more characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9).</p>

<p>A <span>valid non-negative integer</span> represents the number
that is represented in base ten by that string of digits.</p>

<div class="impl">

<p>The <dfn>rules for parsing non-negative integers</dfn> are as
given in the following algorithm. When invoked, the steps must be
followed in the order given, aborting at the first step that returns
a value. This algorithm will return either zero, a positive integer,
or an error.</p>

<ol>

<li><p>Let <var title="">input</var> be the string being
parsed.</p></li>

<li><p>Let <var title="">value</var> be the result of parsing <var
title="">input</var> using the <span>rules for parsing
integers</span>.</p></li>

<li><p>If <var title="">value</var> is an error, return an
error.</p></li>

<li><p>If <var title="">value</var> is less than zero, return an
error.</p></li>

<li><p>Return <var title="">value</var>.</p></li>

</ol>

<!-- Implications: A leading + is ignored. A leading - is ignored if the value is zero. -->

</div>


<h5>Floating-point numbers</h5>

<p>A string is a <dfn>valid floating point number</dfn> if it
Expand Down

0 comments on commit ec18727

Please sign in to comment.