2013-09-16 5 views
2

Я новичок в Antlr. Я хочу использовать Antlr в C#, и я сделал все, что описано в https://github.com/sharwell/antlr4cs, но когда я строю свой проект, ничего не происходит.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

ответ

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; 
    } 
    
+0

Спасибо! это работает. – user37337

Смежные вопросы