Esempio n. 1
0
        public override MatchContext Match(Token token, MatchContext context)
        {
            MatchContext newContext;

            if (!(token is CommentLiteral))
            {
                string tokenText = token.TextValue;
                if (token.Root.Language.IsCaseInsensitive)
                {
                    TextSpan textSpan = caseInsensitiveRegex.Match(tokenText).GetTextSpan(tokenText);
                    if (!textSpan.IsZero)
                    {
                        newContext = context.AddMatch(token);
                    }
                    else
                    {
                        newContext = context.Fail();
                    }
                }
                else if (id.Equals(tokenText))
                {
                    newContext = context.AddMatch(token);
                }
                else
                {
                    newContext = context.Fail();
                }
            }
            else
            {
                newContext = context.Fail();
            }

            return(newContext);
        }
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            if (ust is IntLiteral intLiteral)
            {
                return(MinValue <= intLiteral.Value && MaxValue > intLiteral.Value
                    ? context.AddMatch(intLiteral)
                    : context.Fail());
            }
            if (ust is LongLiteral longLiteral)
            {
                return(MinValue <= longLiteral.Value && MaxValue > longLiteral.Value
                    ? context.AddMatch(longLiteral)
                    : context.Fail());
            }
            if (ust is BigIntLiteral bigIntLiteral)
            {
                return(MinValue <= bigIntLiteral.Value && MaxValue > bigIntLiteral.Value
                    ? context.AddMatch(bigIntLiteral)
                    : context.Fail());
            }

            if (context.UstConstantFolder != null &&
                context.UstConstantFolder.TryGetOrFold(ust, out FoldResult foldingResult))
            {
                context.MatchedWithFolded = true;
                if (foldingResult.Value is long longValue)
                {
                    return(MinValue <= longValue && MaxValue > longValue
                        ? context.AddMatches(foldingResult.TextSpans)
                        : context.Fail());
                }
            }

            return(context.Fail());
        }
Esempio n. 3
0
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            var idToken = ust as IdToken;

            if (idToken == null)
            {
                return(context.Fail());
            }

            MatchContext newContext = context;

            if (ust.Parent is AssignmentExpression parentAssignment &&
                ReferenceEquals(idToken, parentAssignment.Left))
            {
                if (Value != null)
                {
                    newContext = Value.MatchUst(idToken, newContext);
                    if (newContext.Success)
                    {
                        newContext.Vars[Id] = idToken;
                    }
                }
                else
                {
                    newContext.Vars[Id] = idToken;
                    newContext          = newContext.AddMatch(idToken);
                }
            }
Esempio n. 4
0
        public override MatchContext Match(Ust ust, MatchContext context)
        {
            MatchContext newContext = Pattern.MatchUst(ust, context);

            return(newContext.Success
                ? newContext.Fail()
                : newContext.AddMatch(ust));
        }
Esempio n. 5
0
        public override MatchContext Match(ThrowStatement throwStatement, MatchContext context)
        {
            MatchContext newContext = Expression.MatchUst(throwStatement.ThrowExpression, context);

            return(newContext.Success
                ? newContext.AddMatch(throwStatement)
                : newContext.Fail());
        }
Esempio n. 6
0
        public override MatchContext Match(ReturnStatement returnStatement, MatchContext context)
        {
            MatchContext newContext = Expression.MatchUst(returnStatement.Return, context);

            return(newContext.Success
                ? newContext.AddMatch(returnStatement)
                : newContext.Fail());
        }
Esempio n. 7
0
        public override MatchContext Match(Ust ust, MatchContext context)
        {
            if (ust == null)
            {
                return(context.MakeSuccess());
            }

            return(context.AddMatch(ust));
        }
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            var baseReferenceToken = ust as BaseReferenceToken;

            if (baseReferenceToken == null)
            {
                return(context.Fail());
            }

            return(context.AddMatch(ust));
        }
 protected override MatchContext Match(Ust ust, MatchContext context)
 {
     if (ust is TupleCreateExpression)
     {
         return(context.AddMatch(ust));
     }
     else
     {
         return(context.Fail());
     }
 }
