//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected org.boris.expr.Expr parseExpression(String paramString) throws org.boris.expr.ExprException
        protected internal virtual Expr parseExpression(string paramString)
        {
            Expr expr;

            if (!paramString.StartsWith("=", StringComparison.Ordinal))
            {
                expr = Exprs.parseValue(paramString);
            }
            else
            {
                paramString = paramString.Substring(1);
                ExprParser exprParser = new ExprParser();
                exprParser.ParserVisitor = this;
                try
                {
                    exprParser.parse(new ExprLexer(paramString));
                }
                catch (IOException iOException)
                {
                    throw new ExprException(iOException);
                }
                expr = exprParser.get();
            }
            return(expr);
        }
Example #2
0
        public virtual Expr parseStatement(string paramString)
        {
            paramString = StringUtils.escapeParametricExpression(paramString);
            ExprParser exprParser = new ExprParser();

            try
            {
                exprParser.parse(new ExprLexer(paramString));
            }
            catch (IOException iOException)
            {
                Console.WriteLine(iOException.ToString());
                Console.Write(iOException.StackTrace);
                throw new ExprException(iOException.Message);
            }
            Expr expr = exprParser.get();

            Exprs.ToUpper(expr);
            if (expr is ExprEvaluatable)
            {
                expr = ((ExprEvaluatable)expr).evaluate(this);
            }
            else
            {
                throw new ExprException("Not Evaluatable result for: " + paramString);
            }
            return(expr);
        }
Example #3
0
 public WindowFuncExpr(Identifier serverName
                       , Identifier databaseName
                       , Identifier schemaName
                       , Identifier name
                       , Exprs arguments
                       , PartitionBy partitionBy
                       , OrderBy orderBy)
 {
     this.Comments     = new Comments(6);
     this.ServerName   = serverName;
     this.DataBaseName = databaseName;
     this.SchemaName   = schemaName;
     this.Name         = name;
     this.Quantifier   = QuantifierType.None;
     this.HasWildcard  = false;
     this.Arguments    = arguments;
     this.PartitionBy  = partitionBy;
     this.OrderBy      = orderBy;
     //
     if (this.PartitionBy != null)
     {
         this.PartitionBy.Parent = this;
     }
     if (this.OrderBy != null)
     {
         this.OrderBy.Parent = this;
     }
 }
        private Expr ConstructBinaryExpr(List <Expr> pathExps)
        {
            // Case 1: Simple addition of @home and "\build\script.xml" as in "@home\build\script.xml"
            if (pathExps.Count == 2)
            {
                return(Exprs.Binary(pathExps[0], Operator.Add, pathExps[1], pathExps[0].Token));
            }
            // Case 2: Add up all the expressions.
            // Start with the last 2 and keep adding backwards.
            // e.g. 0 1 2 3
            // Exp1: Bin( 2, add, 3 )
            // Exp2: Bin( 1, Exp1 )
            // Exp3: Bin( 0, Exp2 )
            // e.g.  Bin( 0, add, Bin( 1, add, Bin( 2, add, 3 ) ) )
            var lastIndex = pathExps.Count - 1;
            var left      = pathExps[lastIndex - 1];
            var right     = pathExps[lastIndex];
            var exp       = Exprs.Binary(left, Operator.Add, right, left.Token);

            for (var ndx = lastIndex - 2; ndx >= 0; ndx--)
            {
                left = pathExps[ndx];
                exp  = Exprs.Binary(left, Operator.Add, exp, left.Token);
            }
            return(exp);
        }
