private static LoveNotBinding CovertToNotBinding(LoveBindingBase loveBinding) { if (loveBinding.Content.StartsWith("!")) { return(new LoveNotBinding(loveBinding.Start + 1, loveBinding.Length - 1, loveBinding.Content.Substring(1))); } return(null); }
private LoveControlBlock CreateControlBlock(List <LoveNode> blockSet, string controlType, string statement, string openBraces) { var controlStart = blockSet.First() as LoveBinding; var controlEnd = blockSet.Last(); var hasClosingBraces = openBraces == "{" && controlEnd is LoveBinding && (controlEnd as LoveBinding).Content.Trim() == "}"; var bodyLength = blockSet.Count - 1; bodyLength -= hasClosingBraces ? 1 : 0; var bodyChildren = blockSet.Skip(1).Take(bodyLength); var bodyBlock = new LoveBlock(bodyChildren.First().Start, bodyChildren.Sum(c => c.Length)); bodyBlock.Children.AddRange(bodyChildren); if (controlType == "if") { LoveBindingBase statementBinding = CreateStatement(controlStart, statement); return(new LoveIfBlock(controlStart.Start, controlEnd.Start - controlStart.Start + controlEnd.Length, statementBinding, bodyBlock)); } else if (controlType == "foreach") { var regexForeach = @"\s*(\S+)\s+in\s+(\S+)\s*"; var m = Regex.Match(statement, regexForeach); if (m.Success) { var itemName = m.Groups[1].Value; statement = m.Groups[2].Value; var itemNameSpan = new LoveName(controlStart.Start + controlStart.Content.IndexOf(itemName), itemName.Length, itemName); LoveBindingBase statementBinding = CreateStatement(controlStart, statement); return(new LoveForeachBlock(controlStart.Start, controlEnd.Start - controlStart.Start + controlEnd.Length, itemNameSpan, statementBinding, bodyBlock)); } else { return(null); } } return(null); }
private static LoveMarkupExpression ConvertToMarkupExpression(LoveBindingBase loveBinding) { var regexHtmlHelper = @"\s*Html\."; var m = Regex.Match(loveBinding.Content, regexHtmlHelper); if (m.Success) { return(new LoveMarkupExpression(loveBinding.Start, loveBinding.Length, loveBinding.Content)); } return(null); }
private static LoveNode ConvertBinding(LoveBindingBase binding) { var conversions = new List <Func <LoveBindingBase, LoveNode> >() { ConvertToMarkupExpression, CovertToNotBinding }; foreach (var conversion in conversions) { var converted = conversion(binding); if (converted != null) { return(converted); } } return(binding); }