Skip to content

Commit

Permalink
New - Uploaded initial project structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Labelle committed Feb 24, 2017
1 parent 54c260d commit 8ad112e
Show file tree
Hide file tree
Showing 32 changed files with 20,613 additions and 0 deletions.
29 changes: 29 additions & 0 deletions appveyor.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '1.0.{build}'

configuration:
- Debug
- Release

platform: Any CPU

environment:
# Don't report back to the mothership
DOTNET_CLI_TELEMETRY_OPTOUT: 1
init:
- ps: $Env:LABEL = "CI" + $Env:APPVEYOR_BUILD_NUMBER.PadLeft(5, "0")

before_build:
- appveyor-retry dotnet restore -v Minimal

build_script:
- dotnet build "src\jmespath.net" -c %CONFIGURATION% --no-dependencies --version-suffix %LABEL%

after_build:

test_script:
- dotnet test "test\jmespath.net.tests" -c %CONFIGURATION%

cache:
- '%USERPROFILE%\.nuget\packages'

on_finish:
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "test", "." ],
"sdk": {
"version": "1.0.0-preview2-003121"
}
}
43 changes: 43 additions & 0 deletions jmespath.net.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{6D7773F3-76FA-4E25-A85C-7AA1AD5668D8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{65D019ED-1B19-47DD-8C89-4FBABAA860D8}"
ProjectSection(SolutionItems) = preProject
appveyor.ml = appveyor.ml
global.json = global.json
README.md = README.md
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "jmespath.net.tests", "tests\jmespath.net.tests\jmespath.net.tests.xproj", "{43EC8A0D-27A8-476C-8806-ED18FCC8B2F2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{17EC0D83-06FD-45A9-87CE-5A6901204774}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "jmespath.netstandard", "src\jmespath.net\jmespath.netstandard.xproj", "{C1B8BA55-2115-406F-944D-39EFA384879D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{43EC8A0D-27A8-476C-8806-ED18FCC8B2F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43EC8A0D-27A8-476C-8806-ED18FCC8B2F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43EC8A0D-27A8-476C-8806-ED18FCC8B2F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43EC8A0D-27A8-476C-8806-ED18FCC8B2F2}.Release|Any CPU.Build.0 = Release|Any CPU
{C1B8BA55-2115-406F-944D-39EFA384879D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C1B8BA55-2115-406F-944D-39EFA384879D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1B8BA55-2115-406F-944D-39EFA384879D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1B8BA55-2115-406F-944D-39EFA384879D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{43EC8A0D-27A8-476C-8806-ED18FCC8B2F2} = {17EC0D83-06FD-45A9-87CE-5A6901204774}
{C1B8BA55-2115-406F-944D-39EFA384879D} = {6D7773F3-76FA-4E25-A85C-7AA1AD5668D8}
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions src/jmespath.net/Expressions/JmesPathExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
/// <summary>
/// Represents the base class for a JmesPath expression.
/// </summary>
public abstract class JmesPathExpression
{
/// <summary>
/// Evaluates the expression against the specified JSON object.
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public abstract JToken Transform(JToken json);
}
}
25 changes: 25 additions & 0 deletions src/jmespath.net/Expressions/JmesPathIdentifier.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
public class JmesPathIdentifier : JmesPathExpression
{
private readonly string name_;

public JmesPathIdentifier(string name)
{
name_ = name;
}

public string Name => name_;

public override JToken Transform(JToken json)
{
System.Diagnostics.Debug.Assert(json.Type == JTokenType.Object);
var jsonObject = json as JObject;
System.Diagnostics.Debug.Assert(jsonObject != null);

return jsonObject[name_];
}
}
}
22 changes: 22 additions & 0 deletions src/jmespath.net/Expressions/JmesPathIndexExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
public class JmesPathIndexExpression : JmesPathExpression
{
private readonly JmesPathExpression expression_;
private readonly JmesPathExpression specifier_;

public JmesPathIndexExpression(JmesPathExpression expression, JmesPathExpression specifier)
{
expression_ = expression;
specifier_ = specifier;
}

public override JToken Transform(JToken json)
{
var token = expression_.Transform(json);
return token == null ? null : specifier_.Transform(token);
}
}
}
33 changes: 33 additions & 0 deletions src/jmespath.net/Expressions/JmesPathMultiSelectHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
public sealed class JmesPathMultiSelectHash : JmesPathExpression
{
private readonly IDictionary<string, JmesPathExpression> dictionary_
= new Dictionary<string, JmesPathExpression>()
;

public JmesPathMultiSelectHash(IDictionary<string, JmesPathExpression> dictionary)
{
foreach (var key in dictionary.Keys)
dictionary_.Add(key, dictionary[key]);
}

public override JToken Transform(JToken json)
{
var properties = new List<JProperty>();

foreach (var key in dictionary_.Keys)
{
var expression = dictionary_[key];
var result = expression.Transform(json);

properties.Add(new JProperty(key, result));
}

return new JObject(properties);
}
}
}
32 changes: 32 additions & 0 deletions src/jmespath.net/Expressions/JmesPathMultiSelectList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
public sealed class JmesPathMultiSelectList : JmesPathExpression
{
private readonly IList<JmesPathExpression> expressions_
= new List<JmesPathExpression>()
;

public JmesPathMultiSelectList(IList<JmesPathExpression> expressions)
{
foreach (var expression in expressions)
expressions_.Add(expression);
}

public override JToken Transform(JToken json)
{
var items = new List<JToken>();
foreach (var expression in expressions_)
{
var result = expression.Transform(json);
// TODO: what is result == null ?

items.Add(result);
}

return new JArray(items);
}
}
}
24 changes: 24 additions & 0 deletions src/jmespath.net/Expressions/JmesPathNumber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
/// <summary>
/// Represents a JmesPath number.
/// </summary>
public class JmesPathNumber : JmesPathExpression
{
public JmesPathNumber(int value)
{
Value = value;
}

public int Value { get; }

public override JToken Transform(JToken json)
{
System.Diagnostics.Debug.Assert(false);
throw new NotImplementedException();
}
}
}
38 changes: 38 additions & 0 deletions src/jmespath.net/Expressions/JmesPathSliceExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
/// <summary>
/// Represents a JmesPath slice expression.
/// </summary>
public class JmesPathSliceExpression : JmesPathExpression
{
private readonly JmesPathExpression expression_;

public JmesPathSliceExpression(JmesPathExpression number)
{
expression_ = number;
}

public override JToken Transform(JToken json)
{
if (json.Type != JTokenType.Array)
return null;

// slice expression adhere to the following rule:
// if the element being sliced is not an array, the result is null.

var array = json as JArray;
if (array == null)
return null;

if (expression_ is JmesPathNumber)
{
var index = ((JmesPathNumber)expression_).Value;
return array[index];
}
else
return null;
}
}
}
39 changes: 39 additions & 0 deletions src/jmespath.net/Expressions/JmesPathSubExpression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using Newtonsoft.Json.Linq;

namespace DevLab.JmesPath.Expressions
{
/// <summary>
/// Represents a JmesPath sub expression.
/// </summary>
public sealed class JmesPathSubExpression : JmesPathExpression
{
private readonly JmesPathExpression expression_;
private readonly JmesPathExpression subExpression_;

/// <summary>
/// Initialize a new instance of the <see cref="JmesPathSubExpression"/> class
/// with two <see cref="JmesPathExpression"/> objects.
/// </summary>
/// <param name="expression"></param>
/// <param name="subExpression"></param>
public JmesPathSubExpression(JmesPathExpression expression, JmesPathExpression subExpression)
{
if (expression == null) throw new ArgumentNullException(nameof(expression));
if (subExpression == null) throw new ArgumentNullException(nameof(subExpression));

System.Diagnostics.Debug.Assert(subExpression is JmesPathIdentifier);

expression_ = expression;
subExpression_ = subExpression;
}

public override JToken Transform(JToken json)
{
var result = expression_.Transform(json);
if (result == null)
return null;
return subExpression_.Transform(result);
}
}
}
Loading

0 comments on commit 8ad112e

Please sign in to comment.