[Pkg-javascript-commits] [node-acorn-jsx] 56/484: Give readToken sub-functions meaningful names

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit 4229ef792e58a19218a8c737f04d6ee741453e1d
Author: Marijn Haverbeke <marijnh at gmail.com>
Date:   Tue Nov 20 16:57:07 2012 +0100

    Give readToken sub-functions meaningful names
---
 acorn.js   |  33 +++++++--------
 index.html | 138 +++++++++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 110 insertions(+), 61 deletions(-)

diff --git a/acorn.js b/acorn.js
index 43425c8..9160e58 100644
--- a/acorn.js
+++ b/acorn.js
@@ -487,47 +487,47 @@
   // The `forceRegexp` parameter is used in the one case where the
   // `tokRegexpAllowed` trick does not work. See `parseStatement`.
 
-  function readToken_46(code) { // '.'
+  function readToken_dot(code) {
     var next = input.charCodeAt(tokPos+1);
     if (next >= 48 && next <= 57) return readNumber(String.fromCharCode(code));
     ++tokPos;
     return finishToken(_dot);
   }
 
-  function readToken_47() { // '/'
+  function readToken_slash() { // '/'
     var next = input.charCodeAt(tokPos+1);
     if (tokRegexpAllowed) {++tokPos; return readRegexp();}
     if (next === 61) return finishOp(_assign, 2);
     return finishOp(_slash, 1);
   }
 
-  function readToken_37_42() { // '%*'
+  function readToken_mult_modulo() { // '%*'
     var next = input.charCodeAt(tokPos+1);
     if (next === 61) return finishOp(_assign, 2);
     return finishOp(_bin10, 1);
   }
 
-  function readToken_124_38(code) { // '|&'
+  function readToken_pipe_amp(code) { // '|&'
     var next = input.charCodeAt(tokPos+1);
     if (next === code) return finishOp(code === 124 ? _bin1 : _bin2, 2);
     if (next === 61) return finishOp(_assign, 2);
     return finishOp(code === 124 ? _bin3 : _bin5, 1);
   }
 
-  function readToken_94() { // '^'
+  function readToken_caret() { // '^'
     var next = input.charCodeAt(tokPos+1);
     if (next === 61) return finishOp(_assign, 2);
     return finishOp(_bin4, 1);    
   }
 
-  function readToken_43_45(code) { // '+-'
+  function readToken_plus_min(code) { // '+-'
     var next = input.charCodeAt(tokPos+1);
     if (next === code) return finishOp(_incdec, 2);
     if (next === 61) return finishOp(_assign, 2);
     return finishOp(_plusmin, 1);    
   }
 
-  function readToken_60_62(code) { // '<>'
+  function readToken_lt_gt(code) { // '<>'
     var next = input.charCodeAt(tokPos+1);
     var size = 1;
     if (next === code) {
@@ -540,19 +540,18 @@
     return finishOp(_bin7, size);
   }
   
-  function readToken_61_33(code) { // '=!'
+  function readToken_eq_excl(code) { // '=!'
     var next = input.charCodeAt(tokPos+1);
     if (next === 61) return finishOp(_bin6, input.charCodeAt(tokPos+2) === 61 ? 3 : 2);
     return finishOp(code === 61 ? _eq : _prefix, 1);
   }
 
   function getTokenFromCode(code) {
-
     switch(code) {
       // The interpretation of a dot depends on whether it is followed
       // by a digit.
     case 46: // '.'
-      return readToken_46(code);
+      return readToken_dot(code);
 
       // Punctuation tokens.
     case 40: ++tokPos; return finishToken(_parenL);
@@ -585,25 +584,25 @@
     // of the type given by its first argument.
 
     case 47: // '/'
-      return readToken_47(code);
+      return readToken_slash(code);
 
     case 37: case 42: // '%*'
-      return readToken_37_42();
+      return readToken_mult_modulo();
 
     case 124: case 38: // '|&'
-      return readToken_124_38(code);
+      return readToken_pipe_amp(code);
 
     case 94: // '^'
-      return readToken_94();
+      return readToken_caret();
 
     case 43: case 45: // '+-'
-      return readToken_43_45(code);
+      return readToken_plus_min(code);
 
     case 60: case 62: // '<>'
-      return readToken_60_62(code);
+      return readToken_lt_gt(code);
 
     case 61: case 33: // '=!'
-      return readToken_61_33(code);
+      return readToken_eq_excl(code);
 
     case 126: // '~'
       return finishOp(_prefix, 1);
diff --git a/index.html b/index.html
index 14bbb86..8a4419b 100644
--- a/index.html
+++ b/index.html
@@ -296,22 +296,69 @@ into it.</p>
 <p>All in the name of speed.</p>
 
 <p>The <code>forceRegexp</code> parameter is used in the one case where the
-<code>tokRegexpAllowed</code> trick does not work. See <code>parseStatement</code>.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">readToken</span><span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="p">{</span>
-    <span class="nx">tokStart</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span>
-    <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span> <span class="nx">tokStartLoc</span> <span class="o">=</span> <span class="nx">curLineLoc</span><span class="p">();</span>
-    <span class="nx">tokCommentsBefore</span> <span class="o">=</span> <span class="nx">tokComments</span><span class="p">;</span>
-    <span class="k">if</span> <span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readRegexp</span><span class="p">();</span>
-    <span class="k">if</span> <span class="p">(</span><span class="nx">tokPos</span> <span class="o">>=</span> <span class="nx">inputLen</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_eof</span><span class="p">);</span>
+<code>tokRegexpAllowed</code> trick does not work. See <code>parseStatement</code>.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">function</span> <span class="nx">readToken_dot</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
+    <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">>=</span> <span class="mi">48</span> <span class="o">&&</span> <span class="nx">next</span> <span class="o"><=</span> <span class="mi">57</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readNumber</span><span class="p">(</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span cl [...]
+    <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
+    <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_dot</span><span class="p">);</span>
+  <span class="p">}</span>
 
-    <span class="kd">var</span> <span class="nx">code</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-56">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-56">¶</a>             [...]
-identifiers, so '\' also dispatches to that.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">if</span> <span class="p">(</span><span class="nx">isIdentifierStart</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="o">||</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">92</span> <span class="cm">/* '\' */</span><span class="p">)</span> <span  [...]
+  <span class="kd">function</span> <span class="nx">readToken_slash</span><span class="p">()</span> <span class="p">{</span> <span class="c1">// '/'</span>
+    <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">tokRegexpAllowed</span><span class="p">)</span> <span class="p">{</span><span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">readRegexp</span><span class="p">();}</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
+    <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_slash</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+  <span class="p">}</span>
+
+  <span class="kd">function</span> <span class="nx">readToken_mult_modulo</span><span class="p">()</span> <span class="p">{</span> <span class="c1">// '%*'</span>
+    <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
+    <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin10</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+  <span class="p">}</span>
+
+  <span class="kd">function</span> <span class="nx">readToken_pipe_amp</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '|&'</span>
+    <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">124</span> <span class="o">?</span> <span class="nx">_bin1</span> <span class="o">:</span> <span class="nx">_bin2</span><span class="p">,</span> <span class="mi">2</span> [...]
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
+    <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">124</span> <span class="o">?</span> <span class="nx">_bin3</span> <span class="o">:</span> <span class="nx">_bin5</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+  <span class="p">}</span>
+
+  <span class="kd">function</span> <span class="nx">readToken_caret</span><span class="p">()</span> <span class="p">{</span> <span class="c1">// '^'</span>
+    <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
+    <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin4</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>    
+  <span class="p">}</span>
+
+  <span class="kd">function</span> <span class="nx">readToken_plus_min</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '+-'</span>
     <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_incdec</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
+    <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_plusmin</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>    
+  <span class="p">}</span>
+
+  <span class="kd">function</span> <span class="nx">readToken_lt_gt</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '<>'</span>
+    <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="kd">var</span> <span class="nx">size</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
+      <span class="nx">size</span> <span class="o">=</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">62</span> <span class="o">&&</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">2</span><span class="p">)</span> <span class="o">===</span> <span class="mi">62</span> <span class="o">?</span> <span class="mi">3</s [...]
+      <span class="k">if</span> <span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="nx">size</span><span class="p">)</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</sp [...]
+      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin8</span><span class="p">,</span> <span class="nx">size</span><span class="p">);</span>
+    <span class="p">}</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span>
+      <span class="nx">size</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">2</span><span class="p">)</span> <span class="o">===</span> <span class="mi">61</span> <span class="o">?</span> <span class="mi">3</span> <span class="o">:</span> <span class="mi">2</span><span class="p">;</span>
+    <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin7</span><span class="p">,</span> <span class="nx">size</span><span class="p">);</span>
+  <span class="p">}</span>
+  
+  <span class="kd">function</span> <span class="nx">readToken_eq_excl</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// '=!'</span>
+    <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin6</span><span class="p">,</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">2</span>< [...]
+    <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">61</span> <span class="o">?</span> <span class="nx">_eq</span> <span class="o">:</span> <span class="nx">_prefix</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+  <span class="p">}</span>
 
-    <span class="k">switch</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-57">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-57">¶</a>               </div>               <p>The interpretation of a dot depends on whether it is followed
+  <span class="kd">function</span> <span class="nx">getTokenFromCode</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
+    <span class="k">switch</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-56">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-56">¶</a>               </div>               <p>The interpretation of a dot depends on whether it is followed
 by a digit.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">case</span> <span class="mi">46</span><span class="o">:</span> <span class="c1">// '.'</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">>=</span> <span class="mi">48</span> <span class="o">&&</span> <span class="nx">next</span> <span class="o"><=</span> <span class="mi">57</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readNumber</span><span class="p">(</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span  [...]
-      <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span>
-      <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_dot</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-58">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-58">¶</a>               </div>               <p>Punctuation tokens.</p>             </td>             <td class="code">       [...]
+      <span class="k">return</span> <span class="nx">readToken_dot</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-57">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-57">¶</a>               </div>               <p>Punctuation tokens.</p>             </td>             <td class="code">     [...]
     <span class="k">case</span> <span class="mi">41</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_parenR</span><span class="p">);</span>
     <span class="k">case</span> <span class="mi">59</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_semi</span><span class="p">);</span>
     <span class="k">case</span> <span class="mi">44</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_comma</span><span class="p">);</span>
