How to compile .g4 to .cs? - c#

I reread all documentations but still didn't get what exactly do I need to do. Please explain step by step what do I need to do to set up work with Antlr in VS2019 (for C#) and how can I compile .g4 to .cs after. Do I need to install Antlr4 or Antlr4.Runtime or Antlr4.Runtime.Standard? Do I need to download "antlr-4.8-complete.jar" file from official site? If so, what should I do with it after? In general, as you can see, I'm confused in it.

I recommend this way--not because I wrote the software--but because it is easy and uses the most up-to-date release of Antlr:
Install the NET SDK (aka "dotnet.exe").
dotnet new -i Antlr4BuildTasks.Templates
dotnet new antlr
dotnet build
dotnet run
You can then open VS2019 or VSCode on the .csproj. See Antlr4BuildTasks.Templates. It uses Antlr4BuildTask for building. You don't need to install Java nor Antlr--it includes a copy of the Java JRE and Antlr. But, you will need connectivity to NuGet.org.
If for whatever reason you need to generate the .cs files outside of a build, then you can type it in from a shell:
java -jar ~/Downloads/antlr-4.8-complete.jar -Dlanguage=CSharp *.g4
Note, Antlr4.Runtime.Standard is the current Antlr runtime for C# as a netstandard1.3;net35 package. Antlr4.Runtime is Harwell's port of the entire Antlr Java code and runtime v4.6.6 to C#, and, as far as I know, it is not being maintained. There is a tool in that package that is the equivalent to the Java-based Antlr tool, so you can use that in a similar way. But, it is roughly 3 years behind the current release v4.8--soon to be v4.9. The Antlr4BuildTasks package I wrote is a modification of Harwell's package, but instead calls the Java-based Antlr tool.
Support within an editor for Antlr in VS2019, VSCode, or what have you, for syntactic or semantic highlighting, goto refs, goto def, etc., should be considered separate from the build of your app. Harwell's extension is for VS2017. For VSCode, you have the choice of Mike's vscode-antlr or my LSP-based tool Antlrvsix-vscode. For VS2019, you can use my extension Antlrvsix, or one of the few unsupported and very old extensions. Or, you can skip all that, and just edit it as text.

Related

How can I configure OmniSharp to support intellisense for C# without the use of .NET Core or MSBuild configuration files?

I am referencing Gtk# and building using Mono, writing my code in VS Code (code.visualstudio.com). I'd like intellisense for C#. By "intellisense" I mean the correct functions, members, etc. come up with "." - this is separate from predictive suggestions based on other code in the file.
I have tried both the current Microsoft C# extension (https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) as well as the Legacy Microsoft C# extension (https://marketplace.visualstudio.com/items?itemName=ms-vscode.omnisharp).
Both of these appear to use OmniSharp as the means for providing intellisense, and both either load MS Build files and/or "project.json" files.
The current Microsoft C# extension seems to use "project.json" files which appear to follow a schema specifically for .NET Core. I tried to leverage this anyway by creating a local GtkSharp NuGet package out of the Mono DLLs, but I could not then "dotnet restore" because these NuGet packages were incompatible with .NET Core. I followed: https://docs.nuget.org/ndocs/hosting-packages/local-feeds and https://docs.nuget.org/ndocs/create-packages/creating-a-package
The Legacy Microsoft C# extension works if I use Visual Studio to generate solution (.sln) and project (.csproj) files. VS Code then recognizes these files and uses intellisense properly. Trying to hand-roll solution and project files failed because there seem to be a lot of entries OmniSharp is looking for when setting up using this method.
Fundamentally, I want to provide a simple lightweight configuration which says: "Here is my code (.cs files), and here are the assemblies I reference (.dlls) as well as their comment files (.xml)" - and then have VS Code provide intellisense for those files and referenced assemblies. The .NET Core "project.json" files are simple enough, but are incompatible. The MS Build files are significantly more complicated than what I am looking for and require Visual Studio (or maybe a much deeper knowledge of MS Build) to generate OmniSharp compatible files. I'm looking for a separation between build configuration and intellisense configuration.
How can I configure VS code to support intellisense for C# without the use of .NET Core or MSBuild?
This has nothing to do with build systems, and strictly relates to providing intellisense support using one of the OmniSharp-based C# VS Code extensions provided by Microsoft without the use of "project.json" or MS Build configuration files.

How to use Xamarin without the IDE?