Example #5
0
 internal WindowFuncExpr(Identifier serverName
                         , Identifier databaseName
                         , Identifier schemaName
                         , Identifier name
                         , QuantifierType quantifier
                         , bool hasWildcard
                         , Exprs arguments
                         , PartitionBy partitionBy
                         , OrderBy orderBy
                         , Comments comments)
 {
     this.Comments    = comments;
     _serverName      = serverName;
     _dataBaseName    = databaseName;
     _schemaName      = schemaName;
     _name            = name;
     _quantifier      = quantifier;
     _hasWildcard     = hasWildcard;
     this.Arguments   = arguments;
     this.PartitionBy = partitionBy;
     this.OrderBy     = orderBy;
     //
     if (this.PartitionBy != null)
     {
         this.PartitionBy.Parent = this;
     }
     if (this.OrderBy != null)
     {
         this.OrderBy.Parent = this;
     }
 }
        public override void ExitInPredicate(MiniSqlParserParser.InPredicateContext context)
        {
            var comments = this.GetComments(context);

            Exprs  exprs = null;
            IQuery query = null;

            if (context.exprs() != null)
            {
                exprs = (Exprs)_stack.Pop();
            }
            else if (context.query() != null)
            {
                query = (IQuery)_stack.Pop();
            }
            else
            {
                exprs = new Exprs();
            }
            var operand = (Expr)_stack.Pop();
            var not     = context.K_NOT() != null;

            var node = new InPredicate(operand, not, exprs, query, comments);

            _stack.Push(node);
        }
Example #7
0
        private VariableExpr ParseVariable()
        {
            var nameToken = _tokenIt.NextToken;
            var name      = _tokenIt.ExpectId();

            return(Exprs.Ident(name, nameToken) as VariableExpr);
        }
Example #8
0
        /// <summary>
        /// Sorts expression
        /// </summary>
        /// <returns></returns>
        public override Expr Parse(object context)
        {
            var startToken = _tokenIt.NextToken;
            var constExp   = context as ConstantExpr;
            var ctx        = _parser.Context;

            var percentToken = _tokenIt.Peek(1);
            var numberVal    = (LObject)constExp.Value;

            // Validate
            if (numberVal.Type != LTypes.Number)
            {
                throw _tokenIt.BuildSyntaxException("number required when percentage( % ) : " + percentToken.Token.Text, percentToken);
            }

            // Move past the current "%" token.
            var t = _tokenIt.Advance(2);

            var val = ((LNumber)numberVal).Value;

            val = val / 100;
            var finalExp = Exprs.Const(new LNumber(val), startToken);

            return(finalExp);
        }
Example #9
0
 public Call(IdentifierToken name, Exprs args, SrcLoc location = null)
     :
     base(location)
 {
     Name = name;
     Args = args;
 }
Example #10
0
        protected override IType ValidateExpr(Environment env)
        {
            EnsureValidBinding(env);

            if (!(Binding.Type is IFunctionType func))
            {
                throw new TranspilationException($"Cannot invoke non-invokable '{Name}'", Location);
            }

            AssertParameterCount(func);

            Exprs.ForEach(expr => expr.Validate(env));

            if (func is GenericFunctionWrapper wrapper)
            {
                func = SpecifyFunc(wrapper, env);
            }
            else if (Handle != null)
            {
                throw new TranspilationException($"Cannot specify generic types for non-generic function '{Name}'.", Location);
            }

            foreach (var(expr, type) in Exprs.Zip(func.ParameterTypes))
            {
                expr.AssertType(type);
            }

            // We re-assign the name such that it will be converted properly
            Name = Binding?.Name ?? Name;

            return(func.ReturnType);
        }
Example #11
0
        /// <summary>
        /// Creates a constant number
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public object ToConstantNumber(BindingCallExpr expr)
        {
            var num   = Convert.ToDouble(expr.ParamList[0]);
            var token = expr.ParamList[1] as TokenData;

            return(Exprs.Const(new LNumber(num), token));
        }
Example #12
0
        /// <summary>
        /// Parses the time expression.
        /// - 12pm
        /// - 12:30pm
        /// - 12:30 pm
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            var startToken = _tokenIt.NextToken;
            var time       = ParseTime(this, false, false);

            return(Exprs.Const(new LTime(time), startToken));
        }
Example #13
0
        /// <summary>
        /// Creates a constant string
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public object ToListCheck(BindingCallExpr expr)
        {
            var name  = expr.ParamList[0] as TokenData;
            var token = expr.ParamList[1] as TokenData;

            return(Exprs.ListCheck(name, token));
        }
