Esempio n. 1
0
        // =======================================================================================
        // VBScript BASE SOURCE RE-GENERATION
        // =======================================================================================
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there
        /// should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            var output = new StringBuilder();

            output.Append(indenter.Indent + "SELECT CASE ");
            output.AppendLine(Expression.GenerateBaseSource(NullIndenter.Instance));

            if (_openingComments != null)
            {
                foreach (CommentStatement statement in _openingComments)
                {
                    output.AppendLine(statement.GenerateBaseSource(indenter.Increase()));
                }
                output.AppendLine("");
            }

            for (int index = 0; index < _content.Count; index++)
            {
                // Render branch start
                CaseBlockSegment segment = _content[index];
                if (segment is CaseBlockExpressionSegment)
                {
                    output.Append(indenter.Increase().Indent);
                    output.Append("CASE ");
                    var valuesArray = ((CaseBlockExpressionSegment)segment).Values.ToArray();
                    for (int indexValue = 0; indexValue < valuesArray.Length; indexValue++)
                    {
                        Expression statement = valuesArray[indexValue];
                        output.Append(statement.GenerateBaseSource(NullIndenter.Instance));
                        if (indexValue < (valuesArray.Length - 1))
                        {
                            output.Append(", ");
                        }
                    }
                    output.AppendLine("");
                }
                else
                {
                    output.AppendLine(indenter.Increase().Indent + "CASE ELSE");
                }

                // Render branch content
                foreach (ICodeBlock statement in segment.Statements)
                {
                    output.AppendLine(statement.GenerateBaseSource(indenter.Increase().Increase()));
                }
            }

            output.Append(indenter.Indent + "END SELECT");
            return(output.ToString());
        }
Esempio n. 2
0
        // =======================================================================================
        // VBScript BASE SOURCE RE-GENERATION
        // =======================================================================================
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there
        /// should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            StringBuilder output = new StringBuilder();

            // Open statement
            output.Append(indenter.Indent);
            output.Append("For ");
            output.Append(this.loopVar.Content);
            output.Append(" = ");
            output.Append(this.loopFrom.GenerateBaseSource(NullIndenter.Instance));
            output.Append(" To ");
            output.Append(this.loopTo.GenerateBaseSource(NullIndenter.Instance));
            if (this.loopStep != null)
            {
                output.Append(" Step ");
                output.Append(this.LoopStep.GenerateBaseSource(NullIndenter.Instance));
            }
            output.AppendLine("");

            // Render inner content
            foreach (ICodeBlock statement in this.statements)
            {
                output.AppendLine(statement.GenerateBaseSource(indenter.Increase()));
            }

            // Close statement
            output.Append(indenter.Indent + "Next");
            return(output.ToString());
        }
Esempio n. 3
0
        // =======================================================================================
        // VBScript BASE SOURCE RE-GENERATION
        // =======================================================================================
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there
        /// should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            StringBuilder output = new StringBuilder();

            output.AppendLine(indenter.Indent + "Class " + this.className.Content);
            foreach (ICodeBlock block in this.statements)
            {
                output.AppendLine(block.GenerateBaseSource(indenter.Increase()));
            }
            output.Append(indenter.Indent + "End Class");
            return(output.ToString());
        }
Esempio n. 4
0
        // =======================================================================================
        // VBScript BASE SOURCE RE-GENERATION
        // =======================================================================================
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            var output = new StringBuilder();

            // Open statement (with condition if this construct has a pre condition)
            output.Append(indenter.Indent + "Do");
            if (IsPreCondition && (ConditionIfAny != null))
            {
                output.Append(" ");
                if (IsDoWhileCondition)
                {
                    output.Append("While ");
                }
                else
                {
                    output.Append("Until ");
                }
                output.AppendLine(ConditionIfAny.GenerateBaseSource(NullIndenter.Instance));
            }
            else
            {
                output.AppendLine();
            }

            // Render inner content
            foreach (var statement in Statements)
            {
                output.AppendLine(statement.GenerateBaseSource(indenter.Increase()));
            }

            // Close statement (with condition if this construct has a pre condition)
            output.Append(indenter.Indent + "Loop");
            if (!IsPreCondition && (ConditionIfAny != null))
            {
                output.Append(" ");
                if (IsDoWhileCondition)
                {
                    output.Append("While ");
                }
                else
                {
                    output.Append("Until ");
                }
                output.Append(ConditionIfAny.GenerateBaseSource(NullIndenter.Instance));
            }
            return(output.ToString());
        }
