[antlr-interest] MSBUILD/Vs2008

Sam Harwell sharwell at pixelminegames.com
Wed Oct 7 16:20:16 PDT 2009


I like to keep one item group for each of the files, but neither order
nor grouping make a difference in functionality.

 

I didn't make a wiki article because it still seems makeshift support.
I'd like to finish the following first:

 

*         Improve the build dependency detection, especially for
grammars that depend on the .tokens file from other grammars.

*         Create a working Clean target (which carries over to Rebuild).
For this to work with source control, I need to make sure that:

o   The generated code files are not written to disk if their contents
haven't changed.

o   The same source file always generates the same output file, which
means removing relative paths and timestamps from the comments.

*         Create a Visual Studio template for adding a grammar to the
project without editing the project file manually. If this doesn't work
as well as I'd like, I would integrate the full functionality into my
Visual Studio language service for ANTLR and StringTemplate
<http://wiki.pixelminegames.com/index.php?title=Tools:nFringe:Antlr:Feat
ures> .

 

Sam

 

From: Jim Idle [mailto:jimi at temporal-wave.com] 
Sent: Wednesday, October 07, 2009 1:34 PM
To: Sam Harwell; antlr-interest at antlr.org
Subject: RE: [antlr-interest] MSBUILD/Vs2008

 

Cool. Perhps you can put this in the Wiki artivcle?

 

One question - when I have 3 grammar files in the project, is that just
the one ItemGroup or multiple, one per .g file?

 

Jim

 

From: Sam Harwell [mailto:sharwell at pixelminegames.com] 
Sent: Wednesday, October 07, 2009 11:29 AM
To: Jim Idle; antlr-interest at antlr.org
Subject: RE: [antlr-interest] MSBUILD/Vs2008

 

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: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Jim Idle
Sent: Wednesday, October 07, 2009 1:15 PM
To: antlr-interest at antlr.org
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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20091007/2321e9db/attachment.html 


More information about the antlr-interest mailing list