示例#1
0
        public static IComparisonWithAdvance HTMLTag(
            ILog log,
            Options options,
            string tagName,
            OrComparison attributes,
            string name = null)
        {
            ICharComparison isWhitespace   = IsWhitespace(log);
            IOperation      skipWhitespace = SkipWhitespace(log);

            StatementList statementList = new StatementList(log);

            statementList.Name = name;

            statementList.Add(new CharComparison(log, options, '<'));
            statementList.Add(new StringComparison(log, options, tagName));
            statementList.Add(isWhitespace);

            // The reason for the or list is in case the tags appear in a different order on different browsers
            DelimitedListComparison list = new DelimitedListComparison(log, options, attributes, isWhitespace);

            statementList.Add(list);
            list.MinAmount = attributes.Count;
            list.MaxAmount = attributes.Count;

            statementList.Add(skipWhitespace);
            statementList.Add(new CharComparison(log, options, '>'));

            return(statementList);
        }
示例#2
0
        public static IComparisonWithAdvance CreateListOfTokens(
            Options options,
            IComparisonWithAdvance token,
            IComparisonWithAdvance segment,
            string name = null,
            ILog log    = null)
        {
            DelimitedListComparison list = new DelimitedListComparison(log, options, token, segment);

            list.MinAmount = 1;
            list.Name      = name;

            return(list);
        }
示例#3
0
        public static IComparisonWithAdvance CreateNumber(
            Options options,
            IComparisonWithAdvance end,
            string name = null,
            ILog log    = null)
        {
            //// List of 1 or 2 sets of numbers seperated by a .
            StatementList stmtList = new StatementList(log);

            stmtList.Name = name;

            OrComparison isDotOrEnd = new OrComparison(log);

            isDotOrEnd.Add(end);
            ICharComparison isDot = new CharComparison(log, options, '.');

            isDotOrEnd.Add(isDot);
            PatternComparison patternComp = new PatternComparison(log, options);

            patternComp.MinLength     = 1;
            patternComp.EndComparison = isDotOrEnd;

            // All characters must be between 0 and 9
            var allCharacters = new ComparisonRange <IComparisonWithAdvance>();

            allCharacters.Range.Min = 1;
            var isNumber = new CharDelegateComparison(log, Char.IsNumber);

            allCharacters.Comparison = isNumber;
            patternComp.AddComparisonRange(allCharacters);

            // List consisting of 1 or 2 items seperated by .
            DelimitedListComparison functionName = new DelimitedListComparison(log, options, patternComp, isDot);

            functionName.MinAmount = 1;
            functionName.MaxAmount = 2;
            stmtList.Add(functionName);
            return(stmtList);
        }
