public void ConvertPlaceholderToCode(string placeholder, CodeBody varName) { foreach (IMixedBody elem in elements) { elem.ConvertPlaceholderToCode(placeholder, varName); } }
private CodeBody(CodeBody src) { placeholders = new HashSet<string>(src.placeholders); pieces = src.pieces.Select(it => it.Clone()).ToList(); TypeName = src.TypeName; HasStatement = src.HasStatement; identifiersPool = new HashSet<string>(src.identifiersPool); }
public CodeBody Append(CodeBody other) { append(other.pieces); if (other.HasStatement) this.HasStatement = true; return this; }
private CodeMix addBody(CodeBody body) { if (body != null) { elements.Add(body); body.AttachIdentifiersPool(identifiers); } return(this); }
public CodeBody Embed(CodeBody other) { if (other.HasStatement) AddSnippet("{"); append(other.pieces); if (other.HasStatement) AddSnippet("}"); return this; }
public void ConvertPlaceholderToCode(string placeholder, CodeBody varName) { var conv = new List<CodePiece>(); foreach (CodePiece p in pieces) if (p.Type == CodePiece.TypeEnum.Placeholder && p.Content == placeholder) conv.AddRange(varName.Clone().Pieces); else conv.Add(p); pieces = conv; }
public CodeMacro(CodePiece controlName, bool isBoolean, CodeBody varBody, params CodeMix[] altCodes) { this.ControlName = controlName; this.varBody = varBody ?? new CodeBody(); this.isBoolean = isBoolean; this.altCodes = altCodes; if (altCodes.Length != 1 && varBody != null) { throw new ArgumentException(); } if (isBoolean && (altCodes.Length != 0 || varBody != null)) { throw new ArgumentException(); } }
public void ConvertPlaceholderToCode(string placeholder, CodeBody varName) { if (getControlPlaceholder() == placeholder) { if (varName.Pieces.Count() == 1) { ControlName = varName.Pieces.Single(); } else { // the reason for this is we don't handle compound variable/expressions like "foo.field.bar" // and the reason for the reason is, such compound expression can come only from standard placeholders // like $pos or $coords, and it does not make sense to check them if they exist or if they are null or not throw ParseControlException.NewAndRun("Placeholder \"" + placeholder + "\" cannot be used as control variable in macro."); } } varBody.ConvertPlaceholderToCode(placeholder, varName); foreach (CodeMix mix in altCodes) { mix.ConvertPlaceholderToCode(placeholder, varName); } }
public CodeBody BuildBody(IEnumerable <Tuple <string, bool> > presentVariables) { // some of the names can be duplicated, but we are interested if any variable (with the same name) // is enabled -- if yes, we have to pass the argument Dictionary <string, bool> anyVarPresent = null; if (presentVariables != null) { anyVarPresent = presentVariables.Select(it => it.Item1).Distinct().ToDictionary(it => it, it => false); foreach (string s in presentVariables.Where(it => it.Item2).Select(it => it.Item1)) { anyVarPresent[s] = true; } } var merged = new CodeBody(); foreach (CodeBody body in expand(anyVarPresent)) { merged.Append(body); } return(merged); }
public CodeMix AddBody(CodeBody body) { return(addBody(body.Trim())); }