Skip to content

Commit

Permalink
Version 0.2.1.
Browse files Browse the repository at this point in the history
Using a more reliable way to convert groups to links.
Added LinksGroup struct and ILinksGroupListExtensions class.
Link struct:
* Added Combine method.
* Removed AddDependency method.
  • Loading branch information
Konard committed Dec 3, 2019
1 parent c0c87b3 commit 4c36c8e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 40 deletions.
21 changes: 21 additions & 0 deletions Platform.Communication.Protocol.Lino/ILinksGroupListExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

namespace Platform.Communication.Protocol.Lino
{
public static class ILinksGroupListExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static List<Link> ToLinksList(this IList<LinksGroup> groups)
{
var list = new List<Link>();
for (var i = 0; i < groups.Count; i++)
{
groups[i].AppendToLinksList(list);
}
return list;
}
}
}
37 changes: 3 additions & 34 deletions Platform.Communication.Protocol.Lino/Link.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,40 +60,6 @@ public string GetValuesString()
return sb.ToString();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Link AddDependency(Link dependency)
{
if (Values.IsNullOrEmpty())
{
return new Link(new Link(dependency), this);
}
else
{
var firstValue = Values[0];
if (firstValue.Id == null)
{
var newValues = new List<Link>();
newValues.Add(firstValue.AddDependency(dependency));
newValues.AddSkipFirst(Values);
return new Link(newValues);
}
else
{
if (Values.Count > 1)
{
return new Link(new Link(dependency), new Link(Values));
}
else
{
var newValues = new List<Link>();
newValues.Add(new Link(dependency));
newValues.AddAll(Values);
return new Link(newValues);
}
}
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Link Simplify()
{
Expand All @@ -116,6 +82,9 @@ public Link Simplify()
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Link Combine(Link other) => new Link(this, other);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string GetValueString(Link value) => value.ToLinkOrIdString();

Expand Down
83 changes: 83 additions & 0 deletions Platform.Communication.Protocol.Lino/LinksGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Platform.Collections;
using Platform.Collections.Lists;

#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

namespace Platform.Communication.Protocol.Lino
{
public struct LinksGroup : IEquatable<LinksGroup>
{
public Link Link
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set;
}

public IList<LinksGroup> Groups
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksGroup(Link link, IList<LinksGroup> groups)
{
Link = link;
Groups = groups;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LinksGroup(Link link) : this(link, null) { }

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator List<Link>(LinksGroup value) => value.ToLinksList();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public List<Link> ToLinksList()
{
var list = new List<Link>();
AppendToLinksList(list);
return list;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AppendToLinksList(List<Link> list) => AppendToLinksList(list, Link, this);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AppendToLinksList(List<Link> list, Link dependency, LinksGroup group)
{
list.Add(dependency);
var groups = group.Groups;
if (!groups.IsNullOrEmpty())
{
for (int i = 0; i < groups.Count; i++)
{
var innerGroup = groups[i];
AppendToLinksList(list, dependency.Combine(innerGroup.Link), innerGroup);
}
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object obj) => obj is LinksGroup linksGroup ? Equals(linksGroup) : false;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode() => (Link, Groups.GenerateHashCode()).GetHashCode();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(LinksGroup other) => Link == other.Link && Groups.EqualTo(other.Groups);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(LinksGroup left, LinksGroup right) => left.Equals(right);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(LinksGroup left, LinksGroup right) => !(left == right);
}
}
8 changes: 4 additions & 4 deletions Platform.Communication.Protocol.Lino/Parser.peg
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@namespace Platform.Communication.Protocol.Lino
@classname Parser
@using System.Linq
document <IList<Link>> = #{ state["Indentation"] = 0; } _ l:links eof { l.SelectMany(x => x).Select(x => x.Simplify()).ToList() }
links <IList<IList<Link>>> = list:line+ { list }
line <IList<Link>> = INDENTATION l:element { l }
element <IList<Link>> = e:anyLink eol INDENT l:links UNDENT { new Link[] { e }.Concat(l.SelectMany(x => x).Select(y => y.AddDependency(e))).ToList() } / e:anyLink eol { new Link[] { e } }
document <IList<Link>> = #{ state["Indentation"] = 0; } _ l:links eof { l.ToLinksList() }
links <IList<LinksGroup>> = list:line+ { list }
line <LinksGroup> = INDENTATION l:element { l }
element <LinksGroup> = e:anyLink eol INDENT l:links UNDENT { new LinksGroup(e, l) } / e:anyLink eol { new LinksGroup(e) }
identityOrLink <Link> = l:multiLineAnyLink { l } / i:identity { i }
anyLink <Link> = multiLineAnyLink / singleLineAnyLink
multiLineAnyLink <Link> = multiLinePointLink / multiLineValueLink / multiLineLink
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Description>LinksPlatform's Platform.Communication.Protocol.Lino Class Library</Description>
<Copyright>Konstantin Diachenko</Copyright>
<AssemblyTitle>Platform.Communication.Protocol.Lino</AssemblyTitle>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionPrefix>0.2.1</VersionPrefix>
<Authors>Konstantin Diachenko</Authors>
<TargetFrameworks>net471;netstandard2.0;netstandard2.1</TargetFrameworks>
<AssemblyName>Platform.Communication.Protocol.Lino</AssemblyName>
Expand All @@ -24,7 +24,11 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>latest</LangVersion>
<PackageReleaseNotes>Added support for significant whitespace parsing.</PackageReleaseNotes>
<PackageReleaseNotes>Using a more reliable way to convert groups to links.
Added LinksGroup struct and ILinksGroupListExtensions class.
Link struct:
* Added Combine method.
* Removed AddDependency method.</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(MSBuildRuntimeType)' == 'Core' AND '$(OS)' != 'Windows_NT'">
Expand Down

0 comments on commit 4c36c8e

Please sign in to comment.