Пример #1
0
 public void ConvertPlaceholderToCode(string placeholder, CodeBody varName)
 {
     foreach (IMixedBody elem in elements)
     {
         elem.ConvertPlaceholderToCode(placeholder, varName);
     }
 }
Пример #2
0
 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);
 }
Пример #3
0
        public CodeBody Append(CodeBody other)
        {
            append(other.pieces);

            if (other.HasStatement)
                this.HasStatement = true;

            return this;
        }
Пример #4
0
 private CodeMix addBody(CodeBody body)
 {
     if (body != null)
     {
         elements.Add(body);
         body.AttachIdentifiersPool(identifiers);
     }
     return(this);
 }
Пример #5
0
        public CodeBody Embed(CodeBody other)
        {
            if (other.HasStatement)
                AddSnippet("{");
            append(other.pieces);
            if (other.HasStatement)
                AddSnippet("}");

            return this;
        }
Пример #6
0
        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;
        }
Пример #7
0
        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();
            }
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        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);
        }
Пример #10
0
 public CodeMix AddBody(CodeBody body)
 {
     return(addBody(body.Trim()));
 }