Merge pull request #1522 from parrt/ericvergnaud-publish-to-nuget

Ericvergnaud publish to nuget
This commit is contained in:
Terence Parr 2016-12-15 13:32:21 -08:00 committed by GitHub
commit d388e6b867
7 changed files with 133 additions and 47 deletions

View File

@ -1,8 +1,6 @@
# C♯
See also [Sam Harwell's Alternative C# target](https://github.com/tunnelvisionlabs/antlr4cs)
### Which frameworks are supported?
## Which frameworks are supported?
The C# runtime is CLS compliant, and only requires a corresponding 3.5 .Net framework.
@ -13,19 +11,15 @@ In practice, the runtime has been extensively tested against:
No issue was found, so you should find that the runtime works pretty much against any recent .Net framework.
### How do I get started?
## How do I get started?
You will find full instructions on the Git web page for ANTLR C# runtime.
You will find full instructions on the [Git repo page for ANTLR C# runtime](https://github.com/antlr/antlr4/tree/master/runtime/CSharp).
### How do I use the runtime from my project?
## How do I use the runtime from my project?
(i.e., How do I run the generated lexer and/or parser?)
Let's suppose that your grammar is named, as above, "MyGrammar".
Let's suppose this parser comprises a rule named "StartRule"
The tool will have generated for you the following files:
Let's suppose that your grammar is named `MyGrammar`. The tool will generate for you the following files:
* MyGrammarLexer.cs
* MyGrammarParser.cs
@ -34,7 +28,7 @@ The tool will have generated for you the following files:
* MyGrammarVisitor.js (if you have activated the -visitor option)
* MyGrammarBaseVisitor.js (if you have activated the -visitor option)
Now a fully functioning code might look like the following:
Now a fully functioning code might look like the following for start rule `StartRule`:
```
using Antlr4.Runtime;
@ -58,7 +52,7 @@ This program will work. But it won't be useful unless you do one of the followin
(please note that production code is target specific, so you can't have multi target grammars that include production code)
### How do I create and run a custom listener?
## How do I create and run a custom listener?
Let's suppose your MyGrammar grammar comprises 2 rules: "key" and "value".
@ -96,4 +90,5 @@ ParseTreeWalker.DEFAULT.walk(printer, tree);
Further information can be found from The Definitive ANTLR Reference book.
The C# implementation of ANTLR is as close as possible to the Java one, so you shouldn't find it difficult to adapt the examples for C#.
The C# implementation of ANTLR is as close as possible to the Java one, so you shouldn't find it difficult to adapt the examples for C#. See also [Sam Harwell's alternative C# target](https://github.com/tunnelvisionlabs/antlr4cs)

View File

@ -229,6 +229,70 @@ popd
### CSharp
*Publishing to Nuget from Linux/MacOSX*
**Getting ready to run Nuget**
Of course you need Mono and `nuget` to be installed. On mac:
```bash
brew install mono
brew install nuget
```
Or, you can [download nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe).
From the shell on mac, you can check all is ok by typing
```bash
nuget
```
This should display the nuget help.
**Creating the assembly**
```bash
$ cd runtime/CSharp/runtime/CSharp/Antlr4.Runtime
$ xbuild /p:Configuration=Release Antlr4.Runtime.mono.csproj
...
Copying file from '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.Standard.dll' to '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/lib/Release/Antlr4.Runtime.Standard.dll'
Done building project "/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.mono.csproj".
```
Alternately, you may want to build ANTLR using Xamarin Studio Community (free).
**Packaging for NuGet**
```bash
cd runtime/CSharp/runtime/CSharp
```
which is where the `Package.nuspec` file resides.
Type the following command:
```bash
$ nuget pack Package.nuspec
Attempting to build package from 'Package.nuspec'.
Successfully created package '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime.Standard.4.6.0.nupkg'.
```
This should display: Successfully created package *<package-path>*
**Publishing to NuGet**
You need to be a NuGet owner for "ANTLR 4 Standard Runtime"
As a registered NuGet user, you can then manually upload the package spec here (`runtime/CSharp/runtime/CSharp/Package.nuspec`): [https://www.nuget.org/packages/manage/upload](https://www.nuget.org/packages/manage/upload)
Alternately, you can publish from the cmd line. You need to get your NuGet key from [https://www.nuget.org/account#](https://www.nuget.org/account#) and then from the cmd line, you can then type:
```bash
nuget push Antlr4.Runtime.Standard.<version>.nupkg <your-key> -Source https://www.nuget.org/api/v2/package
```
**Creating DLLs**
```bash
cd ~/antlr/code/antlr4/runtime/CSharp/runtime/CSharp
# kill previous ones manually as "xbuild /t:Clean" didn't seem to do it

View File

@ -1,11 +1,18 @@
# C# target for ANTLR 4
### Note to existing users
### Note to historical users
Versions of ANTLR 4.4.x and before managed the C# target as a [separate tool provided by Sam Harwell](https://github.com/tunnelvisionlabs/antlr4cs/releases/tag/v4.3.0). As of 4.5, we our releasing a (mono-compatible) C# target derived from Sam's with the main tool. ANTLR 4.5 is now able to generate C#, Java, Python 2, Python 3 and JavaScript. Sam continues to work on his version of the ANTLR tool and so a C# target is also available through that.
Versions of ANTLR 4.4.x and before managed the C#
target as part of a [separate tool provided by Sam Harwell](https://github.com/tunnelvisionlabs/antlr4cs/releases/tag/v4.3.0).
As of 4.5, we our releasing a (mono-compatible) C# target together
with the main tool.
This makes it possible to use ANTLR 4 in any C# development environment, including of course Microsoft Visual Studio, but also Xamarin Studio, which runs on MacOS X.
Given Microsoft's recent commitment to *cross-platform developer experiences*, we believe this is a great opportunity for C# developers.
Mono compatibility makes it possible to use ANTLR 4 in any C# development
environment, including of course Microsoft Visual Studio, but also Xamarin Studio, which runs on MacOS X.
Given Microsoft's recent commitment to *cross-platform developer experiences*,
we believe this is a great opportunity for C# developers.
Releasing the runtime with the tool ensures that you can get the exact same behavior across many languages: Java, C#, Python, JavaScript, Go, Swift and C++.
## Getting Started
@ -16,39 +23,37 @@ You can install *any* of the following versions of Java to use this target.
If you already have one of the following installed, you should check to make sure the installation is up-to-date.
* Java 8 runtime environment (x86 or x64)
* Java 8 development kit (x86 or x64, provided that the JRE option is also installed during the development kit installation)
* Java 7 runtime environment (x86 or x64)
* Java 7 development kit (x86 or x64, provided that the JRE option is also installed during the development kit installation)
* Java 6 runtime environment (x86 or x64)
* Java 6 development kit (x86 or x64, provided that the JRE option is also installed during the development kit installation)
### Step 2: Download the tool and runtime, and install the runtime
### Step 2: Download the tool
You need to download the following from the ANTLR web site:
You need to download the ANTLR tool from the ANTLR web site.
This is a Java archive (*.jar) used to generate the C# code from an ANTLR grammar.
1. The ANTLR tool. This is a Java archive (*.jar) used to generate the C# code from an ANTLR grammar.
2. The ANTLR runtime assembly. This is a regular .Net assembly (*.dll).
You then need to install the runtime assembly in the GAC.
This is required to easily reference the runtime from your project.
Go the the directory where you downloaded the runtime, and type the following command:
`gacutil -i Antlr4.Runtime.dll`
### Step 3: Add a reference to the ANTLR runtime in your project
We trust that you know how to do this :-).
### Step 4: Add or create a grammar file (*.g4) in your project
### Step 3: Add or create a grammar file (*.g4) in your project
To avoid confusing your IDE, we suggest setting the build action to None for this file.
See the docs and the book to learn about writing lexer and parser grammars.
### Step 5: Generate the C# code
This can be done either from the cmd line, or by adding a custom pre-build command.
At minimal, the cmd line should look as follows: ``java -jar antlr4-4.5.jar -Dlanguage=CSharp grammar.g4``
### Step 4: Generate the C# code
This can be done either from the cmd line, or by adding a custom pre-build command in your project.
At minimal, the cmd line should look as follows: ``java -jar antlr4-4.6.jar -Dlanguage=CSharp grammar.g4``
This will generate the files, which you can then integrate in your project.
This is just a quick start. The tool has many useful options to control generation, please refer to its documentation.
### Step 5: Add a reference to the ANTLR runtime in your project
The Antlr 4 standard runtime for C# is now available from NuGet.
We trust that you know how to do add NuGet references to your project :-).
The package id is Antlr.4.Runtime. We do not support other packages.
### Step 6: You're done!
Of course, the generated code is not going to meet your requirement by magic.
@ -60,10 +65,10 @@ While the latter works, it is no longer the recommended approach, because it is
See the web site for examples of using the generated code.
To learn more about ANTLR 4, read the book.
To learn more about ANTLR 4, read [the book](http://a.co/2n4rJlb).
### Visual Studio integration
If you require tighter Visual Studio integration, you can use the tools from Tunnel Vision Labs.
If you require tighter Visual Studio integration, you can use the tools from [Tunnel Vision Labs](http://tunnelvisionlabs.com/).
(please note however that they use a different tool and runtime)

View File

@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Antlr4.Runtime</RootNamespace>
<AssemblyName>Antlr4.Runtime</AssemblyName>
<AssemblyName>Antlr4.Runtime.Standard</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<BaseIntermediateOutputPath>obj\net20\</BaseIntermediateOutputPath>
@ -21,7 +21,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\net35\Debug\</OutputPath>
<OutputPath>lib\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;NET35PLUS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@ -29,7 +29,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\net35\Release\</OutputPath>
<OutputPath>lib\Release</OutputPath>
<DefineConstants>TRACE;NET35PLUS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>

View File

@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Antlr4.Runtime</RootNamespace>
<AssemblyName>Antlr4.Runtime</AssemblyName>
<AssemblyName>Antlr4.Runtime.Standard</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<BaseIntermediateOutputPath>obj\net35\</BaseIntermediateOutputPath>

View File

@ -5,8 +5,6 @@ VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{47C0086D-577C-43DA-ADC7-544F27656E45}"
ProjectSection(SolutionItems) = preProject
..\..\tool\resources\org\antlr\v4\tool\templates\codegen\CSharp\CSharp.stg = ..\..\tool\resources\org\antlr\v4\tool\templates\codegen\CSharp\CSharp.stg
..\..\tool\src\org\antlr\v4\codegen\CSharpTarget.java = ..\..\tool\src\org\antlr\v4\codegen\CSharpTarget.java
..\..\Readme.md = ..\..\Readme.md
EndProjectSection
EndProject

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Antlr4.Runtime.Standard</id>
<version>4.6.0</version>
<language>en-us</language>
<title>ANTLR 4 Standard Runtime</title>
<description>The standard C# ANTLR 4 runtime from the ANTLR Organization</description>
<summary>The runtime library for parsers generated by the C# target of the standard ANTLR 4 tool.</summary>
<authors>Eric Vergnaud, Terence Parr, Sam Harwell</authors>
<owners>The ANTLR Organization</owners>
<releaseNotes>https://github.com/antlr/antlr4/releases</releaseNotes>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<licenseUrl>https://github.com/antlr/antlr4/blob/master/LICENSE.txt</licenseUrl>
<projectUrl>https://github.com/antlr/antlr4</projectUrl>
<iconUrl>https://raw.github.com/antlr/website-antlr4/master/images/icons/antlr.png</iconUrl>
<copyright>Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.</copyright>
<tags>antlr parsing grammar</tags>
<dependencies />
</metadata>
<files>
<file src="Antlr4.Runtime/lib/Release/Antlr4.Runtime.Standard.dll" target="lib/net35/"/>
</files>
</package>