tunnelvisionlabs / antlr4cs

The original, highly-optimized C# Target for ANTLR 4
Other
448 stars 103 forks source link

How to build a multiple file grammar in Visual Studio? #111

Open scottcarr opened 9 years ago

scottcarr commented 9 years ago

I've got a large grammar that's split up into multiple files and multiple grammars that I stitch together with import statements.

If I include the top level file in my .csproj, the parser and lexer build fine, but the issue is that if any of the imported grammars change Visual Studio doesn't know to rebuild the top level grammar.

I don't want to build a parser for the imported grammars only the top level one.

How do I tell Visual Studio (2015) that the top level grammar is dependent on other files?

I installed the Antlr4 -Pre Nuget package and I have this is my .csproj file to include the top level grammar:

<Antlr4 Include="MyTopLevelGrammar.g4">
<Generator>MSBuild:Compile</Generator>
<CustomToolNamespace>MyTopLevelGrammar</CustomToolNamespace>
</Antlr4>

I really need to split the grammar into multiple files because I'm building parsers for two different languages with common constructs.

Thank you!

Edit: I think Build Action: Antlr4AbstractGrammar does what I need. Is this the purpose off that action?

sharwell commented 9 years ago

It appears that setting the build action to Antlr4AbstractGrammar will in fact trigger regeneration of your grammars when a dependency changes.

:thought_balloon: I wonder where I came up with that name. It's definitely not the same as the AbstractGrammar property.

scottcarr commented 9 years ago

Thanks for your response. When I try to build my parser in Visual Studio I get a java out of memory error. The weird thing is that if I run "java -jar antlr4-csharp-4.5-SNAPSHOT-complete.jar mygrammar.g4" from PowerShell it seems to generate the parser without error. Any ideas? I installed Anltr4 -Pre with nuget. Is there an option to give the JVM more memory?