@@ -320,57 +367,60 @@ by a digit.</p>             </td>             <td class="code">               <d
     <span class="k">case</span> <span class="mi">123</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_braceL</span><span class="p">);</span>
     <span class="k">case</span> <span class="mi">125</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_braceR</span><span class="p">);</span>
     <span class="k">case</span> <span class="mi">58</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_colon</span><span class="p">);</span>
-    <span class="k">case</span> <span class="mi">63</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_question</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-59">             <td class="docs">               <div class="pilwrap">                 <a [...]
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">120</span> <span class="o">||</span> <span class="nx">next</span> <span class="o">===</span> <span class="mi">88</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readHexNumber</span><span class="p">();</span></pre></div>             </td>           </tr>                               <tr id="section-60">             <td class="docs" [...]
+    <span class="k">case</span> <span class="mi">63</span><span class="o">:</span> <span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_question</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-58">             <td class="docs">               <div class="pilwrap">                 <a [...]
+      <span class="kd">var</span> <span class="nx">next</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">1</span><span class="p">);</span>
+      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">120</span> <span class="o">||</span> <span class="nx">next</span> <span class="o">===</span> <span class="mi">88</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readHexNumber</span><span class="p">();</span></pre></div>             </td>           </tr>                               <tr id="section-59">             <td class="docs" [...]
 number, or float.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">case</span> <span class="mi">49</span><span class="o">:</span> <span class="k">case</span> <span class="mi">50</span><span class="o">:</span> <span class="k">case</span> <span class="mi">51</span><span class="o">:</span> <span class="k">case</span> <span class="mi">52</span><span class="o">:</span> <span class="k">case</span> <span class="mi">53</span><span  [...]
