Skip to content

Commit c7174be

Browse files
Merge pull request #40 from delegateas/thygesteffensen/dot-index-fix
Thygesteffensen/dot index fix
2 parents 148543d + a51a544 commit c7174be

28 files changed

Lines changed: 113 additions & 60 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace ExpressionEngine
4+
{
5+
internal class ExpressionEngineException : Exception
6+
{
7+
public ExpressionEngineException(string message) : base(message)
8+
{
9+
}
10+
}
11+
}

ExpressionEngine/ExpressionGrammar.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,7 @@ from index in _method.Or(stringLiteral).Or(integer).Contained(lBracket, rBracket
6666
from nll in nullConditional
6767
from dot in Parse.Char('.')
6868
from index in Parse.AnyChar.Except(
69-
lBracket
70-
.Or(rBracket)
71-
.Or(lParenthesis)
72-
.Or(rParenthesis)
73-
.Or(Parse.Char('@'))
74-
.Or(Parse.Char(','))
75-
.Or(Parse.Char('.'))
76-
.Or(Parse.Char('?'))
69+
Parse.Chars('[', ']', '{', '}', '[', ']', '@', ',', '.', '?')
7770
).Many().Text()
7871
select new IndexRule(new StringLiteralRule(new ValueContainer(index)), nll);
7972

@@ -123,12 +116,7 @@ from exp in enclosedExpression.Optional()
123116
.Many()
124117
select new ValueTask<ValueContainer>(new ValueContainer(string.Concat(e)));
125118

126-
Parser<ValueTask<ValueContainer>> charPrefixedString =
127-
from at in Parse.Char('@')
128-
from str in Parse.LetterOrDigit.Many().Text().Except(Parse.Chars('{', '@'))
129-
select new ValueTask<ValueContainer>(new ValueContainer(str));
130-
131-
_input = expression.Or(charPrefixedString).Or(joinedString);
119+
_input = expression.Or(joinedString);
132120
}
133121

134122
public async ValueTask<string> EvaluateToString(string input)

ExpressionEngine/Functions/Implementations/CollectionFunctions/ContainsFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[
4444
var substring = value.GetValue<string>();
4545
return new ValueTask<ValueContainer>(new ValueContainer(text.Contains(substring)));
4646
default:
47-
throw new PowerAutomateMockUpException($"Cannot perform contains on {collection.Type()}.");
47+
throw new ExpressionEngineException($"Cannot perform contains on {collection.Type()}.");
4848
}
4949
}
5050
}

ExpressionEngine/Functions/Implementations/CollectionFunctions/EmptyFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[
2424
ValueContainer.ValueType.Object => new ValueTask<ValueContainer>(new ValueContainer(
2525
value.GetValue<Dictionary<string, ValueContainer>>().Count == 0)),
2626
ValueContainer.ValueType.Null => new ValueTask<ValueContainer>(new ValueContainer(true)),
27-
_ => throw new PowerAutomateMockUpException(
27+
_ => throw new ExpressionEngineException(
2828
$"Empty expression can only operate on String, Array or Object types, not {value.Type()}.")
2929
};
3030
}

ExpressionEngine/Functions/Implementations/CollectionFunctions/FirstFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[
2121
value.GetValue<string>().Substring(0, 1))),
2222
ValueContainer.ValueType.Array => new ValueTask<ValueContainer>(new ValueContainer(
2323
value.GetValue<IEnumerable<ValueContainer>>().First())),
24-
_ => throw new PowerAutomateMockUpException(
24+
_ => throw new ExpressionEngineException(
2525
$"Empty expression can only operate on String or Array types, not {value.Type()}.")
2626
};
2727
}

ExpressionEngine/Functions/Implementations/CollectionFunctions/IntersectionFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[
1717
{
1818
ValueContainer.ValueType.Array => IntersectList(parameters),
1919
ValueContainer.ValueType.Object => IntersectDict(parameters),
20-
_ => throw new PowerAutomateMockUpException(
20+
_ => throw new ExpressionEngineException(
2121
$"Can only intersect Array and Object, not {parameters[0].Type()}.")
2222
};
2323
}

ExpressionEngine/Functions/Implementations/CollectionFunctions/LastFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[
2121
value.GetValue<string>().ToCharArray().Last().ToString())),
2222
ValueContainer.ValueType.Array => new ValueTask<ValueContainer>(new ValueContainer(
2323
value.GetValue<IEnumerable<ValueContainer>>().Last())),
24-
_ => throw new PowerAutomateMockUpException(
24+
_ => throw new ExpressionEngineException(
2525
$"Empty expression can only operate on String or Array types, not {value.Type()}.")
2626
};
2727
}

ExpressionEngine/Functions/Implementations/CollectionFunctions/SkipFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[
2020
{
2121
ValueContainer.ValueType.Array => new ValueTask<ValueContainer>(new ValueContainer(
2222
value.GetValue<IEnumerable<ValueContainer>>().Skip(count))),
23-
_ => throw new PowerAutomateMockUpException(
23+
_ => throw new ExpressionEngineException(
2424
$"Empty expression can only operate on String or Array types, not {value.Type()}.")
2525
};
2626
}

ExpressionEngine/Functions/Implementations/CollectionFunctions/TakeFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public override ValueTask<ValueContainer> ExecuteFunction(params ValueContainer[
2020
{
2121
ValueContainer.ValueType.Array => new ValueTask<ValueContainer>(new ValueContainer(
2222
value.GetValue<IEnumerable<ValueContainer>>().Take(count))),
23-
_ => throw new PowerAutomateMockUpException(
23+
_ => throw new ExpressionEngineException(
2424
$"Empty expression can only operate on String or Array types, not {value.Type()}.")
2525
};
2626
}

ExpressionEngine/Functions/Implementations/CollectionFunctions/UnionFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override async ValueTask<ValueContainer> ExecuteFunction(params ValueCont
1717
{
1818
ValueContainer.ValueType.Array => UnionList(parameters),
1919
ValueContainer.ValueType.Object => UnionDict(parameters),
20-
_ => throw new PowerAutomateMockUpException(
20+
_ => throw new ExpressionEngineException(
2121
$"Can only union Array and Object, not {parameters[0].Type()}.")
2222
};
2323
}

0 commit comments

Comments
 (0)