/// <summary> /// Sets an Option that was requested from template /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <param name="parserOptions"></param> /// <returns></returns> public async Promise SetOption(string name, IMorestachioExpression value, ParserOptions parserOptions) { var val = (await value.GetValue(new ContextObject(parserOptions, ".", null, new object()), new ScopeData())) .Value; if (name.Equals("TokenPrefix", StringComparison.InvariantCultureIgnoreCase)) { if (val == null) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value")); return; } PrefixToken = val.ToString(); } if (name.Equals("TokenSuffix", StringComparison.InvariantCultureIgnoreCase)) { if (val == null) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value")); return; } SuffixToken = val.ToString(); } }
/// <summary> /// Sets an Option that was requested from template /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <param name="parserOptions"></param> /// <returns></returns> public async Promise SetOption(string name, IMorestachioExpression value, ParserOptions parserOptions) { var val = (await value.GetValue(new ContextObject(".", null, new object()), new ScopeData(parserOptions))) .Value; if (name.Equals("TrimTailing", StringComparison.OrdinalIgnoreCase)) { if (val == null) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value")); return; } if (!(val is bool valBool)) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'")); return; } TrimTailing = valBool; } if (name.Equals("TrimLeading", StringComparison.OrdinalIgnoreCase)) { if (val == null) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value")); return; } if (!(val is bool valBool)) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'")); return; } TrimLeading = valBool; } if (name.Equals("TrimAllTailing", StringComparison.OrdinalIgnoreCase)) { if (val == null) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value")); return; } if (!(val is bool valBool)) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'")); return; } TrimAllTailing = valBool; } if (name.Equals("TrimAllLeading", StringComparison.OrdinalIgnoreCase)) { if (val == null) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned null for option '{name}' that does not accept a null value")); return; } if (!(val is bool valBool)) { Errors.Add(new MorestachioSyntaxError(CurrentLocation.AddWindow(new CharacterSnippedLocation()), "SET OPTION", "VALUE", $"The expression returned '{val.GetType()}' for option '{name}' but expected and value of type '{typeof(bool)}'")); return; } TrimAllLeading = valBool; } }