I want to write an iOS app in C# with Xamarin and MonoTouch. I want to use Vim and Z shell instead of Xamarin Studio. However, I can't find much documentation on how to build from the command-line.
The documentation for the mtouch command says you have to pass an assembly as an argument, but how do I create that assembly?
The command line compilers that Mono provides are mcs, gmcs, and dmcs. For Mono 2.10.x and earlier, these are for C# 1.0, C# 2.0, and C# 4.0, respectively; for Mono 3.0.x, mcs defaults to the most recent version, and you have to select earlier language/runtime versions with the -langversion and -sdk options. The dmcs and gmcs commands in 3.0.x are scripts that call mcs with the appropriate -sdk option.
I am not sufficiently familiar with Xamarin.iOS to know how the libraries are laid out, but the -lib option allows you to tell the compiler about additional directories containing .dll assemblies and -r allows you to reference a specific assembly. The compiler will build a .exe assembly by default; use -target:library or -t:library to build a .dll one instead. The -help option will give you a list of all options.
You can use whatever build system you prefer from the command line. If you need to process MSBuild project files, then xbuild can handle them, but make, cmake, scons work fine, too, and are probably preferable to editing .sln files in Vim. You may still have to figure out dependencies yourself if they aren't obvious and if you have a complex project with multiple assemblies (the compiler is fast enough that you can just recompile everything for small single-assembly projects).
Note that I am not using Mono for this myself, but primarily for command line projects on OS X/Linux, so the above may be missing some subtle details related to building mtouch-ready assemblies for iOS.

ASP.NET sass/scss compilation at run-time and at compile-time?

I am searching for a solution for compiling my .scss files at run-time and at compile-time.
The reason I need both is that our designers work on Macs and prefer the ease of having their .scss files compiled dynamically at run-time (especially during a development phase). On the other hand, I need compile-time support to validate that the SCSS compiles successfully during my build process. My goal is to fail a build if the SCSS doesn't compile.
I have found several libraries available on NuGet, however, minor flaws in each of them are holding me back.
Is there a solution available for both of these scenarios?
Here's where my research has led me:
Run-time Support
BundleTransformer.SassAndScss via HttpHandler (works with Bourbon, albeit very slow)
Cassette.Sass (unable to compile Bourbon due to error)
Compile-time support:
Cassette.MSBuild (Does not appear to bundle SCSS files, only CSS)
Mindscape Web Workbench (Pro version apparently includes a command-line tool, however, documentation is very limited on the feature)
Others?
The Pro edition of the Mindscape Web Workbench includes a command-line tool for compiling at runtime. Currently, only the nightly build is capable of compiling Bourbon and Neat (one of my requirements).
Here is my pre-build event which is working great at the moment:
"C:\Program Files (x86)\Mindscape\Web Workbench\Command Line\wwcmd.exe"
"$(ProjectDir)scss\style.scss" /o:../css /style:compressed
UPDATE:
We decided to simply call SASS from a pre-build event as opposed to using Web Workbench.
call sass -C "$(ProjectDir)assets\scss\main.scss" "$(ProjectDir)assets\css\compiled\main.css" --style compressed
Check out SassAndCoffee. It's what Cassette is using and it embeds everything into a few assemblies.
Web Workbench on the other hand actually installs ruby and the sass gems to the file system in a very long folder path hidden beneath the current users directory, which is likely to be troublesome for a web application and with respect to security and permissions.
For ASP.NET Core you can use this package to compile scss at build time and it includes a watcher for debug-time and hot-reloading.
AspNetCore.SassCompiler
Sass Compiler Library for .NET Core 3.1/5.x./6.x without node.
https://github.com/koenvzeijl/AspNetCore.SassCompiler
# Package Manager
PM> Install-Package AspNetCore.SassCompiler
# .NET CLI
dotnet add package AspNetCore.SassCompiler

How can I get/run the 'gsharp' GUI wrapper for the csharp REPL in Mono?

Mono's C# REPL has on its page this bit of info:
A GUI version of this tool is called gsharp and is available when you install the mono-tools package
The same bit of info is mentioned in the Mono 2.2 release notes.
However, while I've installed the 30-day trial of mono-tools (vsix for VS2010), and the normal Mono for Windows package (2.10.8), I don't see anything in either that lets me open the window from the screen shot "C# InteractiveBase Shell". I also can't find any files on my disk (after installing both) starting with 'gsharp'
Did 'gsharp' move somewhere else?
I know the source is available as part of the mono-tools repo # https://github.com/mono/mono-tools/tree/master/gsharp, but just trying to find a 'release build' to use instead if possible. :)
Mono-tools for Visual Studio is a former product of Novell, which is discontinued (which Xamarin doesn't offer either).
I recommend you try to install Mono for Windows official bundle from http://www.mono-project.com/ If that installer doesn't include it, I recommend you compile mono-tools yourself, shouldn't be very hard with cygwin or mingw32.
PS: Note, "Mono tools for Visual Studio" and the "mono-tools" module (https://github.com/mono/mono-tools) are two different things.
(BTW, Mono 2.2 is very old. Only accept Mono 2.10.x or higher nowadays)

Makefile for C# console programs

How can I write a Makefile (gnu make) to compile a C# console project that has several files. I understand that there are other build tools, but my course requirements force me to submit a makefile.
You can simply use the compiler for the C#, with providing right arguments to it.
Here you can find examples
According to MSDN:
If you are working on a computer that only has the Windows Software Development Kit (SDK),
you can use the C# compiler at the command line if you use the SDK Command Prompt, which is
available from the Microsoft .NET Framework SDK menu option.
Or simply install the .NET Framework (thank to the #Alexei Levenkov).
If you have a Visual Studio installed just create a batch file and call
devenv your_project_complete_path
Or use MsBuild as provided in sample.
or use csc as provided in sample.

Categories