// use pure name, no dollar in front // for identifiers which are references by dollar and symbol name, // like "PLUS .... $PLUS" instead of setting up identifiers "plus:PLUS ..... plus" public CodeBody AddPlaceholder(string s) { if (s.StartsWith(CodePiece.PlaceholderSigil)) throw new ArgumentException(); pieces.Add(CodePiece.Create(CodePiece.TypeEnum.Placeholder, s)); placeholders.Add(s); return this; }
public CodeBody AddIdentifier(string s) { if (s != null) { pieces.Add(CodePiece.Create(CodePiece.TypeEnum.Identifier, s)); identifiersPool.Add(s); } return this; }
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); } }
private CodePiece(CodePiece src) { Type = src.Type; Content = src.Content; }
public CodeBody AddSnippet(string s) { pieces.Add(CodePiece.Create(CodePiece.TypeEnum.Snippet, s)); return this; }