I disabled the clean due to problems with P4 having the generated files
readonly on disk. You can use it as a base for future improvements if
you want.

 

This forces the correct build order so you only have to build once (I
included the import line just so you see where I placed it). This
configuration uses the C# port of the tool to generate grammars.

 

  <PropertyGroup>

    <!-- This forces the correct build order since ANTLR tool generates
.cs files -->

    <UseHostCompilerIfAvailable>False</UseHostCompilerIfAvailable>

  </PropertyGroup>

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

  <PropertyGroup>

 
<Antlr3ToolPath>$(MSBuildProjectDirectory)\..\bin\Bootstrap</Antlr3ToolP
ath>

 
<CoreCompileDependsOn>$(CoreCompileDependsOn);GenerateAntlrCode</CoreCom
pileDependsOn>

 
<CoreCleanDependsOn>$(CoreCleanDependsOn);CleanAntlrCode</CoreCleanDepen
dsOn>

    <PostBuildEvent>

    </PostBuildEvent>

  </PropertyGroup>

  <Target Name="GenerateAntlrCode" Inputs="@(Antlr3)"
Outputs="%(OutputFiles)">

    <Message Importance="normal" Text="Antlr: Transforming '@(Antlr3)'
to '%(Antlr3.OutputFiles)'" />

    <!--<Exec Command="java -cp
%22$(Antlr3ToolPath)\antlr3.jar;$(Antlr3ToolPath)\antlr-2.7.7.jar;$(Antl
r3ToolPath)\stringtemplate-3.1b1.jar%22 org.antlr.Tool -lib
%22%(RootDir)%(Directory).%22 -message-format vs2005 @(Antlr3)"
Outputs="%(OutputFiles)" />-->

    <Exec Command="%22$(Antlr3ToolPath)\Antlr3.exe%22
-Xconversiontimeout 5000 -lib %22%(RootDir)%(Directory).%22
-message-format vs2005 @(Antlr3)" Outputs="%(OutputFiles)" />

  </Target>

  <Target Name="CleanAntlrCode">

    <ItemGroup>

      <_CleanAntlrFileWrites
Include="@(Antlr3->'%(RelativeDir)%(Filename).tokens')" />

    </ItemGroup>

    <Message Importance="normal" Text="Antlr: Deleting output files
'@(_CleanAntlrFileWrites)'" />

    <!-- NOT FULLY TESTED: Uncomment this line to actually delete
grammar outputs on clean. -->

    <!--<Delete Files="@(_CleanAntlrFileWrites)" />-->

  </Target>

 

Here is my msbuild items for a lexer grammar:

 

  <ItemGroup>

    <Antlr3 Include="Grammars\ActionAnalysisLexer.g3">

 
<OutputFiles>Grammars\ActionAnalysisLexer.cs;Grammars\ActionAnalysisLexe
r.tokens</OutputFiles>

    </Antlr3>

    <Compile Include="Grammars\ActionAnalysisLexer.cs">

      <AutoGen>True</AutoGen>

      <DesignTime>True</DesignTime>

      <DependentUpon>ActionAnalysisLexer.g3</DependentUpon>

    </Compile>

    <Compile Include="Grammars\ActionAnalysisLexerHelper.cs">

      <DependentUpon>ActionAnalysisLexer.g3</DependentUpon>

    </Compile>

  </ItemGroup>

 

For a combined grammar:

 

  <ItemGroup>

    <Antlr3 Include="Grammars\ANTLR.g3">

 
<OutputFiles>Grammars\ANTLRParser.cs;Grammars\ANTLRLexer.cs;Grammars\ANT
LR.tokens</OutputFiles>

      <CopyToOutputDirectory>Always</CopyToOutputDirectory>

    </Antlr3>

    <Compile Include="Grammars\ANTLRParser.cs">

      <AutoGen>True</AutoGen>

      <DesignTime>True</DesignTime>

      <DependentUpon>ANTLR.g3</DependentUpon>

    </Compile>

    <Compile Include="Grammars\ANTLRParserHelper.cs">

      <DependentUpon>ANTLR.g3</DependentUpon>

    </Compile>

    <Compile Include="Grammars\ANTLRLexer.cs">

      <AutoGen>True</AutoGen>

      <DesignTime>True</DesignTime>

      <DependentUpon>ANTLR.g3</DependentUpon>

    </Compile>

    <Compile Include="Grammars\ANTLRLexerHelper.cs">

      <DependentUpon>ANTLR.g3</DependentUpon>

    </Compile>

  </ItemGroup>

 

A tree grammar:

 

  <ItemGroup>

    <Antlr3 Include="Grammars\ANTLRTreePrinter.g3">

 
<OutputFiles>Grammars\ANTLRTreePrinter.cs;Grammars\ANTLRTreePrinter.toke
ns</OutputFiles>

    </Antlr3>

    <Compile Include="Grammars\ANTLRTreePrinter.cs">

      <AutoGen>True</AutoGen>

      <DesignTime>True</DesignTime>

      <DependentUpon>ANTLRTreePrinter.g3</DependentUpon>

    </Compile>

    <Compile Include="Grammars\ANTLRTreePrinterHelper.cs">

      <DependentUpon>ANTLRTreePrinter.g3</DependentUpon>

    </Compile>

  </ItemGroup>

 

Sam

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Jim Idle
Sent: Wednesday, October 07, 2009 1:15 PM
To: [email protected]
Subject: [antlr-interest] MSBUILD/Vs2008

 

Has anyone worked out the exact configuration for MSBUILD instructions
for adding in to csproj files in VS2008 with the C# target? The Wiki
version may have worked fine for VS2005 but in VS2008 it does not
encapsulate dependencies properly and the .cs files get compiled before
the .g files, which means you have to build twice. Also, it does not
cover 'clean' and 'rebuild' etc. I suspect that this is easy to work out
for someone that already knows MSBUILD well, but I don't and don't
particularly want to spend the time doing so right now ;-)

 

Cheers,

 

Jim


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to