Antlr4cs什么都不做

时间:2013-09-16 09:26:44

标签: c# antlr antlr4

我是Antlr的新手。我想在C#中使用Antlr,我已经完成了https://github.com/sharwell/antlr4cs中描述的所有事情,但是当我构建我的项目时,没有任何事情发生。

我的项目文件的一部分:

<ItemGroup>
  <Antlr4 Include="Model\ScriptGrammar\ScriptGrammar.g4">
    <Generator>MSBuild:Compile</Generator>
    <CustomToolNamespace>Model.ScriptGrammar</CustomToolNamespace>
  </Antlr4>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
  <!-- Folder containing Antlr4BuildTasks.dll -->
  <Antlr4BuildTaskPath>..\..\External\Antlr</Antlr4BuildTaskPath>
  <!-- Path to the ANTLR Tool itself. -->
  <Antlr4ToolPath>..\..\External\Antlr\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar</Antlr4ToolPath>
</PropertyGroup>
<Import Project="..\..\External\Antlr\Antlr4.targets" />
<PropertyGroup>
  <PostBuildEvent>$(ProjectDir)\copyExternals.bat</PostBuildEvent>
</PropertyGroup>

我的测试语法文件:

grammar ScriptGrammar;
options 
{ 
    language=CSharp_v4_5; 
} 

r : 'hello' ID ; // match keyword hello followed by an identifier
ID : [a-z]+ ; // match lower-case identifiers
WS : [ \t\r\n]+ -> skip ; // skip spaces, tabs, newlines, \r (Windows)

我正在使用Visual Studio 2012 Professional

1 个答案:

答案 0 :(得分:2)

  1. 从项目文件中删除以下行:

    <PropertyGroup>
      <!-- Folder containing Antlr4BuildTasks.dll -->
      <Antlr4BuildTaskPath>..\..\External\Antlr</Antlr4BuildTaskPath>
      <!-- Path to the ANTLR Tool itself. -->
      <Antlr4ToolPath>..\..\External\Antlr\antlr4-csharp-4.0.1-SNAPSHOT-complete.jar</Antlr4ToolPath>
    </PropertyGroup>
    <Import Project="..\..\External\Antlr\Antlr4.targets" />
    
  2. 使用NuGet包管理器安装此处描述的Antlr4包: https://www.nuget.org/packages/Antlr4

  3. 从语法文件中删除以下行。该语言由构建工具设置。

    options 
    { 
        language=CSharp_v4_5; 
    }