Esempio n. 10
0
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            switch (ust)
            {
            case IntLiteral intLiteral:
                return(Value == intLiteral.Value
                    ? context.AddMatch(ust)
                    : context.Fail());

            case LongLiteral longLiteral:
                return(Value == longLiteral.Value
                    ? context.AddMatch(ust)
                    : context.Fail());

            case BigIntLiteral bigIntLiteral:
                return(Value == bigIntLiteral.Value
                    ? context.AddMatch(ust)
                    : context.Fail());
            }

            if (context.UstConstantFolder != null &&
                context.UstConstantFolder.TryGetOrFold(ust, out FoldResult foldingResult))
            {
                context.MatchedWithFolded = true;
                if (foldingResult.Value is int intValue)
                {
                    return(Value == intValue?context.AddMatches(foldingResult.TextSpans) : context.Fail());
                }
                if (foldingResult.Value is long longValue)
                {
                    return(Value == longValue?context.AddMatches(foldingResult.TextSpans) : context.Fail());
                }
                if (foldingResult.Value is BigInteger bigIntValue)
                {
                    return(Value == bigIntValue?context.AddMatches(foldingResult.TextSpans) : context.Fail());
                }
            }

            return(context.Fail());
        }
Esempio n. 11
0
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            foreach (PatternUst pattern in Patterns)
            {
                context = pattern.MatchUst(ust, context);
                if (!context.Success)
                {
                    return(context.Fail());
                }
            }

            return(context.AddMatch(ust));
        }
Esempio n. 12
0
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            var booleanLiteral = ust as BooleanLiteral;

            if (booleanLiteral == null)
            {
                return(context.Fail());
            }

            return((Boolean == null || Boolean.Value.Equals(booleanLiteral.Value))
                ? context.AddMatch(booleanLiteral)
                : context.Fail());
        }
Esempio n. 13
0
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            var binaryOperatorLiteral = ust as BinaryOperatorLiteral;

            if (binaryOperatorLiteral == null)
            {
                return(context.Fail());
            }

            return(BinaryOperator.Equals(binaryOperatorLiteral.BinaryOperator)
                ? context.AddMatch(binaryOperatorLiteral)
                : context.Fail());
        }
Esempio n. 14
0
        public override MatchContext Match(Ust ust, MatchContext context)
        {
            MatchContext newContext = context;

            foreach (PatternUst pattern in Patterns)
            {
                newContext = pattern.MatchUst(ust, newContext);
                if (!newContext.Success)
                {
                    return(newContext.Fail());
                }
            }

            return(newContext.AddMatch(ust));
        }
Esempio n. 15
0
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            var returnStatement = ust as ReturnStatement;

            if (returnStatement == null)
            {
                return(context.Fail());
            }

            MatchContext newContext = Expression.MatchUst(returnStatement.Return, context);

            return(newContext.Success
                ? newContext.AddMatch(returnStatement)
                : newContext.Fail());
        }
Esempio n. 16
0
        protected override MatchContext Match(Ust ust, MatchContext context)
        {
            if (ust is StringLiteral stringLiteral)
            {
                return(String.Equals(stringLiteral.Text) ? context.AddMatch(stringLiteral) : context.Fail());
            }

            if (context.UstConstantFolder != null &&
                context.UstConstantFolder.TryGetOrFold(ust, out FoldResult foldingResult))
            {
                context.MatchedWithFolded = true;
                if (foldingResult.Value is string stringValue)
                {
                    return(String.Equals(stringValue) ? context.AddMatches(foldingResult.TextSpans) : context.Fail());
                }
            }

            return(context.Fail());
        }
