示例#1
0
        public TextLine(string text)
        {
            // Set the text
            this.Text = text;

            // Parse the words
            this.Words = CSharpCodeParser.ParseWords(text);
        }
示例#2
0
        public TextLine(string text, int lineNumber)
        {
            // Set the text
            this.Text = text;

            // Set the LineNumber
            this.LineNumber = lineNumber;

            // Parse the words
            this.Words = CSharpCodeParser.ParseWords(text);
        }
示例#3
0
        /// <summary>
        /// This method attempts to parse an IfStatement object out of the sourceCode given.
        /// </summary>
        public static IfStatement ParseIfStatement(string sourceCode, int level = 1)
        {
            // initial value
            IfStatement ifStatement = null;

            // local
            int                openParenCount  = 0;
            int                closeParenCount = 0;
            int                openParenIndex  = 0;
            int                closeParenIndex = 0;
            char               openParen       = OpenParenString[0];
            char               closeParen      = CloseParenString[0];
            int                len             = 0;
            string             innerCode       = "";
            string             source          = "";
            string             op             = "";
            string             target         = "";
            ComparisonTypeEnum comparisonType = ComparisonTypeEnum.NotSet;

            // if the sourceCode exists
            if (!String.IsNullOrEmpty(sourceCode))
            {
                // trim the sourceCode
                sourceCode = sourceCode.Trim();

                // if this is an ifStatement
                if (sourceCode.StartsWith("if"))
                {
                    // set the count of each character to make sure we have a valid ifStatement
                    openParenCount  = GetOccurrencesOfChar(sourceCode, openParen);
                    closeParenCount = GetOccurrencesOfChar(sourceCode, closeParen);

                    // if this is a 'Simple' IfStatement
                    if ((openParenCount == closeParenCount) && (openParenCount == 1))
                    {
                        // get the index of the openParen
                        openParenIndex  = sourceCode.IndexOf(openParen);
                        closeParenIndex = sourceCode.IndexOf(closeParen);
                        len             = closeParenIndex - openParenIndex - 1;

                        // set the inner code
                        innerCode = sourceCode.Substring(openParenIndex + 1, len);

                        // if the innerCode exists
                        if (!String.IsNullOrEmpty(innerCode))
                        {
                            // get the words
                            List <Word> words = CSharpCodeParser.ParseWords(innerCode);

                            // if the words collection existsre are exactly 3 words
                            if (words != null)
                            {
                                // if there is only one word
                                if (words.Count == 1)
                                {
                                    // set the sourceWord
                                    source = words[0].Text;

                                    // if this is a NotComparison
                                    bool isEqual = (!source.StartsWith("!"));

                                    // create the ifStatement
                                    ifStatement = new IfStatement(source, isEqual, level);
                                }
                                // if there are exactly 3 words
                                else if (words.Count == 3)
                                {
                                    // parse out the items that build the ifStatement
                                    source = words[0].Text;
                                    op     = words[1].Text;
                                    target = words[2].Text;

                                    // Get the comparisonType for the operator
                                    comparisonType = IfStatementParser.GetComparisonType(op);

                                    // now create the ifStatement
                                    ifStatement = new IfStatement(source, comparisonType, target, level);
                                }
                            }
                        }
                    }
                }
            }

            // return value
            return(ifStatement);
        }