-      <span class="k">return</span> <span class="nx">readNumber</span><span class="p">(</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">));</span></pre></div>             </td>           </tr>                               <tr id="section-61">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-61">¶</a>   [...]
-      <span class="k">return</span> <span class="nx">readString</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-62">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-62">¶</a>               </div>               <p>Operators are parsed inline in tiny state machines. '=' (61) is
+      <span class="k">return</span> <span class="nx">readNumber</span><span class="p">(</span><span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">));</span></pre></div>             </td>           </tr>                               <tr id="section-60">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-60">¶</a>   [...]
+      <span class="k">return</span> <span class="nx">readString</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-61">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-61">¶</a>               </div>               <p>Operators are parsed inline in tiny state machines. '=' (61) is
 often referred to. <code>finishOp</code> simply skips the amount of
 characters it is given as second argument, and returns a token
 of the type given by its first argument.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">case</span> <span class="mi">47</span><span class="o">:</span> <span class="c1">// '/'</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">tokRegexpAllowed</span><span class="p">)</span> <span class="p">{</span><span class="o">++</span><span class="nx">tokPos</span><span class="p">;</span> <span class="k">return</span> <span class="nx">readRegexp</span><span class="p">();}</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
-      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_slash</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_slash</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
 
     <span class="k">case</span> <span class="mi">37</span><span class="o">:</span> <span class="k">case</span> <span class="mi">42</span><span class="o">:</span> <span class="c1">// '%*'</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
-      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin10</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_mult_modulo</span><span class="p">();</span>
 
     <span class="k">case</span> <span class="mi">124</span><span class="o">:</span> <span class="k">case</span> <span class="mi">38</span><span class="o">:</span> <span class="c1">// '|&'</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">124</span> <span class="o">?</span> <span class="nx">_bin1</span> <span class="o">:</span> <span class="nx">_bin2</span><span class="p">,</span> <span class="mi">2</spa [...]
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
-      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">124</span> <span class="o">?</span> <span class="nx">_bin3</span> <span class="o">:</span> <span class="nx">_bin5</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_pipe_amp</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
 
     <span class="k">case</span> <span class="mi">94</span><span class="o">:</span> <span class="c1">// '^'</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
-      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin4</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_caret</span><span class="p">();</span>
 
     <span class="k">case</span> <span class="mi">43</span><span class="o">:</span> <span class="k">case</span> <span class="mi">45</span><span class="o">:</span> <span class="c1">// '+-'</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_incdec</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</span> <span class="mi">2</span><span class="p">);</span>
-      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_plusmin</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_plus_min</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
 
     <span class="k">case</span> <span class="mi">60</span><span class="o">:</span> <span class="k">case</span> <span class="mi">62</span><span class="o">:</span> <span class="c1">// '<>'</span>
-      <span class="kd">var</span> <span class="nx">size</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="nx">code</span><span class="p">)</span> <span class="p">{</span>
-        <span class="nx">size</span> <span class="o">=</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">62</span> <span class="o">&&</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">2</span><span class="p">)</span> <span class="o">===</span> <span class="mi">62</span> <span class="o">?</span> <span class="mi">3< [...]
-        <span class="k">if</span> <span class="p">(</span><span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span> <span class="o">+</span> <span class="nx">size</span><span class="p">)</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_assign</span><span class="p">,</ [...]
-        <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin8</span><span class="p">,</span> <span class="nx">size</span><span class="p">);</span>
-      <span class="p">}</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span>
-        <span class="nx">size</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">2</span><span class="p">)</span> <span class="o">===</span> <span class="mi">61</span> <span class="o">?</span> <span class="mi">3</span> <span class="o">:</span> <span class="mi">2</span><span class="p">;</span>
-      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin7</span><span class="p">,</span> <span class="nx">size</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_lt_gt</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
 
     <span class="k">case</span> <span class="mi">61</span><span class="o">:</span> <span class="k">case</span> <span class="mi">33</span><span class="o">:</span> <span class="c1">// '=!'</span>
