<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>public abstract string[] Blog() &#187; DRY</title>
	<atom:link href="http://extractmethod.wordpress.com/category/dry/feed/" rel="self" type="application/rss+xml" />
	<link>http://extractmethod.wordpress.com</link>
	<description>Wandering the Internet is search of better code and coding techniques</description>
	<lastBuildDate>Sat, 21 Jun 2008 14:01:14 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='extractmethod.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/aa59efbf3eef34a86e290a03a0aeb4a1?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>public abstract string[] Blog() &#187; DRY</title>
		<link>http://extractmethod.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://extractmethod.wordpress.com/osd.xml" title="public abstract string[] Blog()" />
		<item>
		<title>Integrating ANTLR Code Generation with Visual Studio 2008</title>
		<link>http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/</link>
		<comments>http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/#comments</comments>
		<pubDate>Wed, 02 Jan 2008 23:44:04 +0000</pubDate>
		<dc:creator>casademora</dc:creator>
				<category><![CDATA[ANTLR]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[DRY]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[msbuild]]></category>

		<guid isPermaLink="false">http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/</guid>
		<description><![CDATA[ANTLR is a DSL tool that can generate a language parser based on a grammar (*.g) file. From there, you hook into the parser so that your code can interpret the language into constructs your application can understand. But, in order to get your grammar file correct, you make end up using a variety of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=extractmethod.wordpress.com&blog=2356552&post=6&subd=extractmethod&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://www.antlr.org/">ANTLR</a> is a DSL tool that can generate a language parser based on a grammar (*.g) file. From there, you hook into the parser so that your code can interpret the language into constructs your application can understand. But, in order to get your grammar file correct, you make end up using a variety of development methods such as TDD, and all of them will have the same step: run the <a href="http://www.antlr.org/works">ANTLR tool</a> against your grammar file to generate your parser code.The ANTLR web site has <a href="http://www.antlr.org/wiki/display/ANTLR3/Integration+with+development+environments" title="Integrating ANTLR With other development environments">an article</a> on <a href="http://www.antlr.org/wiki/display/ANTLR3/ANTLR+v3+documentation" title="ANTLR Documentation Wiki">its wiki</a> that will let you integrate the ANTLR tool into your Visual Studio Build process. Follow the steps outlined in that article <b>first</b>.  Since VS 2008 project files are basically MS Build files, the steps work almost verbatim. However, here are a few caveats I encountered:The Exec command in the <b>GenerateAntlrCode</b> target needed some <i>classpath</i> modifications. Basically, I needed to tell <a href="http://java.sun.com/">java</a> where the Antlr jar file was located. Here is what I ended up with:
<div class="csharpcode">
<pre><span class="lnum">1:  </span><span class="kwrd">&lt;</span><span class="html">Target</span> <span class="attr">Name</span><span class="kwrd">="GenerateAntlrCode"</span> <span class="attr">Inputs</span><span class="kwrd">="@(Antlr3)"</span> <span class="attr">Outputs</span><span class="kwrd">="%(Antlr3.OutputFiles)"</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum">2:  </span>    <span class="kwrd">&lt;</span><span class="html">Exec</span> <span class="attr">Command</span><span class="kwrd">="java -cp %22$(Antlr3ToolPath)\antlr.jar;$(Antlr3ToolPath)\antlr-3.0.1.jar;$(Antlr3ToolPath)\stringtemplate-3.1b1.jar%22 org.antlr.Tool -message-format vs2005 -lib $(AntlrGrammarPath)  @(Antlr3)"</span> <span class="attr">Outputs</span><span class="kwrd">="%(Antlr3.OutputFiles)"</span> <span class="kwrd">/&gt;</span> <span class="lnum">   </span> <span class="lnum">3:  </span>  <span class="kwrd">&lt;/</span><span class="html">Target</span><span class="kwrd">&gt;</span></pre>
</div>
<p>A couple of notes regarding this target:
<ul>
<li>%22 is the escaped form of double-quotes (&#8220;)</li>
<li>I decided to create a build variable so that any changes to a path was updated everywhere (<a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY principle</a>).</li>
<li>You need to reference several jars:
<ul>
<li>antlr.jar -&gt; The Antlr 2.7.7 tool</li>
<li>antlr-3.0.1.jar -&gt; The Antlr 3.0.1 tool</li>
<li>stringtemplate-3.1b1.jar -&gt; The String Template library</li>
</ul>
</li>
</ul>
<p>The antlr 2.7.7 jar is needed for the StreamToken class that seems to be in a different namespace than the 3.0.1 jar.The properties called Antlr3ToolPath and Antlr3GrammarPath are defined in a property group like so:
<div class="csharpcode">
<pre><span class="lnum">1:  </span>  <span class="kwrd">&lt;</span><span class="html">PropertyGroup</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum">2:  </span>    <span class="kwrd">&lt;</span><span class="html">Antlr3ToolPath</span><span class="kwrd">&gt;</span>$(MSBuildProjectDirectory)\..\..\Tools\ANTLR<span class="kwrd">&lt;/</span><span class="html">Antlr3ToolPath</span><span class="kwrd">&gt;</span> <span class="lnum">  </span> <span class="lnum">3:  </span>    <span class="kwrd">&lt;</span><span class="html">AntlrGrammarPath</span><span class="kwrd">&gt;</span>$(MSBuildProjectDirectory)\Model\Parsers<span class="kwrd">&lt;/</span><span class="html">AntlrGrammarPath</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum">4:  </span>    <span class="kwrd">&lt;</span><span class="html">BuildDependsOn</span><span class="kwrd">&gt;</span>GenerateAntlrCode;$(BuildDependsOn)<span class="kwrd">&lt;/</span><span class="html">BuildDependsOn</span><span class="kwrd">&gt;</span> <span class="lnum">   </span> <span class="lnum"><span class="lnum">5:  </span>  <span class="kwrd">&lt;/</span><span class="html">PropertyGroup</span><span class="kwrd">&gt;</span></span></pre>
</div>
<p>The reason the GrammarPath is basically pointing to the output folder of the parser. This is needed because I am using the ANTLR output option of AST, which generates an Abstract Syntax Tree that much be consumed by another ANTLR grammar. For more details on why you need two grammar files for this process, I recommend the book The Definitive ANTLR Reference, by Terrence Parr.After that, I was able to use Visual Studio to generate the code on every build of the code. When using TDD tools like <a href="http://www.jetbrains.net/resharper">resharper</a> or <a href="http://www.testdriven.net">testdriven.net</a>, this is an added bonus in that any changes made to the grammar are incorporated in my unit tests. Bonus number 2: since the changes are within the project file itself, and since my continuous integration server is based on my Visual Studio Solution file, the grammar files are also included on my build server and will cause the build to fail if the grammar fails to compile.I hope your build goes just as nicely.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/extractmethod.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/extractmethod.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/extractmethod.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/extractmethod.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/extractmethod.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=extractmethod.wordpress.com&blog=2356552&post=6&subd=extractmethod&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://extractmethod.wordpress.com/2008/01/02/integrating-antlr-code-generation-with-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4c5bc935da066bf73113e426f396ba60?s=96&#38;d=identicon" medium="image">
			<media:title type="html">casademora</media:title>
		</media:content>
	</item>
	</channel>
</rss>