Esempio n. 5
0
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            var output = new StringBuilder();

            output.Append(indenter.Indent);
            output.Append("WITH ");
            output.AppendLine(Target.GenerateBaseSource(NullIndenter.Instance));

            foreach (var statement in Content)
            {
                output.AppendLine(statement.GenerateBaseSource(indenter.Increase()));
            }

            output.Append(indenter.Indent);
            output.Append("END WITH");
            return(output.ToString());
        }
Esempio n. 6
0
        // =======================================================================================
        // VBScript BASE SOURCE RE-GENERATION
        // =======================================================================================
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there
        /// should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            var output = new StringBuilder();

            var allClauses = ConditionalClauses.Cast <IfBlockSegment>().ToList();

            if (OptionalElseClause != null)
            {
                allClauses.Add(OptionalElseClause);
            }

            for (int index = 0; index < allClauses.Count; index++)
            {
                // Render branch start: IF / ELSEIF / ELSE
                var segment = allClauses[index];
                if (segment is IfBlockConditionSegment)
                {
                    output.Append(indenter.Indent);
                    if (index == 0)
                    {
                        output.Append("IF ");
                    }
                    else
                    {
                        output.Append("ELSEIF ");
                    }
                    output.Append(
                        ((IfBlockConditionSegment)segment).Condition.GenerateBaseSource(NullIndenter.Instance)
                        );
                    output.AppendLine(" THEN");
                }
                else
                {
                    output.AppendLine(indenter.Indent + "ELSE");
                }

                // Render branch content
                foreach (var statement in segment.Statements)
                {
                    output.AppendLine(statement.GenerateBaseSource(indenter.Increase()));
                }
            }
            output.Append(indenter.Indent + "END IF");
            return(output.ToString());
        }
        // =======================================================================================
        // VBScript BASE SOURCE RE-GENERATION
        // =======================================================================================
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there
        /// should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            StringBuilder output = new StringBuilder();

            // Open statement
            output.Append(indenter.Indent);
            output.Append("For Each ");
            output.Append(this.loopVar.Content);
            output.Append(" In ");
            output.AppendLine(this.loopSrc.GenerateBaseSource(NullIndenter.Instance));

            // Render inner content
            foreach (ICodeBlock statement in this.statements)
            {
                output.AppendLine(statement.GenerateBaseSource(indenter.Increase()));
            }

            // Close statement
            output.Append(indenter.Indent + "Next");
            return(output.ToString());
        }
Esempio n. 8
0
        // =======================================================================================
        // VBScript BASE SOURCE RE-GENERATION
        // =======================================================================================
        /// <summary>
        /// Re-generate equivalent VBScript source code for this block - there
        /// should not be a line return at the end of the content
        /// </summary>
        public string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            // Ensure derived class has behaved itself
            if ((this.keyWord ?? "").Trim() == "")
            {
                throw new Exception("Derived class has not defined non-blank/null keyWord");
            }

            // Render opening declaration (scope, name, arguments)
            StringBuilder output = new StringBuilder();

            output.Append(indenter.Indent);
            if (IsPublic)
            {
                output.Append("Public ");
            }
            else
            {
                output.Append("Private ");
            }
            if (IsDefault)
            {
                output.Append("Default ");
            }
            output.Append(this.keyWord + " ");
            output.Append(Name.Content);
            output.Append("(");
            var numberOfParameters = Parameters.Count();

            for (int index = 0; index < numberOfParameters; index++)
            {
                Parameter parameter = Parameters.ElementAt(index);
                if (parameter.ByRef)
                {
                    output.Append("ByRef ");
                }
                else
                {
                    output.Append("ByVal ");
                }
                output.Append(parameter.Name.Content);
                if (parameter.IsArray)
                {
                    output.Append("()");
                }
                if (index < (numberOfParameters - 1))
                {
                    output.Append(", ");
                }
            }
            output.AppendLine(")");

            // Render content
            foreach (var block in Statements)
            {
                output.AppendLine(block.GenerateBaseSource(indenter.Increase()));
            }

            // Close
            output.Append(indenter.Indent + "End " + this.keyWord);
            return(output.ToString());
        }