public IEnumerable <object> ConvertTokens(IEnumerable <object> sequence) { var enumerator = sequence.GetEnumerator(); while (enumerator.MoveNext()) { var item = enumerator.Current; if (item is StartExpressionToken) { yield return(item); item = GetNext(enumerator); if (item is Expression) { yield return(item); continue; } if (item is WordExpressionToken word && IsRegisteredHelperName(word.Value)) { yield return(HandlebarsExpression.HelperExpression(word.Value)); } else { yield return(item); } }
private static SubExpressionExpression BuildSubExpression(IEnumerator <object> enumerator) { object item = GetNext(enumerator); var path = item as PathExpression; if (path == null) { throw new HandlebarsCompilerException("Found a sub-expression that does not contain a path expression"); } var helperArguments = AccumulateSubExpression(enumerator); return(HandlebarsExpression.SubExpressionExpression( HandlebarsExpression.HelperExpression( path.Path, helperArguments))); }
public IEnumerable <object> ConvertTokens(IEnumerable <object> sequence) { var enumerator = sequence.GetEnumerator(); while (enumerator.MoveNext()) { var item = enumerator.Current; if (item is HelperExpression helperExpression) { var helperArguments = AccumulateArguments(enumerator); yield return(HandlebarsExpression.HelperExpression( helperExpression.HelperName, helperArguments)); yield return(enumerator.Current); } else if (item is PathExpression pathExpression) { var helperArguments = AccumulateArguments(enumerator); if (helperArguments.Count > 0) { yield return(HandlebarsExpression.HelperExpression( pathExpression.Path, helperArguments)); yield return(enumerator.Current); } else { yield return(item); yield return(enumerator.Current); } } else { yield return(item); } } }
protected override Expression VisitHelperExpression(HelperExpression hex) { return(HandlebarsExpression.HelperExpression( hex.HelperName, hex.Arguments.Select(Visit))); }