Skip to content

Commit

Permalink
Added containsKey function
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoboss committed Dec 21, 2023
1 parent f8b777a commit d64468b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions StepLang/Framework/Pure/ContainsKeyFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using StepLang.Expressions.Results;
using StepLang.Interpreting;
using StepLang.Tokenizing;

namespace StepLang.Framework.Pure;

public class ContainsKeyFunction : GenericFunction<MapResult, StringResult>
{
public const string Identifier = "containsKey";

protected override IEnumerable<NativeParameter> NativeParameters { get; } = new NativeParameter[] {
new(OnlyMap, "subject"),
new(OnlyString, "key"),
};

protected override IEnumerable<ResultType> ReturnTypes { get; } = OnlyBool;

protected override BoolResult Invoke(TokenLocation callLocation, Interpreter interpreter, MapResult argument1, StringResult argument2)
{
return argument1.Value.ContainsKey(argument2.Value);
}
}
1 change: 1 addition & 0 deletions StepLang/Interpreting/Scope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private Scope()
CreateVariable(SubstringFunction.Identifier, new SubstringFunction().ToResult());
CreateVariable(IndexOfFunction.Identifier, new IndexOfFunction().ToResult());
CreateVariable(ContainsFunction.Identifier, new ContainsFunction().ToResult());
CreateVariable(ContainsKeyFunction.Identifier, new ContainsKeyFunction().ToResult());
CreateVariable(StartsWithFunction.Identifier, new StartsWithFunction().ToResult());
CreateVariable(EndsWithFunction.Identifier, new EndsWithFunction().ToResult());
CreateVariable(PrintFunction.Identifier, new PrintFunction().ToResult());
Expand Down

0 comments on commit d64468b

Please sign in to comment.