[as2api-dev] [CVS trunk] Rather than each lexical action call emit() directly, just return the token

David Holroyd dave at badgers-in-foil.co.uk
Mon, 04 Jul 2005 23:21:51 +0000


<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="4">Commit in <b><tt>trunk/as2api/parse</tt></b><span id="info"> on MAIN</span></td></tr>
<tr><td><tt><a href="#file1">lexer.rb</a></tt></td><td align="right" id="added">+17</td><td align="right" id="removed">-17</td><td nowrap="nowrap" align="center"><a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/parse/lexer.rb?rev=185&amp;content-type=text/vnd.viewcvs-markup">185</a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/parse/lexer.rb.diff?r1=185&amp;r2=186">-&gt;</a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/parse/lexer.rb?rev=186&amp;content-type=text/vnd.viewcvs-markup">186</a></td></tr>
</table>
<pre class="comment">
Rather than each lexical action call emit() directly, just return the token
and have the calling code do the emit().  This is simpler.
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname"><a
href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk">trunk</a>/<a
href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api">as2api</a>/<a
href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/parse">parse</a></span><br />
<div class="fileheader"><big><b>lexer.rb</b></big> <small id="info"><a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/parse/lexer.rb?rev=185&amp;content-type=text/vnd.viewcvs-markup">185</a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/parse/lexer.rb.diff?r1=185&amp;r2=186">-&gt;</a> <a href="http://svn.badgers-in-foil.co.uk/viewcvs.cgi/as2api/trunk/as2api/parse/lexer.rb?rev=186&amp;content-type=text/vnd.viewcvs-markup">186</a></small></div>
<pre class="diff"><small id="info">--- trunk/as2api/parse/lexer.rb	2005-07-04 22:31:48 UTC (rev 185)
+++ trunk/as2api/parse/lexer.rb	2005-07-04 23:21:49 UTC (rev 186)
@@ -288,8 +288,8 @@
</small></pre><pre class="diff" id="context">     EOE
     ActionScript::Parse.const_set(class_name, the_class)
 
</pre><pre class="diff" id="removed">-    add_match(match) do |lex, match, io|
-      lex.emit(ActionScript::Parse.const_get(class_name).new(io.lineno))
</pre><pre class="diff" id="added">+    add_match(match) do |match, io|
+      ActionScript::Parse.const_get(class_name).new(io.lineno)
</pre><pre class="diff" id="context">     end
   end
 
</pre><pre class="diff"><small id="info">@@ -297,17 +297,17 @@
</small></pre><pre class="diff" id="context">     make_simple_token(name.capitalize, name, "#{name}\\b")
   end
 
</pre><pre class="diff" id="removed">-  add_match(WHITESPACE) do |<span id="removedchars">lex,&nbsp;</span>match, io|
</pre><pre class="diff" id="added">+  add_match(WHITESPACE) do |match, io|
</pre><pre class="diff" id="context">     # TODO: whitespace tokens don't span lines, which might not be the expected
     #       behaviour
</pre><pre class="diff" id="removed">-    lex.emit(WhitespaceToken.new(match[0], io.lineno))
</pre><pre class="diff" id="added">+    WhitespaceToken.new(match[0], io.lineno)
</pre><pre class="diff" id="context">   end
 
</pre><pre class="diff" id="removed">-  add_match(SINGLE_LINE_COMMENT) do |lex, match, io|
-    lex.emit(SingleLineCommentToken.new(match[1], io.lineno))
</pre><pre class="diff" id="added">+  add_match(SINGLE_LINE_COMMENT) do |match, io|
+    SingleLineCommentToken.new(match[1], io.lineno)
</pre><pre class="diff" id="context">   end
 
</pre><pre class="diff" id="removed">-  add_match(OMULTI_LINE_COMMENT) do |<span id="removedchars">lex,&nbsp;</span>match, io|
</pre><pre class="diff" id="added">+  add_match(OMULTI_LINE_COMMENT) do |match, io|
</pre><pre class="diff" id="context">     lineno = io.lineno
     line = match.post_match
     comment = ''
