[antlr-interest] VS2008 Integration Example
Sam Harwell
sharwell at pixelminegames.com
Tue Oct 14 09:28:10 PDT 2008
Here's how you can get the Clean and Rebuild tasks working as well. If you delete the .tokens files associated with each grammar, then the grammar will get properly rebuilt:
<PropertyGroup>
<CoreCleanDependsOn>$(CoreCleanDependsOn);CleanAntlrCode</CoreCleanDependsOn>
</PropertyGroup>
<Target Name="CleanAntlrCode">
<ItemGroup>
<_CleanAntlrFileWrites Include="@(Antlr3->'%(RelativeDir)%(Filename).tokens')" />
</ItemGroup>
<Message Importance="normal" Text="Antlr: Deleting output files '@(_CleanAntlrFileWrites)'" />
<Delete Files="@(_CleanAntlrFileWrites)" />
</Target>
Sam
-----Original Message-----
From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Gavin Lambert
Sent: Tuesday, October 14, 2008 4:09 AM
To: André van der Merwe; antlr-interest at antlr.org
Subject: Re: [antlr-interest] VS2008 Integration Example
At 21:35 14/10/2008, André van der Merwe wrote:
>Does anyone have a simple example VS2008
>solution that calls ANTLR as part of the build
>(i.e. not a pre-build event).
>
>I've followed the instructions on the web site
>but I'm doing something wrong....
For which target language?
This is the method I use for C# projects (will
probably also work with other .NET languages, but *not* C/C++):
1. Right-click, Unload Project, Right-click, Edit
project. (If you're using Express, you don't
have this option, but you can edit the project
file outside of VS instead.)
2. Somewhere inside the first <PropertyGroup> section, add these:
<AntlrFolder>D:\path\to\antlr\lib</AntlrFolder>
<AntlrClassPath>$(AntlrFolder)\antlr-3.jar;$(AntlrFolder)\stringtemplate-3.2.jar;$(AntlrFolder)\antlr-2.7.7.jar</AntlrClassPath>
3. Immediately below the
<ItemGroup>...</ItemGroup> block containing your
normal source files, add this:
<ItemGroup>
<Antlr3 Include="Your.g">
<OutputFiles>YourLexer.g;YourParser.g;Your.tokens</OutputFiles>
</Antlr3>
<Antlr3 Include="YourTree.g">
<InputFiles>Your.tokens</InputFiles>
<OutputFiles>YourTree.cs</OutputFiles>
</Antlr3>
<Compile Include="YourLexer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Your.g</DependentUpon>
</Compile>
<Compile Include="YourParser.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Your.g</DependentUpon>
</Compile>
<Compile Include="YourTree.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>YourTree.g</DependentUpon>
</Compile>
</ItemGroup>
4. Immediately above the closing </Project> tag, add this:
<Target Name="GenerateAntlrCode"
Inputs="@(Antlr3);%(Antlr3.InputFiles)"
Outputs="%(Antlr3.OutputFiles)">
<Exec Command="java -cp
"$(AntlrClassPath)" org.antlr.Tool
-message-format vs2005 @(Antlr3)"
Outputs="%(Antlr3.OutputFiles)" />
</Target>
<PropertyGroup>
<BuildDependsOn>GenerateAntlrCode;$(BuildDependsOn)</BuildDependsOn>
</PropertyGroup>
5. Edit the above to suit your real files.
There's probably better ways to do this (I'm not
really all that experienced with MSBuild), but
the above works for me. It's a little bit clunky
in that you have to manually edit the project
whenever you add new grammar files (or outputs),
but that's usually not something that happens very often.
One caveat: Visual Studio does weird things if
you have the generated .cs files open when you
build, especially if you've modified the
grammar. It's best to close the .cs files before
you build. (It sometimes seems to compile the
version of the code that's shown in the editor --
ie. the old code -- instead of the newly
generated code. This is especially true if it
thinks the code has been modified -- which
includes the line-ending adjustment it likes
making when you open them.)
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081014/44e614c3/attachment.html
More information about the antlr-interest
mailing list