Skip to content

Commit

Permalink
- Increased version to 2.0.1. Added TakeWhile() and SkipWhile() exten…
Browse files Browse the repository at this point in the history
…sion methods for IList, IListSource, INegListSource.

- Added TryGet(INegListSource, int index)
- Added one-param constructor to MacroProcessor and switched order of params to other constructor for harmony.
  • Loading branch information
qwertie committed Nov 26, 2016
1 parent f3877bc commit ceffb6b
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Core/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
// by using '.*' as shown below - but you shouldn't, because it will cause a simple
// "Rebuild All" command to produce an incompatible assembly, since the .NET
// framework apparently requires an exact match on all four AssemblyVersion numbers.
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
2 changes: 1 addition & 1 deletion Core/Loyc.Essentials/Collections/Adapters/ListSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public struct ListSlice<T> : IRange<T>, ICloneable<ListSlice<T>>, IListAndListSo
/// created.</li>
/// </ul>
/// </remarks>
public ListSlice(IList<T> list, int start, int count)
public ListSlice(IList<T> list, int start, int count = int.MaxValue)
{
_list = list;
_start = start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,76 @@ public static NegListSlice<T> Take<T>(this INegListSource<T> list, int count)
return new NegListSlice<T>(list, list.Min, count);
}

public static ListSlice<T> TakeWhile<T>(this IList<T> list, Func<T, bool> predicate)
{
Maybe<T> value;
for (int i = 0; ; i++) {
if (!(value = list.TryGet(i)).HasValue)
return new ListSlice<T>(list);
else if (!predicate(value.Value))
return new ListSlice<T>(list, 0, i);
}
}
public static Slice_<T> TakeWhile<T>(this IListSource<T> list, Func<T, bool> predicate)
{
Maybe<T> value;
for (int i = 0; ; i++) {
if (!(value = list.TryGet(i)).HasValue)
return new Slice_<T>(list);
else if (!predicate(value.Value))
return new Slice_<T>(list, 0, i);
}
}
public static NegListSlice<T> TakeWhile<T>(this INegListSource<T> list, Func<T, bool> predicate)
{
Maybe<T> value;
for (int i = 0; ; i++) {
if (!(value = list.TryGet(i, default(T))).HasValue)
return new NegListSlice<T>(list);
else if (!predicate(value.Value))
return new NegListSlice<T>(list, 0, i);
}
}
public static Slice_<T> TakeWhile<T>(this IListAndListSource<T> list, Func<T, bool> predicate)
{
return TakeWhile((IListSource<T>)list, predicate);
}

public static ListSlice<T> SkipWhile<T>(this IList<T> list, Func<T, bool> predicate)
{
Maybe<T> value;
for (int i = 0; ; i++) {
if (!(value = list.TryGet(i)).HasValue)
return new ListSlice<T>();
else if (!predicate(value.Value))
return new ListSlice<T>(list, i);
}
}
public static Slice_<T> SkipWhile<T>(this IListSource<T> list, Func<T, bool> predicate)
{
Maybe<T> value;
for (int i = 0; ; i++) {
if (!(value = list.TryGet(i)).HasValue)
return new Slice_<T>();
else if (!predicate(value.Value))
return new Slice_<T>(list, i);
}
}
public static NegListSlice<T> SkipWhile<T>(this INegListSource<T> list, Func<T, bool> predicate)
{
Maybe<T> value;
for (int i = 0; ; i++) {
if (!(value = list.TryGet(i, default(T))).HasValue)
return new NegListSlice<T>();
else if (!predicate(value.Value))
return new NegListSlice<T>(list, i);
}
}
public static Slice_<T> SkipWhile<T>(this IListAndListSource<T> list, Func<T, bool> predicate)
{
return SkipWhile((IListSource<T>)list, predicate);
}