-      <span class="k">if</span> <span class="p">(</span><span class="nx">next</span> <span class="o">===</span> <span class="mi">61</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_bin6</span><span class="p">,</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="o">+</span><span class="mi">2</span [...]
-      <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">code</span> <span class="o">===</span> <span class="mi">61</span> <span class="o">?</span> <span class="nx">_eq</span> <span class="o">:</span> <span class="nx">_prefix</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
+      <span class="k">return</span> <span class="nx">readToken_eq_excl</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
 
     <span class="k">case</span> <span class="mi">126</span><span class="o">:</span> <span class="c1">// '~'</span>
       <span class="k">return</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">_prefix</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span>
-    <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-63">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-63">¶</a>               </div>               <p>If we are here, we either found a non-ASCII identifier
-character, or something that's entirely disallowed.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="kd">var</span> <span class="nx">ch</span> <span class="o">=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
-    <span class="k">if</span> <span class="p">(</span><span class="nx">ch</span> <span class="o">===</span> <span class="s2">"\\"</span> <span class="o">||</span> <span class="nx">nonASCIIidentifierStart</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">ch</span><span class="p">))</span> <span class="k">return</span> <span class="nx">readWord</span><span class="p">();</span>
-    <span class="nx">raise</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">,</span> <span class="s2">"Unexpected character '"</span> <span class="o">+</span> <span class="nx">ch</span> <span class="o">+</span> <span class="s2">"'"</span><span class="p">);</span>
+    <span class="p">}</span>
+
+    <span class="k">return</span> <span class="kc">false</span><span class="p">;</span>
+  <span class="p">}</span>
+
+  <span class="kd">function</span> <span class="nx">readToken</span><span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="p">{</span>
+    <span class="nx">tokStart</span> <span class="o">=</span> <span class="nx">tokPos</span><span class="p">;</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">locations</span><span class="p">)</span> <span class="nx">tokStartLoc</span> <span class="o">=</span> <span class="nx">curLineLoc</span><span class="p">();</span>
+    <span class="nx">tokCommentsBefore</span> <span class="o">=</span> <span class="nx">tokComments</span><span class="p">;</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">forceRegexp</span><span class="p">)</span> <span class="k">return</span> <span class="nx">readRegexp</span><span class="p">();</span>
+    <span class="k">if</span> <span class="p">(</span><span class="nx">tokPos</span> <span class="o">>=</span> <span class="nx">inputLen</span><span class="p">)</span> <span class="k">return</span> <span class="nx">finishToken</span><span class="p">(</span><span class="nx">_eof</span><span class="p">);</span>
+
+    <span class="kd">var</span> <span class="nx">code</span> <span class="o">=</span> <span class="nx">input</span><span class="p">.</span><span class="nx">charCodeAt</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">);</span></pre></div>             </td>           </tr>                               <tr id="section-62">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-62">¶</a>             [...]
+identifiers, so '\' also dispatches to that.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">if</span> <span class="p">(</span><span class="nx">isIdentifierStart</span><span class="p">(</span><span class="nx">code</span><span class="p">)</span> <span class="o">||</span> <span class="nx">code</span> <span class="o">===</span> <span class="mi">92</span> <span class="cm">/* '\' */</span><span class="p">)</span> <span  [...]
+    
+    <span class="kd">var</span> <span class="nx">tok</span> <span class="o">=</span> <span class="nx">getTokenFromCode</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
+
+    <span class="k">if</span><span class="p">(</span><span class="nx">tok</span> <span class="o">===</span> <span class="kc">false</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-63">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-63">¶</a>               </div>               <p>If we are here, we either found a non-A [...]
+character, or something that's entirely disallowed.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="kd">var</span> <span class="nx">ch</span> <span class="o">=</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span><span class="p">(</span><span class="nx">code</span><span class="p">);</span>
+      <span class="k">if</span> <span class="p">(</span><span class="nx">ch</span> <span class="o">===</span> <span class="s2">"\\"</span> <span class="o">||</span> <span class="nx">nonASCIIidentifierStart</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">ch</span><span class="p">))</span> <span class="k">return</span> <span class="nx">readWord</span><span class="p">();</span>
+      <span class="nx">raise</span><span class="p">(</span><span class="nx">tokPos</span><span class="p">,</span> <span class="s2">"Unexpected character '"</span> <span class="o">+</span> <span class="nx">ch</span> <span class="o">+</span> <span class="s2">"'"</span><span class="p">);</span>
+    <span class="p">}</span> 
+    <span class="k">return</span> <span class="nx">tok</span><span class="p">;</span>
   <span class="p">}</span>
 
   <span class="kd">function</span> <span class="nx">finishOp</span><span class="p">(</span><span class="nx">type</span><span class="p">,</span> <span class="nx">size</span><span class="p">)</span> <span class="p">{</span>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list