<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;}
  #copied {background-color:#ccccff;}
  tr.alt #copied {background-color:#bbbbf7;}
  #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 {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;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="5">Commit in <b><tt>metaas/trunk/src</tt></b></td></tr>
<tr><td><tt>main/java/uk/co/badgersinfoil/metaas/impl/<a href="#file1">AS3FragmentParser.java</a></tt> </td><td></td><td align="right" id="added">+23</td><td align="right" id="removed">-6</td><td nowrap="nowrap" align="center">562 -&gt; 563</td></tr>
<tr class="alt"><td><tt>test/java/uk/co/badgersinfoil/metaas/impl/<a href="#file2"><span id="added">AS3FragmentParserTest.java</span></a></tt> </td><td></td><td align="right" id="added">+82</td><td></td><td nowrap="nowrap" align="right">added 563</td></tr>
<tr><td></td><td></td><td align="right" id="added">+105</td><td align="right" id="removed">-6</td><td></td></tr>
</table>
<small id="info">1 added + 1 modified, total 2 files</small><br />
<pre class="comment">
make AS3FragmentParser a bit more robust
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader"><big><b>AS3FragmentParser.java</b></big> <small id="info">562 -&gt; 563</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/AS3FragmentParser.java        2007-12-03 01:31:05 UTC (rev 562)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/AS3FragmentParser.java        2007-12-03 02:07:11 UTC (rev 563)
@@ -8,6 +8,7 @@
</small></pre><pre class="diff" id="context"> 
 import org.antlr.runtime.ParserRuleReturnScope;
 import org.antlr.runtime.RecognitionException;
</pre><pre class="diff" id="added">+import org.antlr.runtime.TokenStream;
</pre><pre class="diff" id="context"> import org.asdt.core.internal.antlr.AS3Parser;
 import uk.co.badgersinfoil.metaas.ActionScriptFactory;
 import uk.co.badgersinfoil.metaas.SyntaxException;
