Ejemplo n.º 1
0
 private static CsExpression parseExpressionEquality(TokenJar tok, ref int i, bool tryNotToThrow = false)
 {
     var left = parseExpressionRelational(tok, ref i, tryNotToThrow);
     if (left == null)
         return null;
     while (tok[i].IsBuiltin("==") || tok[i].IsBuiltin("!="))
     {
         BinaryOperator op = tok[i].IsBuiltin("==") ? BinaryOperator.Eq : BinaryOperator.NotEq;
         i++;
         try
         {
             var right = parseExpressionRelational(tok, ref i);
             left = new CsBinaryOperatorExpression { StartIndex = left.StartIndex, EndIndex = right.EndIndex, Left = left, Right = right, Operator = op };
         }
         catch (ParseException e)
         {
             if (e.IncompleteResult is CsExpression)
                 throw new ParseException(e.Message, e.Index, new CsBinaryOperatorExpression { StartIndex = tok[i].StartIndex, Left = left, Right = (CsExpression) e.IncompleteResult, Operator = op }, e);
             throw new ParseException(e.Message, e.Index, left, e);
         }
     }
     return left;
 }
Ejemplo n.º 2
0
 private static CsExpression parseExpressionRelational(TokenJar tok, ref int i, bool tryNotToThrow = false)
 {
     var left = parseExpressionShift(tok, ref i, tryNotToThrow);
     if (left == null)
         return null;
     while (tok[i].IsBuiltin("<") || tok[i].IsBuiltin(">") || tok[i].IsBuiltin("<=") || tok[i].IsBuiltin(">=") || tok[i].IsBuiltin("is") || tok[i].IsBuiltin("as"))
     {
         if (tok[i].IsBuiltin("is") || tok[i].IsBuiltin("as"))
         {
             var op = tok[i].IsBuiltin("is") ? BinaryTypeOperator.Is : BinaryTypeOperator.As;
             i++;
             try
             {
                 var right = parseTypeName(tok, ref i, typeIdentifierFlags.AllowKeywords | typeIdentifierFlags.AllowNullablesAndPointers | typeIdentifierFlags.AllowArrays).Item1;
                 return new CsBinaryTypeOperatorExpression { StartIndex = left.StartIndex, EndIndex = right.EndIndex, Left = left, Right = right, Operator = op };
             }
             catch (ParseException e)
             {
                 if (e.IncompleteResult is CsTypeName)
                     throw new ParseException(e.Message, e.Index, new CsBinaryTypeOperatorExpression { StartIndex = tok[i].StartIndex, Left = left, Right = (CsTypeName) e.IncompleteResult, Operator = op }, e);
                 throw new ParseException(e.Message, e.Index, left, e);
             }
         }
         else
         {
             BinaryOperator op = tok[i].IsBuiltin("<") ? BinaryOperator.Less : tok[i].IsBuiltin("<=") ? BinaryOperator.LessEq : tok[i].IsBuiltin(">") ? BinaryOperator.Greater : BinaryOperator.GreaterEq;
             i++;
             try
             {
                 var right = parseExpressionShift(tok, ref i);
                 left = new CsBinaryOperatorExpression { StartIndex = left.StartIndex, EndIndex = right.EndIndex, Left = left, Right = right, Operator = op };
             }
             catch (ParseException e)
             {
                 if (e.IncompleteResult is CsExpression)
                     throw new ParseException(e.Message, e.Index, new CsBinaryOperatorExpression { StartIndex = tok[i].StartIndex, Left = left, Right = (CsExpression) e.IncompleteResult, Operator = op }, e);
                 throw new ParseException(e.Message, e.Index, left, e);
             }
         }
     }
     return left;
 }
Ejemplo n.º 3
0
 private static CsExpression parseExpressionCoalesce(TokenJar tok, ref int i, bool tryNotToThrow = false)
 {
     var left = parseExpressionBoolOr(tok, ref i, tryNotToThrow);
     if (left == null)
         return null;
     if (tok[i].IsBuiltin("??"))
     {
         i++;
         try
         {
             var right = parseExpressionCoalesce(tok, ref i);
             left = new CsBinaryOperatorExpression { StartIndex = left.StartIndex, EndIndex = right.EndIndex, Left = left, Right = right, Operator = BinaryOperator.Coalesce };
         }
         catch (ParseException e)
         {
             if (e.IncompleteResult is CsExpression)
                 throw new ParseException(e.Message, e.Index, new CsBinaryOperatorExpression { StartIndex = tok[i].StartIndex, Left = left, Right = (CsExpression) e.IncompleteResult, Operator = BinaryOperator.Coalesce }, e);
             throw new ParseException(e.Message, e.Index, left, e);
         }
     }
     return left;
 }
Ejemplo n.º 4
0
 private static CsExpression parseExpressionMultiplicative(TokenJar tok, ref int i, bool tryNotToThrow = false)
 {
     var left = parseExpressionUnary(tok, ref i, tryNotToThrow);
     if (left == null)
         return null;
     while (tok[i].IsBuiltin("*") || tok[i].IsBuiltin("/") || tok[i].IsBuiltin("%"))
     {
         BinaryOperator op = tok[i].IsBuiltin("*") ? BinaryOperator.Times : tok[i].IsBuiltin("/") ? BinaryOperator.Div : BinaryOperator.Mod;
         i++;
         try
         {
             var right = parseExpressionUnary(tok, ref i);
             left = new CsBinaryOperatorExpression { StartIndex = left.StartIndex, EndIndex = right.EndIndex, Left = left, Right = right, Operator = op };
         }
         catch (ParseException e)
         {
             if (e.IncompleteResult is CsExpression)
                 throw new ParseException(e.Message, e.Index, new CsBinaryOperatorExpression { StartIndex = tok[i].StartIndex, Left = left, Right = (CsExpression) e.IncompleteResult, Operator = op }, e);
             throw new ParseException(e.Message, e.Index, left, e);
         }
     }
     return left;
 }