/// <summary>Copies the contents of an IListSource or IReadOnlyList to an array.</summary>
public static T[] ToArray<T>(this IReadOnlyList<T> c)
{
Expand Down
13 changes: 13 additions & 0 deletions Core/Loyc.Essentials/Collections/Interfaces/INegListSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ public static T TryGet<T>(this INegListSource<T> list, int index, T defaultValue
else
return result;
}

/// <summary>Tries to get a value from the list at the specified index.</summary>
/// <param name="index">The index to access. Valid indexes are between Min and Max.</param>
/// <returns>The retrieved value, or <see cref="Maybe{T}.NoValue"/> if the index provided was not valid.</returns>
public static Maybe<T> TryGet<T>(this INegListSource<T> list, int index)
{
bool fail;
T result = list.TryGet(index, out fail);
if (fail)
return default(Maybe<T>);
else
return result;
}

/// <summary>Determines the index of a specific value.</summary>
/// <returns>The index of the value, if found, or null if it was not found.</returns>
Expand Down
1 change: 1 addition & 0 deletions Main/Ecs/EcsValidators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public static Symbol MethodDefinitionKind(LNode n, bool allowDelegate, Pedantics
/// <param name="body">The method body, or null if there is no method body.
/// The method body calls <see cref="CodeSymbols.Braces"/> if the method is a
/// non-lambda-style method.</param>
/// <returns>The definition kind (#fn, #cons, or #delegate), or null if it's no kind of method.</returns>
/// <remarks>
/// Method declarations (no body) also count.
/// <para/>
Expand Down
4 changes: 2 additions & 2 deletions Main/Ecs/Parser/EcsLexerGrammar.out.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from EcsLexerGrammar.les by LeMP custom tool. LeMP version: 1.9.5.0
// Generated from EcsLexerGrammar.les by LeMP custom tool. LeMP version: 2.0.1.0
// Note: you can give command-line arguments to the tool via 'Custom Tool Namespace':
// --no-out-header Suppress this message
// --verbose Allow verbose messages (shown by VS as 'warnings')
Expand Down Expand Up @@ -5442,4 +5442,4 @@ private bool HexNumber_Test0()
return true;
}
}
}
}
12 changes: 6 additions & 6 deletions Main/Ecs/Parser/EcsParserGrammar.out.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from EcsParserGrammar.les by LeMP custom tool. LeMP version: 1.9.6.0
// Generated from EcsParserGrammar.les by LeMP custom tool. LeMP version: 2.0.1.0
// Note: you can give command-line arguments to the tool via 'Custom Tool Namespace':
// --no-out-header Suppress this message
// --verbose Allow verbose messages (shown by VS as 'warnings')
Expand Down Expand Up @@ -2432,8 +2432,8 @@ LNode Expr(Precedence context)
{
la0 = LA0;
if (context.CanParse(prec = InfixPrecedenceOf(la0))) {
if (LT(0).EndIndex == LT(0 + 1).StartIndex) {
if (context.CanParse(EP.Shift)) {
if (context.CanParse(EP.Shift)) {
if (LT(0).EndIndex == LT(0 + 1).StartIndex) {
la1 = LA(1);
if (PrefixExpr_set0.Contains((int) la1))
goto match1;
Expand All @@ -2455,8 +2455,8 @@ LNode Expr(Precedence context)
else
goto stop;
}
} else if (LT(0).EndIndex == LT(0 + 1).StartIndex) {
if (context.CanParse(EP.Shift)) {
} else if (context.CanParse(EP.Shift)) {
if (LT(0).EndIndex == LT(0 + 1).StartIndex) {
la1 = LA(1);
if (la1 == TT.GT || la1 == TT.LT)
goto match3;
Expand Down Expand Up @@ -5190,4 +5190,4 @@ private bool BlockCallStmt_Test0()
return true;
}
}
}
}
4 changes: 2 additions & 2 deletions Main/LeMP.StdMacros/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion ("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
// In case needed by unit tests
[assembly: InternalsVisibleTo("LeMP, PublicKey=0024000004800000940000000602000000240000525341310004000001000100adec5c8e52098b94dc60b34ac0916d307eec23b2c285a0beeb7168174fc1f6a71dcae43c88904e2907a12f66861de8d8f130c4f7b57cff0aea92ed06b50d96c63cea2ee19ec5d35a2946ddef3f35f0fbd3ec3a358b46fd05c82837c49d91694c1926935dc83e2a28c1ff077e4d8a5f679f1edb1c8a692aa2913d753ea05f4fba")]
2 changes: 1 addition & 1 deletion Main/LeMP/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static void ShowHelp(IEnumerable<KeyValuePair<string, Pair<string, string

public Compiler(IMessageSink sink, Type prelude = null, bool registerEcsAndLes = true)
{
MacroProcessor = new MacroProcessor(prelude, sink);
MacroProcessor = new MacroProcessor(sink, prelude);

if (registerEcsAndLes) {
ParsingService.Register(Loyc.Syntax.Les.Les2LanguageService.Value);
Expand Down
14 changes: 12 additions & 2 deletions Main/LeMP/MacroProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,20 @@ public partial class MacroProcessor
/// <summary>Returns the <c>MacroProcessor</c> running on the current thread, or null if none.</summary>
public static MacroProcessor Current { get { return _current; } }

public MacroProcessor(Type prelude, IMessageSink sink)
/// <summary>Initializes MacroProcessor with default prelude.</summary>
public MacroProcessor(IMessageSink sink) : this(sink, typeof(BuiltinMacros)) { }

/// <summary>Initializes MacroProcessor.</summary>
/// <param name="sink">The destination for warning and error messages. NOTE:
/// this class can process files in parallel. Consider using a thread-safe
/// implementation of <see cref="IMessageSink"/>.</param>
/// <param name="prelude">An initial type from which to add macros.
/// Omit this parameter to use typeof(LeMP.Prelude.BuiltinMacros).</param>
public MacroProcessor(IMessageSink sink, Type prelude)
{
_sink = sink;
AddMacros(prelude ?? typeof(BuiltinMacros));
if (prelude != null)
AddMacros(prelude);
AbortTimeout = TimeSpan.FromSeconds(30);
PreOpenedNamespaces.Add((Symbol)"LeMP.Prelude");
}
Expand Down
4 changes: 2 additions & 2 deletions Main/LeMP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion ("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion ("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
2 changes: 1 addition & 1 deletion Main/LeMP/Tests/MacroTesterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected void Test(string input, IParsingService inLang, string expected, IPars
}
protected virtual MacroProcessor NewLemp(int maxExpand, IParsingService inLang)
{
var lemp = new MacroProcessor(typeof(LeMP.Prelude.BuiltinMacros), MessageSink.Current);
var lemp = new MacroProcessor(MessageSink.Current, typeof(LeMP.Prelude.BuiltinMacros));
lemp.AddMacros(typeof(LeMP.Prelude.Les.Macros));
lemp.AddMacros(typeof(LeMP.StandardMacros).Assembly);
lemp.PreOpenedNamespaces.Add(GSymbol.Get("LeMP"));
Expand Down
2 changes: 1 addition & 1 deletion Main/Tests/Samples.out.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from Samples.ecs by LeMP custom tool. LeMP version: 2.0.0.0
// Generated from Samples.ecs by LeMP custom tool. LeMP version: 2.0.1.0
// Note: you can give command-line arguments to the tool via 'Custom Tool Namespace':
// --no-out-header Suppress this message
// --verbose Allow verbose messages (shown by VS as 'warnings')
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 1.9.6.{build}
version: 2.0.1.{build}

before_build:
- nuget restore Loyc-Slim.sln

build_script:
# First, set some environment variables.
# SEMVER is set manually. Not sure how this can be automated.
- set SEMVER=1.9.6
- set SEMVER=2.0.1
- echo %APPVEYOR_REPO_TAG%
# Build packages as SEMVER-ci{build}
- ps: if ($env:APPVEYOR_REPO_TAG -eq $True) { $env:PKG_VERSION = $env:SEMVER; } else { $env:PKG_VERSION = "$($env:SEMVER)-ci$($env:APPVEYOR_BUILD_NUMBER)"; }
Expand Down

0 comments on commit ceffb6b

Please sign in to comment.