示例#4
0
        // From "response.write blah"
        // To "response.write(blah)"
        public static string AddParenthesisToFunctionCalls(
            ILog log,
            string input,
            out int numMatches,
            Action <Action <string, IAssertion> > fCreateAssertList = null)
        {
            // The parser object that will do the work
            Parser parser = new Parser(log);

            //// Parser options
            // This create a special line wrap
            Options parserOptions = TokenComparison.CreateVBScriptParserOptions(log);

            CharDelegateComparison isWhitespace   = new CharDelegateComparison(log, Char.IsWhiteSpace);
            IOperation             skipWhitespace = TokenComparison.SkipWhitespace(log);

            // State
            List <State> stateList = VBScriptState(log, parserOptions);

            // The main statement list
            StatementList mainStatements = new StatementList(log);

            // Capturing
            Dictionary <string, Capture> capturing = new Dictionary <string, Capture>();

            // Function name capture
            Capture funcNameCapture = new Capture(log);

            funcNameCapture.Name = "FunctionName";
            capturing.Add("funcName", funcNameCapture);
            mainStatements.Add(funcNameCapture);

            // Function name capture statements
            var           vbScriptKeywords          = TokenComparison.VBScriptKeywords(log, parserOptions);
            StatementList funcNameCaptureStatements = new StatementList(log);

            funcNameCapture.Comparison          = funcNameCaptureStatements;
            funcNameCaptureStatements.Exclusion = vbScriptKeywords;

            //// Starts with whitespace or is the start of the input string
            StartOfInputStringComparison isStartOfString            = new StartOfInputStringComparison(log);
            OrComparison startsWithWhitespaceOrIsStartOfInputString = new OrComparison(log);

            startsWithWhitespaceOrIsStartOfInputString.Add(isStartOfString);
            startsWithWhitespaceOrIsStartOfInputString.Add(isWhitespace);
            funcNameCaptureStatements.Add(startsWithWhitespaceOrIsStartOfInputString);

            // Skip whitespace
            funcNameCaptureStatements.Add(skipWhitespace);

            //// Function/sub name.
            //// For example: class1.Func or class1.Func"string arg"
            funcNameCaptureStatements.Add(TokenComparison.CreateVBScriptSub(parserOptions, name: null, log: log));

            //// Arguments list
            // Skip whitespace and don't capture it
            mainStatements.Add(skipWhitespace);

            // Capture
            Capture argListCapture = new Capture(log);

            capturing.Add("funcArgs", argListCapture);
            mainStatements.Add(argListCapture);

            // Function argument list capture statements
            StatementList argListCaptureStatements = new StatementList(log);

            argListCapture.Comparison = argListCaptureStatements;

            // Skip the line wrap (and capture it)
            argListCaptureStatements.Add(parserOptions.SkipLineWrapOperation);

            // Concatenated single arguments
            // Delimited by whitespace, comma & or +
            var vbScriptConcatCommaOrWhitespaceOrEnd =
                TokenComparison.CreateVBScriptConcatCommaOrWhitespaceOrEnd(log, parserOptions);

            // Numbers
            var numberComparison =
                TokenComparison.CreateNumber(parserOptions, vbScriptConcatCommaOrWhitespaceOrEnd, "ArgsNumber", log: log);
            // VB script quoted strings
            var quotedText = TokenComparison.CreateVBScriptQuotedString(parserOptions, name: "Args quoted text", log: log);
            // VB script function which could include arguments, or a variable name
            var VbScriptFunctionOrVar = TokenComparison.CreateVBScriptFunctionOrVar(
                parserOptions,
                vbScriptConcatCommaOrWhitespaceOrEnd,
                vbScriptKeywords,
                "VbScriptFunctionOrVar",
                log: log);

            // Individual arguments
            // Types
            OrComparison individualArgumentTypes = new OrComparison(log);

            individualArgumentTypes.Add(numberComparison);
            individualArgumentTypes.Add(quotedText);
            individualArgumentTypes.Add(VbScriptFunctionOrVar);

            // List delimiter for the individual arguments
            OrComparison vbScriptConcactOrComma = new OrComparison(log);

            {
                var matchAmpersand = new CharComparison(log, parserOptions, '&');
                matchAmpersand.Name = "ArgsStringConcatenation";
                vbScriptConcactOrComma.Add(matchAmpersand);
            }
            vbScriptConcactOrComma.Add(new CharComparison(log, parserOptions, '+'));
            var isComma = new CharComparison(log, parserOptions, ',');

            vbScriptConcactOrComma.Add(isComma);

            DelimitedListComparison individualArgumentList = new DelimitedListComparison(
                log, parserOptions, individualArgumentTypes, seperator: vbScriptConcactOrComma
                );

            individualArgumentList.MinAmount = 1;
            individualArgumentList.ItemTrim  = skipWhitespace;

            // The argument list - comma seperated list of function arguments
            DelimitedListComparison argumentList = new DelimitedListComparison(
                log, parserOptions, individualArgumentList, seperator: isComma
                );

            argumentList.Name      = "ArgumentList";
            argumentList.MinAmount = 1;
            argumentList.ItemTrim  = skipWhitespace;
            argListCaptureStatements.Add(argumentList);

            Action <RunState> InitRunState = null;

            if (fCreateAssertList != null)
            {
                InitRunState = (runState) => {
                    fCreateAssertList(runState.AddAssertion);
                };
            }

            const string replaceWith = "'funcName'('funcArgs')";
            string       replaced    = parser.Replace(
                input, replaceWith, mainStatements, capturing, stateList, out numMatches, null, InitRunState
                );

            return(replaced);
        }