Ejemplo n.º 1
0
        public static int CompareByRange(
            ComparisonRange <COMP_TYPE> lhs,
            ComparisonRange <COMP_TYPE> rhs)
        {
            IComparable comp = lhs.Range;

            return(comp.CompareTo(rhs.Range));
        }
Ejemplo n.º 2
0
        public static IComparisonWithAdvance CreateVBScriptQuotedString(
            Options options,
            string name = null,
            ILog log    = null)
        {
            // We can use a pattern comparison to do this
            // First character is a quote
            // Subsequent characters can either be anything BUT a single ", or double "" but advance 2.
            // Although it seems un-intuitive this gives us the behaviour we require: skip double quotes.

            var isQuote = new CharComparison(log, options, '\"');

            // This requires more than one statement
            StatementList statementList = new StatementList(log);

            statementList.Name = name;

            // The pattern comparison that will do the work
            PatternComparison patternComp = new PatternComparison(log, options);

            statementList.Add(patternComp);
            patternComp.MinLength = 2;

            // First character is open quote
            var first = new ComparisonRange <IComparisonWithAdvance>();

            first.Range.Min  = 1;
            first.Range.Max  = 1;
            first.Comparison = isQuote;
            patternComp.AddComparisonRange(first);

            // Subsequent characters
            var subsequent = new ComparisonRange <IComparisonWithAdvance>();

            subsequent.Range.Min = 2;
            OrComparison isNotSingleQuoteOrIsDoubleQuotesAndAdvance2 = new OrComparison(log);
            var          notQuote = new NotCharComparison(log, isQuote);

            isNotSingleQuoteOrIsDoubleQuotesAndAdvance2.Add(notQuote);
            var doubleQuote = new StringComparison(log, options, "\"\"");

            isNotSingleQuoteOrIsDoubleQuotesAndAdvance2.Add(doubleQuote);
            subsequent.Comparison = isNotSingleQuoteOrIsDoubleQuotesAndAdvance2;
            patternComp.AddComparisonRange(subsequent);

            // End when find the terminating "
            patternComp.EndComparison = isQuote;

            // Skip the trailing quote by advancing by 1
            statementList.Add(new OffsetAdvance(log, 1));
            return(statementList);
        }
Ejemplo n.º 3
0
        // E.g. Test123 matches
        // 1Test123 doesn't (cann't lead with a number)
        // test"123 doesn't match (can only contain letters and numbers)
        public static IComparisonWithAdvance CreateIdentifier(
            Options options,
            IComparisonWithAdvance end,
            IComparison exclusion,
            string name = null,
            ILog log    = null)
        {
            StatementList stmtList = new StatementList(log);

            stmtList.Name = name;

            PatternComparison patternComp = new PatternComparison(log, options);

            patternComp.EndComparison = end;
            patternComp.MinLength     = 1;

            // First character is a letter
            var firstCharacter = new ComparisonRange <IComparisonWithAdvance>();

            firstCharacter.Range.Min = 1;
            firstCharacter.Range.Max = 1;
            var isLetter = new CharDelegateComparison(log, Char.IsLetter);

            firstCharacter.Comparison = isLetter;
            patternComp.AddComparisonRange(firstCharacter);

            // Subsequent (2+) characters can be a letter or digit (0-9)
            var subsequentCharacters = new ComparisonRange <IComparisonWithAdvance>();

            subsequentCharacters.Range.Min = 2;
            var isLetterOrDigit = new CharDelegateComparison(log, Char.IsLetterOrDigit);

            subsequentCharacters.Comparison = isLetterOrDigit;
            patternComp.AddComparisonRange(subsequentCharacters);

            stmtList.Add(patternComp);

            stmtList.Exclusion = exclusion;

            return(stmtList);
        }
Ejemplo n.º 4
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);
        }