</pre><pre class="diff"><small id="info">@@ -316,8 +316,8 @@
</small></pre><pre class="diff" id="context">       line = io.readline;
     end
     comment &lt;&lt; $`
</pre><pre class="diff" id="removed">-    lex.emit(MultiLineCommentToken.new(comment, lineno))
</pre><pre class="diff" id="context">     match.string = $'
</pre><pre class="diff" id="added">+    MultiLineCommentToken.new(comment, lineno)
</pre><pre class="diff" id="context">   end
 
   Keywords.each do |keyword|
</pre><pre class="diff"><small id="info">@@ -332,11 +332,11 @@
</small></pre><pre class="diff" id="context">     make_punctuation_token(*punct)
   end
 
</pre><pre class="diff" id="removed">-  add_match(ident) do |lex, match, io|
-    lex.emit(IdentifierToken.new(match[0], io.lineno))
</pre><pre class="diff" id="added">+  add_match(ident) do |match, io|
+    IdentifierToken.new(match[0], io.lineno)
</pre><pre class="diff" id="context">   end
 
</pre><pre class="diff" id="removed">-  add_match(STRING_START1) do |<span id="removedchars">lex,&nbsp;</span>match, io|
</pre><pre class="diff" id="added">+  add_match(STRING_START1) do |match, io|
</pre><pre class="diff" id="context">     lineno = io.lineno
     line = match.post_match
     str = ''
</pre><pre class="diff"><small id="info">@@ -345,11 +345,11 @@
</small></pre><pre class="diff" id="context">       line = io.readline;
     end
     str &lt;&lt; $1
</pre><pre class="diff" id="removed">-    lex.emit(StringToken.new(str, lineno))
</pre><pre class="diff" id="context">     match.string = $'
</pre><pre class="diff" id="added">+    StringToken.new(str, lineno)
</pre><pre class="diff" id="context">   end
 
</pre><pre class="diff" id="removed">-  add_match(STRING_START2) do |<span id="removedchars">lex,&nbsp;</span>match, io|
</pre><pre class="diff" id="added">+  add_match(STRING_START2) do |match, io|
</pre><pre class="diff" id="context">     lineno = io.lineno
     line = match.post_match
     str = ''
</pre><pre class="diff"><small id="info">@@ -358,12 +358,12 @@
</small></pre><pre class="diff" id="context">       line = io.readline;
     end
     str &lt;&lt; $1
</pre><pre class="diff" id="removed">-    lex.emit(StringToken.new(str, lineno))
</pre><pre class="diff" id="context">     match.string = $'
</pre><pre class="diff" id="added">+    StringToken.new(str, lineno)
</pre><pre class="diff" id="context">   end
 
</pre><pre class="diff" id="removed">-  add_match(num) do |lex, match, io|
-    lex.emit(NumberToken.new(match[0], io.lineno))
</pre><pre class="diff" id="added">+  add_match(num) do |match, io|
+    NumberToken.new(match[0], io.lineno)
</pre><pre class="diff" id="context">   end
 
   def check_fill
</pre><pre class="diff"><small id="info">@@ -381,7 +381,7 @@
</small></pre><pre class="diff" id="context">     @@matches.each_with_index do |token_match, index|
       re, action = token_match
       text &lt;&lt; "if line.scan(/#{re}/)\n"
</pre><pre class="diff" id="removed">-      text &lt;&lt; "  @@matches[#{index}][1].call(self, line, @io)\n"
</pre><pre class="diff" id="added">+      text &lt;&lt; "  emit(@@matches[#{index}][1].call(line, @io))\n"
</pre><pre class="diff" id="context">       text &lt;&lt; "  next\n"
       text &lt;&lt; "end\n"
     end
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.11</small></center>
</body></html>