Example #14
0
        /// <summary>
        /// Creates a constant string
        /// </summary>
        /// <param name="expr"></param>
        /// <returns></returns>
        public object ToConstantString(BindingCallExpr expr)
        {
            var text  = expr.ParamList[0] as TokenData;
            var token = expr.ParamList[1] as TokenData;

            return(Exprs.Const(new LString(text.Token.Text), token));
        }
Example #15
0
        private Tuple <bool, Expr> IsMatch(FluentPluginHelper helper, Type type, Token klass, Token instance, Token prop, Token method)
        {
            var memberName = string.Empty;
            var rootVar    = string.Empty;
            var match      = false;
            var nameToken  = klass;

            // 1. Class property
            if (klass != null && prop != null)
            {
                rootVar = klass.Text;
                if (helper.IsClassProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                }
            }
            // 2. Class method
            else if (klass != null && method != null)
            {
                rootVar = type.Name;
                if (helper.IsClassMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                }
            }
            // 3. Instance property
            else if (instance != null && prop != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceProp(type, prop.Text))
                {
                    memberName = prop.Text;
                    match      = true;
                    nameToken  = instance;
                }
            }
            // 4. Instance method
            else if (instance != null && method != null)
            {
                rootVar = instance.Text;
                if (helper.IsInstanceMethod(type, method.Text))
                {
                    memberName = method.Text;
                    match      = true;
                    nameToken  = instance;
                }
            }
            if (!match)
            {
                return(new Tuple <bool, Expr>(false, null));
            }

            var varExp = Exprs.Ident(rootVar, null);
            var memExp = Exprs.MemberAccess(varExp, memberName, false, null);

            return(new Tuple <bool, Expr>(memberName != null, memExp));
        }
Example #16
0
        /// <summary>Converts the parameters to a constant day expression </summary>
        /// <param name="expr">The function call expressions</param>
        public object ToDuration(BindingCallExpr expr)
        {
            var duration = (string)(expr.ParamList[0]);
            var type     = (string)expr.ParamList[1];
            var token    = expr.ParamList[2] as TokenData;

            return(Exprs.Duration(duration, type, token));
        }
        /// <summary>
        /// Parses the date expression.
        /// - Oct 10
        /// - Oct 10 2011
        /// - Oct 10, 2011
        /// - Oct 10th
        /// - Oct 10th 2011
        /// - Oct 10th, 2011
        /// - October 10
        /// - October 10, 2011
        /// - October 10th
        /// - October 10th, 2011
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            var startToken = _tokenIt.NextToken;
            var date       = ParseDate(this);
            var exp        = Exprs.Const(new LDate(date), startToken);

            return(exp);
        }
Example #18
0
 internal override void Emit(ILGenerator ilg, bool preserve)
 {
     for (int i = 0; i < Exprs.Count - 1; i++)
     {
         Exprs[i].Emit(ilg, false);
     }
     Exprs.LastOrDefault()?.Emit(ilg, preserve);
 }
Example #19
0
        /// <summary>Converts the parameters to a constant day expression </summary>
        /// <param name="expr">The function call expressions</param>
        public object ToRelativeDay(BindingCallExpr expr)
        {
            var day     = Convert.ToInt32(expr.ParamList[0]);
            var time    = (string)expr.ParamList[1];
            var token   = expr.ParamList[2] as TokenData;
            var dayName = _data.LookupDayName(day);

            return(Exprs.Day(dayName, time, token));
        }
Example #20
0
        /// <summary>Converts the parameters to a constant day expression </summary>
        /// <param name="expr">The function call expressions</param>
        public object ToRelativeDate(BindingCallExpr expr)
        {
            var relativeDay = (string)(expr.ParamList[0]);
            var dayOfWeek   = Convert.ToInt32(expr.ParamList[1]);
            var month       = Convert.ToInt32(expr.ParamList[2]);
            var token       = expr.ParamList[3] as TokenData;

            return(Exprs.DateRelative(relativeDay, dayOfWeek, month, token));
        }