Esempio n. 17
0
        public override MatchContext Match(IdToken idToken, MatchContext context)
        {
            MatchContext newContext;

            newContext = context;
            if (idToken.Parent is AssignmentExpression parentAssignment &&
                ReferenceEquals(idToken, parentAssignment.Left))
            {
                if (Value != null)
                {
                    newContext = Value.MatchUst(idToken, newContext);
                    if (newContext.Success)
                    {
                        newContext.Vars[Id] = idToken;
                    }
                }
                else
                {
                    newContext.Vars[Id] = idToken;
                    newContext          = newContext.AddMatch(idToken);
                }
            }
 protected override MatchContext Match(Ust ust, MatchContext context)
 {
     return(ust is Expression expression
         ? context.AddMatch(expression)
         : context.Fail());
 }
Esempio n. 19
0
 public override MatchContext Match(ThisReferenceToken thisReferenceToken, MatchContext context)
 {
     return(context.AddMatch(thisReferenceToken));
 }
Esempio n. 20
0
 public override MatchContext Match(Expression expression, MatchContext context)
 {
     return(context.AddMatch(expression));
 }
Esempio n. 21
0
 protected override MatchContext Match(Ust ust, MatchContext context)
 {
     return(ust is NullLiteral nullLiteral
         ? context.AddMatch(nullLiteral)
         : context.Fail());
 }
Esempio n. 22
0
 public override MatchContext Match(BooleanLiteral booleanLiteral, MatchContext context)
 {
     return((Boolean == null || Boolean.Value.Equals(booleanLiteral.Value))
         ? context.AddMatch(booleanLiteral)
         : context.Fail());
 }
Esempio n. 23
0
 public override MatchContext Match(StringLiteral stringLiteral, MatchContext context)
 {
     return(String.Equals(stringLiteral.Text)
         ? context.AddMatch(stringLiteral)
         : context.Fail());
 }
Esempio n. 24
0
        public override MatchContext Match(Ust ust, MatchContext context)
        {
            var blockStatement = ust as BlockStatement;

            if (blockStatement == null ||
                (!(blockStatement.Parent is MethodDeclaration) &&
                 !(blockStatement.Parent is ConstructorDeclaration) &&
                 !(blockStatement.Parent is NamespaceDeclaration) &&
                 !(blockStatement.Parent is RootUst)))
            {
                return(context.Fail());
            }

            MatchContext newContext = MatchContext.CreateWithInputParamsAndVars(context);

            if (Statements == null || Statements.Count == 0)
            {
                if (blockStatement.Statements == null || blockStatement.Statements.Count == 0)
                {
                    newContext = newContext.AddMatch(blockStatement);
                }
                else
                {
                    return(context.Fail());
                }
            }
            else
            {
                IEnumerable <Statement> statements = blockStatement.Statements
                                                     .Where(statement =>
                                                            !(statement is TypeDeclarationStatement) &&
                                                            !(statement is WrapperStatement));
                Expression[] expressions = statements.SelectMany(statement =>
                                                                 statement
                                                                 .WhereDescendants(descendant =>
                                                                                   descendant is Expression expressionDescendant &&
                                                                                   !(expressionDescendant is Token)))
                                           .Cast <Expression>()
                                           .ToArray();

                var  matchedTextSpans    = new List <TextSpan>();
                int  patternStatementInd = 0;
                bool success             = false;
                for (int i = 0; i < expressions.Length; i++)
                {
                    newContext = MatchContext.CreateWithInputParamsAndVars(newContext);
                    newContext = Statements[patternStatementInd].MatchUst(expressions[i], newContext);
                    if (newContext.Success)
                    {
                        matchedTextSpans.AddRange(newContext.Locations);
                        patternStatementInd += 1;
                        if (patternStatementInd == Statements.Count)
                        {
                            success             = true;
                            patternStatementInd = 0;
                        }
                    }
                }

                if (success)
                {
                    context = context.AddMatches(matchedTextSpans);
                }
                else
                {
                    context = context.Fail();
                }
            }

            return(context);
        }
Esempio n. 25
0
 public override MatchContext Match(BaseReferenceToken ust, MatchContext context)
 {
     return(context.AddMatch(ust));
 }
Esempio n. 26
0
 public void AddMatch(Match match)
 {
     MatchContext.AddMatch(match);
 }
Esempio n. 27
0
 public override MatchContext Match(IntLiteral intLiteral, MatchContext context)
 {
     return(intLiteral.Value == Value
         ? context.AddMatch(intLiteral)
         : context.Fail());
 }
Esempio n. 28
0
 public override MatchContext Match(NullLiteral nullLiteral, MatchContext context)
 {
     return(context.AddMatch(nullLiteral));
 }
 protected override MatchContext Match(Ust ust, MatchContext context)
 {
     return(ust is ThisReferenceToken thisReferenceToken
         ? context.AddMatch(thisReferenceToken)
         : context.Fail());
 }
 public override MatchContext Match(BinaryOperatorLiteral binaryOperatorLiteral, MatchContext context)
 {
     return(BinaryOperator.Equals(binaryOperatorLiteral.BinaryOperator)
         ? context.AddMatch(binaryOperatorLiteral)
         : context.Fail());
 }