Skip to content

Commit

Permalink
HRON basic parser now supports NET2.0. In addition added help functio…
Browse files Browse the repository at this point in the history
…ns to help backmigrate code to NET2.0.
  • Loading branch information
mrange committed Dec 16, 2012
1 parent 7eb2320 commit eb0a4a0
Show file tree
Hide file tree
Showing 19 changed files with 1,697 additions and 91 deletions.
13 changes: 12 additions & 1 deletion Extensions/NumericalExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------

// ### INCLUDE: ../Common/Config.cs


Expand Down
24 changes: 11 additions & 13 deletions Extensions/NumericalExtensions.tt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<#
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------
#>
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------

// ### INCLUDE: ../Common/Config.cs

Expand Down
14 changes: 7 additions & 7 deletions Hron/HRONSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ void WriteLine (StringBuilder line)

public void PreProcessor(SubString line)
{
m_sb.Clear();
m_sb.Remove(0, m_sb.Length);
m_sb.Append('!');
m_sb.AppendSubString(line);
WriteLine(m_sb);
}

public void Empty (SubString line)
{
m_sb.Clear();
m_sb.Remove(0, m_sb.Length);
m_sb.AppendSubString(line);
WriteLine(m_sb);
}

public void Comment(int indent, SubString comment)
{
m_sb.Clear();
m_sb.Remove(0, m_sb.Length);
m_sb.Append('\t', indent);
m_sb.Append('#');
m_sb.AppendSubString(comment);
Expand All @@ -95,7 +95,7 @@ public void Comment(int indent, SubString comment)

public void Value_Begin(SubString name)
{
m_sb.Clear();
m_sb.Remove(0, m_sb.Length);
m_sb.Append('\t', m_indent);
m_sb.Append('=');
m_sb.Append(name);
Expand All @@ -105,7 +105,7 @@ public void Value_Begin(SubString name)

public void Value_Line(SubString value)
{
m_sb.Clear();
m_sb.Remove(0, m_sb.Length);
m_sb.Append('\t', m_indent);
m_sb.AppendSubString(value);
WriteLine(m_sb);
Expand All @@ -118,7 +118,7 @@ public void Value_End(SubString name)

public void Object_Begin(SubString name)
{
m_sb.Clear();
m_sb.Remove(0, m_sb.Length);
m_sb.Append('\t', m_indent);
m_sb.Append('@');
m_sb.AppendSubString(name);
Expand All @@ -133,7 +133,7 @@ public void Object_End(SubString name)

public void Error(int lineNo, SubString line, HRONSerializer.ParseError parseError)
{
m_sb.Clear();
m_sb.Remove(0, m_sb.Length);
m_sb.AppendFormat(Config.DefaultCulture, "# Error at line {0}: {1}", lineNo, parseError);
WriteLine(m_sb);
}
Expand Down
24 changes: 24 additions & 0 deletions NET20/Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------

// ### INCLUDE: Generated_Common.cs

namespace System.Runtime.CompilerServices
{
using System;

sealed class ExtensionAttribute : Attribute
{

}
}

96 changes: 96 additions & 0 deletions NET20/Generated_Common.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------

// ############################################################################
// # #
// # ---==> T H I S F I L E I S G E N E R A T E D <==--- #
// # #
// # This means that any edits to the .cs file will be lost when its #
// # regenerated. Changes should instead be applied to the corresponding #
// # template file (.tt) #
// ############################################################################






namespace System
{
public delegate TResult Func<out TResult> ();
public delegate TResult Func<in T0, out TResult> (T0 v0);

public delegate void Action<
in T0
, in T1
> (
T0 v0
, T1 v1
);

public delegate TResult Func<
in T0
, in T1
, out TResult
> (
T0 v0
, T1 v1
);

public delegate void Action<
in T0
, in T1
, in T2
> (
T0 v0
, T1 v1
, T2 v2
);

public delegate TResult Func<
in T0
, in T1
, in T2
, out TResult
> (
T0 v0
, T1 v1
, T2 v2
);

public delegate void Action<
in T0
, in T1
, in T2
, in T3
> (
T0 v0
, T1 v1
, T2 v2
, T3 v3
);

public delegate TResult Func<
in T0
, in T1
, in T2
, in T3
, out TResult
> (
T0 v0
, T1 v1
, T2 v2
, T3 v3
);


}
77 changes: 77 additions & 0 deletions NET20/Generated_Common.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------

<#@ include file = "..\T4\Header.ttinclude" #>

<#
var count = 5;
#>

namespace System
{
public delegate TResult Func<out TResult> ();
public delegate TResult Func<in T0, out TResult> (T0 v0);

<#
for (var iter = 2; iter < count; ++iter)
{
#>
public delegate void Action<
in T0
<#
for (var inner = 1; inner < iter; ++inner)
{
#>
, in T<#=inner#>
<#
}
#>
> (
T0 v0
<#
for (var inner = 1; inner < iter; ++inner)
{
#>
, T<#=inner#> v<#=inner#>
<#
}
#>
);

public delegate TResult Func<
in T0
<#
for (var inner = 1; inner < iter; ++inner)
{
#>
, in T<#=inner#>
<#
}
#>
, out TResult
> (
T0 v0
<#
for (var inner = 1; inner < iter; ++inner)
{
#>
, T<#=inner#> v<#=inner#>
<#
}
#>
);

<#
}
#>

}
52 changes: 52 additions & 0 deletions NET20/LINQ.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// ----------------------------------------------------------------------------------------------
// Copyright (c) Mårten Rånge.
// ----------------------------------------------------------------------------------------------
// This source code is subject to terms and conditions of the Microsoft Public License. A
// copy of the license can be found in the License.html file at the root of this distribution.
// If you cannot locate the Microsoft Public License, please send an email to
// [email protected]. By using this source code in any fashion, you are agreeing to be bound
// by the terms of the Microsoft Public License.
// ----------------------------------------------------------------------------------------------
// You must not remove this notice, or any other, from this software.
// ----------------------------------------------------------------------------------------------

// ### INCLUDE: Common.cs

namespace System.Linq
{
using System.Collections.Generic;

public interface IOrderedEnumerable<TElement> : IEnumerable<TElement>
{
IOrderedEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, bool descending);
}

static partial class Enumerable
{
public static IEnumerable<T> Where<T>(
this IEnumerable<T> source,
Func<T, bool> predicate
)
{
foreach (var v in source)
{
if (predicate(v))
{
yield return v;
}
}
}

public static IEnumerable<TResult> Select<T>(
this IEnumerable<T> source,
Func<T, TResult> predicate
)
{
foreach (var v in source)
{
yield return predicate(v);
}
}

}
}
Loading

0 comments on commit eb0a4a0

Please sign in to comment.