Example #21
0
 public InPredicate(Expr operand
                    , bool not
                    , Exprs operands)
 {
     this.Comments = new Comments(not ? 1 : 0 + 3);
     this.Operand  = operand;
     this.Not      = not;
     this.Operands = operands;
 }
        private RunExpr ParseRunExpr(TokenData startToken)
        {
            // Move past "on"
            _tokenIt.Advance(1);
            var exp    = _parser.ParseIdExpression(string.Empty, null, false);
            var runexp = Exprs.Run(string.Empty, exp, startToken) as RunExpr;

            return(runexp);
        }
Example #23
0
        private void AssertParameterCount(IFunctionType ft)
        {
            var paramTypes = ft.ParameterTypes;

            if (paramTypes.Count() != Exprs.Count())
            {
                throw new TranspilationException($"Expected {paramTypes.Count()} parameter(s) when invoking function '{Name}', but got {Exprs.Count()}", Location);
            }
        }
Example #24
0
        /// <summary>
        /// Parses the day expression.
        /// Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            var startToken = _tokenIt.NextToken;

            _tokenIt.Advance();
            var word = _tokenIt.NextToken.Token.Text;

            _tokenIt.Advance();
            return(Exprs.Const(new LString(word), startToken));
        }
Example #25
0
        /// <summary>
        /// Parses the money expression in form $number
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            // $<number>
            var startToken = _tokenIt.NextToken;

            _tokenIt.Advance();
            var val = _tokenIt.ExpectNumber();

            return(Exprs.Const(new LNumber(val), startToken));
        }
Example #26
0
        /// <summary>
        /// Parses the fluent function call.
        /// </summary>
        /// <returns></returns>
        public override Expr Parse()
        {
            // 1. Is it a function call?
            var nameExp = Exprs.Ident(_result.Name, null);

            _tokenIt.Advance(_result.TokenCount);
            var exp = _parser.ParseFuncExpression(nameExp, null);

            return(exp);
        }
Example #27
0
        /// <summary>Converts the parameters to a constant date expression </summary>
        /// <param name="expr">The function call expressions</param>
        public object ToConstantDate(BindingCallExpr expr)
        {
            var month = Convert.ToInt32(expr.ParamList[0]);
            var day   = Convert.ToInt32(expr.ParamList[1]);
            var year  = Convert.ToInt32(expr.ParamList[2]);
            var time  = (string)expr.ParamList[3];
            var token = expr.ParamList[4] as TokenData;

            return(Exprs.Date(month, day, year, time, token));
        }
Example #28
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.boris.expr.Expr parseAndValidate(String paramString) throws java.io.IOException, org.boris.expr.ExprException
        public virtual Expr parseAndValidate(string paramString)
        {
            ExprParser exprParser = new ExprParser();

            exprParser.ParserVisitor = this;
            exprParser.parse(new ExprLexer(paramString));
            Expr expr = exprParser.get();

            Exprs.ToUpper(expr);
            return(expr);
        }
Example #29
0
        public object ToEnumerableLoop(BindingCallExpr expr)
        {
            var token          = expr.ParamList[2] as TokenData;
            var varname        = (string)expr.ParamList[0];
            var enableWith     = (bool)expr.ParamList[1];
            var collectionName = varname + "s";
            var varExpr        = Exprs.Ident(collectionName, token);
            var loopexpr       = Exprs.ForEach(varname, varExpr, token);

            ((BlockExpr)loopexpr).EnableAutoVariable = enableWith;
            return(loopexpr);
        }
Example #30
0
        private IFunctionType SpecifyFunc(GenericFunctionWrapper wrapper, Environment env)
        {
            if (Handle == null)
            {
                var exprTypes = Exprs.Select(expr => expr.Type);
                return(wrapper.ResolveByParameterPosition(exprTypes));
            }

            var resolutions = Handle.ResolveByIdentifier(wrapper.Handle, env);

            return(wrapper.ResolveByIdentifier(resolutions));
        }