Exemple #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)
        {
            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());
        }
Exemple #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 virtual string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            var output = new StringBuilder();

            output.Append(indenter.Indent);
            output.Append("Dim ");
            var numberOfVariables = Variables.Count();

            foreach (var indexedVariable in Variables.Select((v, i) => new { Variable = v, Index = i }))
            {
                output.Append(indexedVariable.Variable.Name.Content);
                if (indexedVariable.Variable.Dimensions != null)
                {
                    output.Append("(");
                    var numberOfDimensions = indexedVariable.Variable.Dimensions.Count();
                    foreach (var indexedDimension in indexedVariable.Variable.Dimensions.Select((d, i) => new { Dimension = d, Index = i }))
                    {
                        output.Append(indexedDimension.Dimension.GenerateBaseSource(NullIndenter.Instance));
                        if (indexedDimension.Index < (numberOfDimensions - 1))
                        {
                            output.Append(", ");
                        }
                    }
                    output.Append(")");
                }
                if (indexedVariable.Index < (numberOfVariables - 1))
                {
                    output.Append(", ");
                }
            }
            return(output.ToString());
        }
 /// <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 virtual string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
 {
     return(string.Format(
                "{0}Const {1}",
                indenter.Indent,
                string.Join(", ", Values.Select(v => v.Name + " = " + v.Value))
                ));
 }
Exemple #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)
 {
     if (Content.Trim() == "")
     {
         return("");
     }
     return(indenter.Indent + "'" + Content);
 }
Exemple #5
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());
        }
        // =======================================================================================
        // 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.Append(indenter.Indent);
            output.Append("Randomize");
            if (SeedIfAny != null)
            {
                output.Append(" ");
                output.Append(SeedIfAny.GenerateBaseSource(NullIndenter.Instance));
            }
            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)
        {
            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());
        }
Exemple #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)
        {
            // The Statement class' GenerateBaseSource has logic about rendering strings of tokens and rules about whitespace around
            // (or not around) particular tokens, so the content from this class is wrapped up as a Statement so that the method may
            // be re-used without copying any of it here
            var assignmentOperator = AtomToken.GetNewToken("=", ValueToSet.Tokens.Last().LineIndex);
            var tokensList         = ValueToSet.Tokens.Concat(new[] { assignmentOperator }).Concat(Expression.Tokens).ToList();

            if (ValueSetType == ValueSetTypeOptions.Set)
            {
                tokensList.Insert(0, AtomToken.GetNewToken("Set", ValueToSet.Tokens.First().LineIndex));
            }

            return((new Statement(tokensList, Statement.CallPrefixOptions.Absent)).GenerateBaseSource(indenter));
        }
        // =======================================================================================
        // 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 tokensList = Tokens.ToList();

            if (CallPrefix == CallPrefixOptions.Present)
            {
                tokensList.Insert(0, AtomToken.GetNewToken("Call", tokensList[0].LineIndex));
            }

            var output = new StringBuilder();

            output.Append(indenter.Indent);
            for (int index = 0; index < tokensList.Count; index++)
            {
                var token = tokensList[index];
                if (token is StringToken)
                {
                    output.Append("\"" + token.Content + "\"");
                }
                else if (token is DateLiteralToken)
                {
                    output.Append("#" + token.Content + "#");
                }
                else
                {
                    output.Append(token.Content);
                }

                var nextToken = (index < (tokensList.Count - 1)) ? tokensList[index + 1] : null;
                if (nextToken == null)
                {
                    continue;
                }

                if ((token is MemberAccessorOrDecimalPointToken) ||
                    (token is OpenBrace) ||
                    (nextToken is MemberAccessorOrDecimalPointToken) ||
                    (nextToken is ArgumentSeparatorToken) ||
                    (nextToken is OpenBrace) ||
                    (nextToken is CloseBrace))
                {
                    continue;
                }

                output.Append(" ");
            }
            return(output.ToString().TrimEnd());
        }
Exemple #10
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());
        }
        /// <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());
        }
        // =======================================================================================
        // 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 override string GenerateBaseSource(SourceRendering.ISourceIndentHandler indenter)
        {
            // Grab content from DimStatement..
            string baseContent = base.GenerateBaseSource(NullIndenter.Instance);

            if ((baseContent == null) ||
                (baseContent.Length < 4) ||
                (baseContent.Substring(0, 4).ToUpper() != "DIM "))
            {
                throw new Exception("Unexpected content from base class");
            }

            // .. and change to be ReDim (add in Preserve keyword, if required)
            StringBuilder output = new StringBuilder();

            output.Append(indenter.Indent);
            output.Append("Public ");
            output.Append(baseContent.Substring(4));
            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());
        }
Exemple #15
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("ERASE ");
            foreach (var indexedTarget in Targets.Select((t, i) => new { Index = i, Value = t }))
            {
                if (indexedTarget.Index > 0)
                {
                    output.Append(", ");
                }

                if (indexedTarget.Value.WrappedInBraces)
                {
                    output.Append("(");
                }

                output.Append(indexedTarget.Value.Target.GenerateBaseSource(NullIndenter.Instance));
                if (indexedTarget.Value.ArgumentsIfAny != null)
                {
                    output.Append("(");
                    foreach (var indexedArgument in indexedTarget.Value.ArgumentsIfAny.Select((a, i) => new { Index = i, Value = a }))
                    {
                        if (indexedArgument.Index > 0)
                        {
                            output.Append(", ");
                        }
                        output.Append(indexedArgument.Value.GenerateBaseSource(NullIndenter.Instance));
                    }
                    output.Append(")");
                }

                if (indexedTarget.Value.WrappedInBraces)
                {
                    output.Append(")");
                }
            }
            return(output.ToString());
        }
Exemple #16
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)
 {
     return("");
 }
 // =======================================================================================
 // 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)
 {
     return(indenter.Indent + "ON ERROR RESUME NEXT");
 }
Exemple #18
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());
        }
 // =======================================================================================
 // 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)
 {
     return(indenter.Indent + "Option Explicit");
 }
Exemple #20
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)
 {
     return(indenter.Indent + "Exit " + StatementType.ToString());
 }