Created a new .NET Core project for the C# runtime of Antlr4.

This commit is contained in:
David Neumann 2016-07-07 17:19:17 +02:00
parent 47e268dfea
commit 10270a8c77
21 changed files with 3604 additions and 11 deletions

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>12962409-846e-4b80-933a-bc484d264132</ProjectGuid>
<RootNamespace>Antlr4.Runtime.DotNetCore</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -44,7 +44,9 @@ namespace Antlr4.Runtime.Atn
/// utility methods for analyzing configuration sets for conflicts and/or
/// ambiguities.
/// </remarks>
#if !DOTNETCORE
[System.Serializable]
#endif
public sealed class PredictionMode
{
/// <summary>The SLL(*) prediction mode.</summary>

View File

@ -34,7 +34,9 @@ using Antlr4.Runtime.Sharpen;
namespace Antlr4.Runtime
{
#if !DOTNETCORE
[System.Serializable]
#endif
public class CommonToken : IWritableToken
{
private const long serialVersionUID = -6708843461296520577L;

View File

@ -34,7 +34,7 @@ using Antlr4.Runtime.Dfa;
using Antlr4.Runtime.Sharpen;
using Interlocked = System.Threading.Interlocked;
#if NET45PLUS
#if NET45PLUS || DOTNETCORE
using Volatile = System.Threading.Volatile;
#elif !PORTABLE && !COMPACT
using Thread = System.Threading.Thread;
@ -60,7 +60,7 @@ namespace Antlr4.Runtime.Dfa
{
get
{
#if NET45PLUS
#if NET45PLUS || DOTNETCORE
return Volatile.Read(ref size);
#elif !PORTABLE && !COMPACT
return Thread.VolatileRead(ref size);

View File

@ -42,7 +42,9 @@ namespace Antlr4.Runtime
/// Disambiguating predicate evaluation occurs when we test a predicate during
/// prediction.
/// </remarks>
#if !DOTNETCORE
[System.Serializable]
#endif
public class FailedPredicateException : RecognitionException
{
private const long serialVersionUID = 5379330841495778709L;

View File

@ -40,7 +40,9 @@ namespace Antlr4.Runtime
/// This signifies any kind of mismatched input exceptions such as
/// when the current input does not match the expected token.
/// </remarks>
#if !DOTNETCORE
[System.Serializable]
#endif
public class InputMismatchException : RecognitionException
{
private const long serialVersionUID = 1532568338707443067L;

View File

@ -35,7 +35,9 @@ using Antlr4.Runtime.Sharpen;
namespace Antlr4.Runtime
{
#if !DOTNETCORE
[System.Serializable]
#endif
public class LexerNoViableAltException : RecognitionException
{
private const long serialVersionUID = -730999203913001726L;

View File

@ -34,7 +34,9 @@ using Antlr4.Runtime.Sharpen;
namespace Antlr4.Runtime.Misc
{
#if !DOTNETCORE
[System.Serializable]
#endif
public class MultiMap<K, V> : Dictionary<K, IList<V>>
{
private const long serialVersionUID = -4956746660057462312L;

View File

@ -48,7 +48,9 @@ namespace Antlr4.Runtime.Misc
/// response to a parse error.
/// </remarks>
/// <author>Sam Harwell</author>
#if !DOTNETCORE
[System.Serializable]
#endif
public class ParseCanceledException : OperationCanceledException
{
public ParseCanceledException()

View File

@ -671,7 +671,11 @@ namespace Antlr4.Runtime.Misc
StringBuilder errors = new StringBuilder();
foreach (Tuple<RuleDependencyAttribute, ICustomAttributeProvider> dependency in dependencies)
{
if (!dependency.Item1.Recognizer.IsAssignableFrom(recognizerType))
#if DOTNETCORE
if (!dependency.Item1.Recognizer.GetTypeInfo().IsAssignableFrom(recognizerType))
#else
if (!dependency.Item1.Recognizer.IsAssignableFrom(recognizerType))
#endif
{
continue;
}
@ -798,7 +802,11 @@ namespace Antlr4.Runtime.Misc
private static int[] GetRuleVersions(Type recognizerClass, string[] ruleNames)
{
int[] versions = new int[ruleNames.Length];
#if DOTNETCORE
FieldInfo[] fields = recognizerClass.GetTypeInfo().GetFields();
#else
FieldInfo[] fields = recognizerClass.GetFields();
#endif
foreach (FieldInfo field in fields)
{
bool isStatic = field.IsStatic;
@ -830,7 +838,11 @@ namespace Antlr4.Runtime.Misc
#endif
continue;
}
#if DOTNETCORE
RuleVersionAttribute ruleVersion = ruleMethod.GetCustomAttribute<RuleVersionAttribute>();
#else
RuleVersionAttribute ruleVersion = (RuleVersionAttribute)Attribute.GetCustomAttribute(ruleMethod, typeof(RuleVersionAttribute));
#endif
int version = ruleVersion != null ? ruleVersion.Version : 0;
versions[index] = version;
}
@ -857,10 +869,18 @@ namespace Antlr4.Runtime.Misc
private static MethodInfo GetRuleMethod(Type recognizerClass, string name)
{
#if DOTNETCORE
MethodInfo[] declaredMethods = recognizerClass.GetTypeInfo().GetMethods();
#else
MethodInfo[] declaredMethods = recognizerClass.GetMethods();
#endif
foreach (MethodInfo method in declaredMethods)
{
if (method.Name.Equals(name) && Attribute.IsDefined(method, typeof(RuleVersionAttribute)))
#if DOTNETCORE
if (method.Name.Equals(name) && method.IsDefined(typeof(RuleVersionAttribute)))
#else
if (method.Name.Equals(name) && Attribute.IsDefined(method, typeof(RuleVersionAttribute)))
#endif
{
return method;
}
@ -870,7 +890,11 @@ namespace Antlr4.Runtime.Misc
private static string[] GetRuleNames(Type recognizerClass)
{
#if DOTNETCORE
FieldInfo ruleNames = recognizerClass.GetTypeInfo().GetField("ruleNames");
#else
FieldInfo ruleNames = recognizerClass.GetField("ruleNames");
#endif
return (string[])ruleNames.GetValue(null);
}
@ -878,20 +902,36 @@ namespace Antlr4.Runtime.Misc
{
IList<Tuple<RuleDependencyAttribute, ICustomAttributeProvider>> result = new List<Tuple<RuleDependencyAttribute, ICustomAttributeProvider>>();
#if DOTNETCORE
GetElementDependencies(AsCustomAttributeProvider(clazz.GetTypeInfo()), result);
#else
GetElementDependencies(AsCustomAttributeProvider(clazz), result);
#endif
#if DOTNETCORE
foreach (ConstructorInfo ctor in clazz.GetTypeInfo().GetConstructors(AllDeclaredMembers))
#else
foreach (ConstructorInfo ctor in clazz.GetConstructors(AllDeclaredMembers))
#endif
{
GetElementDependencies(AsCustomAttributeProvider(ctor), result);
foreach (ParameterInfo parameter in ctor.GetParameters())
GetElementDependencies(AsCustomAttributeProvider(parameter), result);
}
#if DOTNETCORE
foreach (FieldInfo field in clazz.GetTypeInfo().GetFields(AllDeclaredMembers))
#else
foreach (FieldInfo field in clazz.GetFields(AllDeclaredMembers))
#endif
{
GetElementDependencies(AsCustomAttributeProvider(field), result);
}
#if DOTNETCORE
foreach (MethodInfo method in clazz.GetTypeInfo().GetMethods(AllDeclaredMembers))
#else
foreach (MethodInfo method in clazz.GetMethods(AllDeclaredMembers))
#endif
{
GetElementDependencies(AsCustomAttributeProvider(method), result);
#if COMPACT
@ -947,12 +987,21 @@ namespace Antlr4.Runtime.Misc
private static string GetSerializedATN(Type recognizerClass)
{
#if DOTNETCORE
FieldInfo serializedAtnField = recognizerClass.GetTypeInfo().GetField("_serializedATN", AllDeclaredStaticMembers);
#else
FieldInfo serializedAtnField = recognizerClass.GetField("_serializedATN", AllDeclaredStaticMembers);
#endif
if (serializedAtnField != null)
return (string)serializedAtnField.GetValue(null);
#if DOTNETCORE
if (recognizerClass.GetTypeInfo().BaseType != null)
return GetSerializedATN(recognizerClass.GetTypeInfo().BaseType);
#else
if (recognizerClass.BaseType != null)
return GetSerializedATN(recognizerClass.BaseType);
#endif
return null;
}

View File

@ -44,7 +44,9 @@ namespace Antlr4.Runtime
/// of the offending input and also knows where the parser was
/// in the various paths when the error. Reported by reportNoViableAlternative()
/// </remarks>
#if !DOTNETCORE
[System.Serializable]
#endif
public class NoViableAltException : RecognitionException
{
private const long serialVersionUID = 5096000008992867052L;

View File

@ -43,7 +43,9 @@ namespace Antlr4.Runtime
/// in the input, where it is in the ATN, the rule invocation stack,
/// and what kind of problem occurred.
/// </remarks>
#if !DOTNETCORE
[System.Serializable]
#endif
public class RecognitionException : Exception
{
private const long serialVersionUID = -3861826954750022374L;

View File

@ -22,7 +22,7 @@
//
//
#if !NET40PLUS || (PORTABLE && !WINRT)
#if (!NET40PLUS && !DOTNETCORE) || (PORTABLE && !WINRT)
using System;
using System.Threading;

View File

@ -28,7 +28,9 @@ using System;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
#if !DOTNETCORE
using System.Runtime.Serialization;
#endif
namespace Antlr4.Runtime.Sharpen
{

View File

@ -26,7 +26,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !NET40PLUS
#if !NET40PLUS && !DOTNETCORE
using System;

View File

@ -27,7 +27,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if !NET40PLUS
#if !NET40PLUS && !DOTNETCORE
using System;
using System.Collections;

View File

@ -155,7 +155,9 @@ namespace Antlr4.Runtime.Tree.Pattern
/// </summary>
public class ParseTreePatternMatcher
{
#if !DOTNETCORE
[System.Serializable]
#endif
public class CannotInvokeStartRule : Exception
{
public CannotInvokeStartRule(Exception e)
@ -164,7 +166,9 @@ namespace Antlr4.Runtime.Tree.Pattern
}
}
#if !DOTNETCORE
[System.Serializable]
#endif
public class StartRuleDoesNotConsumeFullPattern : Exception
{
// Fixes https://github.com/antlr/antlr4/issues/413

View File

@ -43,7 +43,9 @@ namespace Antlr4.Runtime.Tree.Pattern
/// chunks where the
/// tag corresponds to a lexer rule or token type.
/// </summary>
#if !DOTNETCORE
[System.Serializable]
#endif
public class TokenTagToken : CommonToken
{
/// <summary>

View File

@ -0,0 +1,14 @@
{
"buildOptions": {
"define": [ "DEBUG", "TRACE", "DOTNETCORE" ]
},
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.5": {
"imports": "dnxcore50"
}
},
"version": "4.5.3-*"
}

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{47C0086D-577C-43DA-ADC7-544F27656E45}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antlr4.Runtime.vs2013", "Antlr4.Runtime\Antlr4.Runtime.vs2013.csproj", "{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Antlr4.Runtime.DotNetCore", "Antlr4.Runtime\Antlr4.Runtime.DotNetCore.xproj", "{12962409-846E-4B80-933A-BC484D264132}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -17,6 +17,10 @@ Global
{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}.Release|Any CPU.Build.0 = Release|Any CPU
{12962409-846E-4B80-933A-BC484D264132}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12962409-846E-4B80-933A-BC484D264132}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12962409-846E-4B80-933A-BC484D264132}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12962409-846E-4B80-933A-BC484D264132}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE