Hello everyone,
The update described below is not yet released; keep reading for details. :)
I’m working on updating the ANTLR Language Support extension for Visual Studio 2010-2012 to also support working with ANTLR 4 grammars. This extension will integrate direct support for several aspects of the ANTLR 4 C# target into the IDE. This includes support for exceptions and grammar file properties, as shown in the screenshots below.
· (Figure 1) Adds the exceptions in the ANTLR 4 C# runtime to the Debug -> Exceptions… dialog for easy configuration (otherwise you must manually add them)
· (Figure 2) Adds item templates for Lexer, Parser, and Combined ANTLR 4 grammars, including automatically creating the “.g4.cs” partial/helper classes
· (Figure 3) Provides direct access to ANTLR 4 code generation properties when you select a grammar in Solution Explorer
· When an ANTLR 4 grammar file (*.g4) is added to the project
o (Figure 3) Automatically sets the Build Action to Antlr4 and the Target Language to CSharp
o (Figure 3) Automatically configures the Custom Tool Namespace so the generated code is placed in a namespace based on where in the project you added the grammar
· When the “helper file” for an ANTLR 4 grammar (*.g4.cs) is added to the project
o (Figure 4) Automatically sets the file a “dependent on” the grammar itself, so it shows as a child of the grammar node in Solution Explorer
The above general features are already fully implemented. I’m planning to release the update as soon as I complete some minimal syntax highlighting support for ANTLR 4 files (full editing abilities to follow in the future).

Figure 1. Updated Exceptions dialog

Figure 2. ANTLR item templates (v3 and v4)

Figure 3. ANTLR-specific code generation properties

Figure 4. Automatic creation of helper files from ANTLR 4 item templates
Thanks,
--
Sam Harwell
Owner, Lead Developer
![]()
Hi Roberto,
1. It does add them as children, but they won’t show that way in Solution Explorer until you reload the project (either by the Unload Project / Reload Project commands, or by closing and reopening the solution).
2.
The plugin is not responsible for any of the actual code generation, as that would lead to a solution build that’s unnecessarily dependent on the
particular set of extensions a user has installed. Instructions for updating the project file can be found on the following page:
https://github.com/sharwell/antlr4cs
Thank you,
--
Sam Harwell
Owner, Lead Developer
From: antlr-di...@googlegroups.com [mailto:antlr-di...@googlegroups.com]
On Behalf Of Roberto Mencia Franco
Sent: Sunday, March 03, 2013 10:20 PM
To: antlr-di...@googlegroups.com
Subject: [antlr-discussion] Re: Visual Studio 2010-2012 support for using the ANTLR 4 C# target (coming soon)
Hi Sam,
It's great that you've got this so quickly.
I've just updated the ANTLR plug-in in VS and I have a couple of questions:
1 - I Have added a new anrtlr4 g4 file to VS and it adds the helper files (as you said above), however it doesn't automatically add them as child files of the grammar (as your images show). Is this a bug or a future feature that you are currently working on?
2 - How can I make it work to generate the antlr4 parser and lexer from VS? I downloaded the C# target already. Do we need to do manual updates of the projects (same as antlr3) in order to generate the files when the grammar is saved, or it is expected that
the plugin does all the code generation without having to do vs project files surgery?
I can't wait to get all my stuff working with antlr4.
Thanks.
On Friday, March 1, 2013 5:38:37 AM UTC+11, Sam Harwell wrote:
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
This way we can use it as a reference in case something doesn't work.
Hi Roberto,
Your sample is configured correctly and builds without problems here. Do you have Java installed?
If you run into problems where the build says it can’t find a required .tokens file, you should update your Antlr4.targets file to the one in this commit:
https://github.com/sharwell/antlr4cs/commit/d41f4ba906a3f7e90f904316e64b27d345ab4b5f
Figure 1. Updated Exceptions dialog
Figure 2. ANTLR item templates (v3 and v4)
Figure 3. ANTLR-specific code generation properties
Figure 4. Automatic creation of helper files from ANTLR 4 item templates
Thanks,
--
Sam Harwell
Owner, Lead Developer
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/yJR7ezuDqu4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
--
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/yJR7ezuDqu4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
private string JavaHome { get { string javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment"; var value = GetJavaHomeFromRegistry(javaKey, RegistryView.Registry32); if(string.IsNullOrEmpty(value) ) value = GetJavaHomeFromRegistry(javaKey, RegistryView.Registry64); if (string.IsNullOrEmpty(value)) throw new FileNotFoundException("I couldn't find java install"); return value; } } private static string GetJavaHomeFromRegistry(string javaKey, RegistryView registryView) { using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView).OpenSubKey(javaKey)) { if (baseKey != null) { string currentVersion = baseKey.GetValue("CurrentVersion").ToString(); using (var homeKey = baseKey.OpenSubKey(currentVersion)) return homeKey.GetValue("JavaHome").ToString(); } } return null; }
--
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/yJR7ezuDqu4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
-mike
I've just installed the antlr extension into vs 2012 pro and i'm not sure what it is that i'm supposed to see. is it supposed to give me new project templates? if so, it doesn't. when I open a .g or g4 file it appears to colorize it properly as well as intellisense etc, however i'm unsure how to create the lexer/parser files for c#.
I've tried adding a .g file to a dll project and it seems to adjust the build info for the file, but that's about it. is there a walkthrough or something I can look at that might explain the workings in vs a bit better? so far I haven't found anything..
I don't have the code or dll anymore but I think that the issue was corrected.
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/yJR7ezuDqu4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
Hi Ignazio,
Here are more recent instructions.
https://github.com/sharwell/antlr4cs/wiki/Installation
Sam