</pre><pre class="diff"><small id="info">@@ -131,7 +132,9 @@
</small></pre><pre class="diff" id="context">         public static LinkedListTree parseForInit(String expr) {
                 AS3Parser parser = ASTUtils.parse(expr + ";");
                 try {
</pre><pre class="diff" id="removed">-                        return tree(parser.forInit());
</pre><pre class="diff" id="added">+                        LinkedListTree result = tree(parser.forInit());
+                        ensureRemainingInputIs(parser.getTokenStream(), AS3Parser.SEMI, expr);
+                        return result;
</pre><pre class="diff" id="context">                 } catch (RecognitionException e) {
                         throw new SyntaxException(e);
                 }
</pre><pre class="diff"><small id="info">@@ -140,7 +143,9 @@
</small></pre><pre class="diff" id="context">         public static LinkedListTree parseForCond(String expr) {
                 AS3Parser parser = ASTUtils.parse(expr + ";");
                 try {
</pre><pre class="diff" id="removed">-                        return tree(parser.forCond());
</pre><pre class="diff" id="added">+                        LinkedListTree result = tree(parser.forCond());
+                        ensureRemainingInputIs(parser.getTokenStream(), AS3Parser.SEMI, expr);
+                        return result;
</pre><pre class="diff" id="context">                 } catch (RecognitionException e) {
                         throw new SyntaxException(e);
                 }
</pre><pre class="diff"><small id="info">@@ -149,7 +154,9 @@
</small></pre><pre class="diff" id="context">         public static LinkedListTree parseForIter(String expr) {
                 AS3Parser parser = ASTUtils.parse(expr + ")");
                 try {
</pre><pre class="diff" id="removed">-                        return tree(parser.forIter());
</pre><pre class="diff" id="added">+                        LinkedListTree result = tree(parser.forIter());
+                        ensureRemainingInputIs(parser.getTokenStream(), AS3Parser.RPAREN, expr);
+                        return result;
</pre><pre class="diff" id="context">                 } catch (RecognitionException e) {
                         throw new SyntaxException(e);
                 }
</pre><pre class="diff"><small id="info">@@ -180,15 +187,25 @@
</small></pre><pre class="diff" id="context">                 AS3Parser parser = ASTUtils.parse(":" + value);
                 try {
                         LinkedListTree result = tree(parser.typeExpression());
</pre><pre class="diff" id="removed">-                        if (parser.getTokenStream().LA(1) != AS3Parser.EOF) {
-                                throw new SyntaxException("Unexpected tokens in type name: "+value);
-                        }
</pre><pre class="diff" id="added">+                        ensureNoMoreInput(parser.getTokenStream(), value);
</pre><pre class="diff" id="context">                         return result;
                 } catch (RecognitionException e) {
                         throw new SyntaxException("invalid type-spec "+ActionScriptFactory.str(value), e);
                 }
         }
 
</pre><pre class="diff" id="added">+        private static void ensureNoMoreInput(TokenStream input, String value) {
+                if (input.LA(1) != AS3Parser.EOF) {
+                        throw new SyntaxException("Unexpected tokens in input: "+value);
+                }
+        }
+
+        private static void ensureRemainingInputIs(TokenStream input, int expectedTokenType, String value) {
+                if (input.LA(1) != expectedTokenType) {
+                        throw new SyntaxException("Unexpected tokens in input: "+value);
+                }
+        }
+
</pre><pre class="diff" id="context">         public static LinkedListTree parseForInVar(String expr) {
                 AS3Parser parser = ASTUtils.parse(expr + " in");
                 try {
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname" id="added">metaas/trunk/src/test/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader" id="added"><big><b>AS3FragmentParserTest.java</b></big> <small id="info">added at 563</small></div>
<pre class="diff"><small id="info">--- trunk/src/test/java/uk/co/badgersinfoil/metaas/impl/AS3FragmentParserTest.java                                (rev 0)
+++ trunk/src/test/java/uk/co/badgersinfoil/metaas/impl/AS3FragmentParserTest.java        2007-12-03 02:07:11 UTC (rev 563)
@@ -0,0 +1,82 @@
</small></pre><pre class="diff" id="added">+package uk.co.badgersinfoil.metaas.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import junit.framework.TestCase;
+
+public class AS3FragmentParserTest extends TestCase {
+
+        public void testParseStatement() throws Exception {
+                assertParseMethodFailsFor("parseStatement", "+-");
+        }
+
+        public void testParseExprStatement() throws Exception {
+                assertParseMethodFailsFor("parseExprStatement", "");
+        }
+
+        public void testParseCondition() throws Exception {
+                assertParseMethodFailsFor("parseCondition", "");
+        }
+
+        public void testParseExpr() throws Exception {
+                assertParseMethodFailsFor("parseExpr", "");
+        }
+
+        public void testParseExprList() throws Exception {
+                assertParseMethodFailsFor("parseExprList", "");
+        }
+
+        public void testParseIdent() throws Exception {
+                assertParseMethodFailsFor("parseIdent", "");
+        }
+
+        public void testParseParameterDefault() throws Exception {
+                assertParseMethodFailsFor("parseParameterDefault", "");
+        }
+
+        public void testParseForInit() throws Exception {
+                assertParseMethodFailsFor("parseForInit", "+-");
+                assertParseMethodFailsFor("parseForInit", "class");
+        }
+
+        public void testParseForCond() throws Exception {
+                assertParseMethodFailsFor("parseForCond", "+-");
+                assertParseMethodFailsFor("parseForCond", "class");
+        }
+
+        public void testParseForIter() throws Exception {
+                assertParseMethodFailsFor("parseForIter", "+-");
+                assertParseMethodFailsFor("parseForIter", "class");
+        }
+
+        public void testParseImport() throws Exception {
+                assertParseMethodFailsFor("parseImport", "");
+        }
+
+        public void testParseTypeSpec() throws Exception {
+                assertParseMethodFailsFor("parseTypeSpec", "");
+                assertParseMethodFailsFor("parseTypeSpec", "String*");
+        }
+
+        public void testParseForInVar() throws Exception {
+                assertParseMethodFailsFor("parseForInVar", "");
+        }
+
+        public void testParseForInIterated() throws Exception {
+                assertParseMethodFailsFor("parseForInIterated", "");
+        }
+
+        public void testParseVariableDeclarator() throws Exception {
+                assertParseMethodFailsFor("parseVariableDeclarator", "");
+        }
+
+        private static void assertParseMethodFailsFor(String methodName, String input) throws Exception {
+                Method meth = AS3FragmentParser.class.getMethod(methodName, new Class[] { String.class });
+                try {
+                        meth.invoke(null, new Object[] { input });
+                        fail(methodName+"(\""+input+"\") should fail");
+                } catch (InvocationTargetException e) {
+                        // expected
+                }
+        }
+}
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.12</small></center>
</body></html>