示例#1
0
        public Node If()
        {
            var node = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            Expect(TokenCategory.OPENEDPAR);
            node.Add(Expr());
            Expect(TokenCategory.CLOSEDPAR);
            Expect(TokenCategory.OPENEDCURLY);
            if (CurrentToken != TokenCategory.CLOSEDCURLY)
            {
                node.Add(StmtList());
            }
            Expect(TokenCategory.CLOSEDCURLY);
            if (CurrentToken == TokenCategory.ELSEIF)
            {
                node.Add(ElseIf());
            }
            if (CurrentToken == TokenCategory.ELSE)
            {
                node.Add(Else());
            }
            return(node);
        }
示例#2
0
        /****************************************************************
         *                      If Condition Node
         ***************************************************************/

        public Node IfCondition()
        {
            var result = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            if (this.labelCache != null)
            {
                result.Add(this.labelCache);
                this.labelCache = null;
            }

            var expr1 = Expression();

            CheckForThen();
            var stmtList1 = EvaluateStatements();

            result.Add(expr1);
            result.Add(stmtList1);

            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var elseIfToken = Expect(TokenCategory.ELSEIF);
                var expr2       = Expression();
                CheckForThen();
                var stmtList2 = EvaluateStatements();

                var elseIfResult = new ElseIf()
                {
                    expr2, stmtList2
                };
                elseIfResult.AnchorToken = elseIfToken;
                result.Add(elseIfResult);
            }

            if (CurrentToken == TokenCategory.ELSE)
            {
                var elseToken = Expect(TokenCategory.ELSE);
                var stmtList3 = EvaluateStatements();

                var elseResult = new Else()
                {
                    AnchorToken = elseToken
                };
                elseResult.Add(stmtList3);
                result.Add(elseResult);
            }

            if (CurrentToken == TokenCategory.ENDIF)
            {
                Expect(TokenCategory.ENDIF);
            }

            return(result);
        }
示例#3
0
        public Node If()
        {
            var n1 = new If();

            n1.AnchorToken = Expect(TokenType.IF);
            Expect(TokenType.PARENTHESIS_OPEN);
            n1.Add(Expression());
            Expect(TokenType.PARENTHESIS_CLOSE);
            Expect(TokenType.BLOCK_BEGIN);
            var n2 = new StatementList();

            while (firstOfStatement.Contains(CurrentToken))
            {
                n2.Add(Statement());
            }
            n1.Add(n2);
            var n3 = new ElseIfList();

            Expect(TokenType.BLOCK_END);
            while (CurrentToken == TokenType.ELSEIF)
            {
                var nelsif = new ElseIf();
                nelsif.AnchorToken = Expect(TokenType.ELSEIF);
                Expect(TokenType.PARENTHESIS_OPEN);
                nelsif.Add(Expression());
                Expect(TokenType.PARENTHESIS_CLOSE);
                Expect(TokenType.BLOCK_BEGIN);
                var stmtList = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtList.Add(Statement());
                }
                nelsif.Add(stmtList);
                n3.Add(nelsif);
                Expect(TokenType.BLOCK_END);
            }
            n1.Add(n3);
            var els = new Else();

            if (CurrentToken == TokenType.ELSE)
            {
                els.AnchorToken = Expect(TokenType.ELSE);
                Expect(TokenType.BLOCK_BEGIN);
                var stmtList = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtList.Add(Statement());
                }
                els.Add(stmtList);
                Expect(TokenType.BLOCK_END);
            }
            n1.Add(els);
            return(n1);
        }
示例#4
0
        public Node If()
        {
            var result = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            result.Add(Expression());
            var thenstatement = new Then()
            {
                AnchorToken = Expect(TokenCategory.THEN)
            };

            while (firstOfStatement.Contains(CurrentToken))
            {
                thenstatement.Add(Statement());
            }
            result.Add(thenstatement);
            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var elif = new ElseIf()
                {
                    AnchorToken = Expect(TokenCategory.ELSEIF)
                };
                elif.Add(Expression());
                var thenst = new Then()
                {
                    AnchorToken = Expect(TokenCategory.THEN)
                };
                while (firstOfStatement.Contains(CurrentToken))
                {
                    thenst.Add(Statement());
                }
                elif.Add(thenst);
                result.Add(elif);
            }
            if (CurrentToken == TokenCategory.ELSE)
            {
                var elsestatement = new Else()
                {
                    AnchorToken = Expect(TokenCategory.ELSE)
                };
                while (firstOfStatement.Contains(CurrentToken))
                {
                    elsestatement.Add(Statement());
                }
            }
            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOL);
            return(result);
        }
示例#5
0
        //If side function//
        public Node If()
        {
            var result = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            Expect(TokenCategory.PARENTHESIS_OPEN);

            result.Add(Expression());

            Expect(TokenCategory.PARENTHESIS_CLOSE);

            Expect(TokenCategory.CURLY_BRACKET_OPEN);

            result.Add(StmtList());

            Expect(TokenCategory.CURLY_BRACKET_CLOSE);

            var elseIfListr = new ElseIfList();

            while (elsif.Contains(CurrentToken))
            {
                elseIfListr.Add(elseif());
            }

            result.Add(elseIfListr);

            var elser = new Else();

            if (CurrentToken == TokenCategory.ELSE)
            {
                elser = new Else()
                {
                    AnchorToken = Expect(TokenCategory.ELSE)
                };

                Expect(TokenCategory.CURLY_BRACKET_OPEN);

                elser.Add(StmtList());

                Expect(TokenCategory.CURLY_BRACKET_CLOSE);
            }
            result.Add(elser);

            return(result);
        }
        public Node StmtIf()
        {
            var ifStatement = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            Expect(TokenCategory.OPEN_PARENTHESIS);
            ifStatement.Add(Expr());
            Expect(TokenCategory.CLOSE_PARENTHESIS);
            Expect(TokenCategory.OPEN_BRACKET);
            ifStatement.Add(StmtList());
            Expect(TokenCategory.CLOSE_BRACKET);
            ifStatement.Add(ElseIfList());
            ifStatement.Add(Else());
            return(ifStatement);
        }
示例#7
0
        public Node If()
        {
            var n = new If();

            Expect(TokenCategory.IF);
            Expect(TokenCategory.OPENEDPAR);
            n.Add(Expr());
            Expect(TokenCategory.CLOSEDPAR);
            Expect(TokenCategory.OPENEDCURLY);
            //if(CurrentToken != TokenCategory.CLOSEDCURLY){
            n.Add(StmtList());
            //}
            Expect(TokenCategory.CLOSEDCURLY);
            //if(CurrentToken == TokenCategory.ELSEIF){
            n.Add(ElseIf());
            //}
            //if(CurrentToken == TokenCategory.ELSE){
            n.Add(Else());
            //}
            return(n);
        }
示例#8
0
        public Node StmtIf()
        {
            var statementIf = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            Expect(TokenCategory.PARENTHESIS_OPEN);
            statementIf.Add(Expr());
            Expect(TokenCategory.PARENTHESIS_CLOSE);

            Expect(TokenCategory.BRACKETS_OPEN);
            statementIf.Add(StmtList());
            Expect(TokenCategory.BRACKETS_CLOSE);

            if (CurrentToken == TokenCategory.ELSE)
            {
                statementIf.Add(ElseIfList());
            }
            //ElseIfList();
            //Else();
            return(statementIf);
        }
示例#9
0
        // ---------------- ALL MAKE SENSE   ----------------
        public Node StatementIf()
        {
            var n1 = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            Expect(TokenCategory.PARENTHESIS_OPEN);
            n1.Add(Expression());//Esta es la condición
            Expect(TokenCategory.PARENTHESIS_CLOSE);
            Expect(TokenCategory.BRACE_OPEN);
            var list = new ListStatements();

            while (firstOfStatement.Contains(CurrentToken))
            {
                list.Add(Statement());
            }
            n1.Add(list);         // Statements IF
            Expect(TokenCategory.BRACE_CLOSE);
            n1.Add(ElseIfList()); // Elseif list
            n1.Add(Else());       // Else
            return(n1);
        }
示例#10
0
        private static Script genDownload(ScriptContext context, List <string> filteredArgs)
        {
            Script script;

            script    = createEmptyScript(context, "xsharper //download");
            script.Id = "download";
            filteredArgs.AddRange(context.GetStringArray(xs.download));
            script.Usage.Options = UsageOptions.IfHelp | UsageOptions.IfNoArguments | UsageOptions.UsageLine | UsageOptions.AutoSuffix;
            script.Parameters.Add(new CommandLineParameter("uri", CommandLineValueCount.Single, null, null)
            {
                Required = true, Value = "Source URL"
            });
            script.Parameters.Add(new CommandLineParameter("file", CommandLineValueCount.Single, ".", null)
            {
                Value = "Destination file or directory"
            });
            script.Parameters.Add(new CommandLineParameter(null, "cache", CommandLineValueCount.Single, Utils.LowercaseFirstLetter(RequestCacheLevel.Default.ToString()), null)
            {
                Description = "cache-level", Value = "Cache level, one of " + Utils.AllEnumValuesToString(typeof(RequestCacheLevel), " / ")
            });
            script.Parameters.Add(new CommandLineParameter("passive", "activeFtp", CommandLineValueCount.None, true, false)
            {
                Value = "Use active FTP"
            });
            script.Parameters.Add(new CommandLineParameter("userAgent", "userAgent", CommandLineValueCount.Single, null, null)
            {
                Value = "User agent string (http://)"
            });
            script.Parameters.Add(new CommandLineParameter("post", "post", CommandLineValueCount.Single, null, null)
            {
                Value = "HTTP Post string (evaluated as XSharper expression)"
            });
            script.Parameters.Add(new CommandLineParameter("postContentType", "postContentType", CommandLineValueCount.Single, null, null)
            {
                Value = "HTTP Post content type (default is application/x-www-form-urlencoded)"
            });
            script.Parameters.Add(new CommandLineParameter("timeout", "timeout", CommandLineValueCount.Single, null, null)
            {
                Value = "Timeout"
            });
            script.Parameters.Add(new CommandLineParameter("ignoreCertificateErrors", "ignoreCertificateErrors", CommandLineValueCount.None, true, false)
            {
                Value = "Ignore SSL certificate errors "
            });

            script.Add(new Set("oldReceived", "0"));
            script.Add(new SetAttr("d", "cacheLevel", "${cache}"));
            script.Add(new SetAttr("d", "passiveFtp", "${passive}"));
            script.Add(new Set("fn", "${=XS.Download.UrlToLocalFilename($uri,$file)}", TransformRules.Expand));
            script.Add(new Print {
                Value = "Downloading ${=XS.Utils.SecureUri($uri)} => ${fn} ... "
            });
            If ifs1 = new If()
            {
                IsTrue = "${ignoreCertificateErrors}"
            };

            ifs1.Add(new Code("System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };")
            {
                Dynamic = true
            });
            script.Add(ifs1);
            Download d = new Download
            {
                Id              = "d",
                From            = "${uri}",
                To              = "${file}",
                UserAgent       = "${userAgent|=null}",
                Post            = "${=.Expand(${post|=null})}",
                PostContentType = "${postContentType|=null}",
                Timeout         = "${timeout|=null}",
                Transform       = TransformRules.Expand
            };

            If ifs = new If()
            {
                Condition = "${= $.bytesReceived/1024/100 #GT# $oldReceived/1024/100}"
            };

            ifs.Add(new Print(".")
            {
                OutTo = "^info", NewLine = false
            });
            d.Add(ifs);


            d.Add(new Set("oldReceived", "${= $.bytesReceived}", TransformRules.Expand));


            script.Add(d);
            script.Add(new Print {
                Value = "Completed. ${oldReceived} bytes downloaded."
            });
            return(script);
        }
示例#11
0
        public Node If()
        {
            var result = new If()
            {
                AnchorToken = Expect(TokenCategory.IF)
            };

            result.Add(Expression());
            Expect(TokenCategory.THEN);
            if (firstOfStatement.Contains(CurrentToken))
            {
                var statementList = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    statementList.Add(Statement());
                }
                result.Add(statementList);
            }

            var elseIfList = new ElseIfList();

            if (CurrentToken == TokenCategory.ELSEIF)
            {
                while (CurrentToken == TokenCategory.ELSEIF)
                {
                    var elseIf = new ElseIf()
                    {
                        AnchorToken = Expect(TokenCategory.ELSEIF)
                    };

                    elseIf.Add(Expression());
                    Expect(TokenCategory.THEN);
                    if (firstOfStatement.Contains(CurrentToken))
                    {
                        var statementList = new StatementList();
                        while (firstOfStatement.Contains(CurrentToken))
                        {
                            statementList.Add(Statement());
                        }
                        elseIf.Add(statementList);
                    }
                    elseIfList.Add(elseIf);
                }
            }
            result.Add(elseIfList);

            var els = new Else();

            if (CurrentToken == TokenCategory.ELSE)
            {
                els.AnchorToken = Expect(TokenCategory.ELSE);
                if (firstOfStatement.Contains(CurrentToken))
                {
                    var statementList = new StatementList();
                    while (firstOfStatement.Contains(CurrentToken))
                    {
                        statementList.Add(Statement());
                    }
                    els.Add(statementList);
                }
            }
            result.Add(els);

            Expect(TokenCategory.END);
            Expect(TokenCategory.SEMICOLON);
            return(result);
        }
示例#12
0
        public Node If()
        {
            var ifToken = Expect(TokenCategory.IF);
            var nodeIf  = new If()
            {
                AnchorToken = ifToken
            };

            nodeIf.Add(Expression());
            Expect(TokenCategory.THEN);
            var stmtList = new StatementList();

            while (firstOfStatement.Contains(CurrentToken))
            {
                stmtList.Add(Statement());
            }

            nodeIf.Add(stmtList);

            while (CurrentToken == TokenCategory.ELSEIF)
            {
                var nodeElseIf = new ElseIf()
                {
                    AnchorToken = Expect(TokenCategory.ELSEIF)
                };

                nodeElseIf.Add(Expression());
                Expect(TokenCategory.THEN);

                var stmtListElseIf = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtListElseIf.Add(Statement());
                }

                nodeElseIf.Add(stmtListElseIf);
                nodeIf.Add(nodeElseIf);
            }

            while (CurrentToken == TokenCategory.ELSE)
            {
                var nodeElse = new Else()
                {
                    AnchorToken = Expect(TokenCategory.ELSE)
                };

                var stmtListElse = new StatementList();
                while (firstOfStatement.Contains(CurrentToken))
                {
                    stmtListElse.Add(Statement());
                }

                nodeElse.Add(stmtListElse);
                nodeIf.Add(nodeElse);
            }

            Expect(TokenCategory.END);
            Expect(TokenCategory.ENDLINE);

            return(nodeIf);


            // var ifToken = Expect(TokenCategory.IF);
            // var exprList = new ExpressionList();
            // exprList.Add(Expression());
            // var thenNode = new Then() {
            //     AnchorToken = Expect(TokenCategory.THEN)
            // };
            // var stmtList = new StatementList();
            // while (firstOfStatement.Contains(CurrentToken)) {
            //     stmtList.Add(Statement());
            // }
            // if(CurrentToken == TokenCategory.ELSEIF) {
            //     while (CurrentToken == TokenCategory.ELSEIF) {
            //         var elseIf = new ElseIf() {
            //             AnchorToken = Expect(TokenCategory.ELSEIF)
            //         };
            //         exprList.Add(Expression());
            //         Console.WriteLine("Revisa then");
            //         var thenNodetwo = new Then() {
            //             AnchorToken = Expect(TokenCategory.THEN)
            //         };
            //         while (firstOfStatement.Contains(CurrentToken)) {
            //             stmtList.Add(Statement());
            //         }
            //     }
            // }
            // if(CurrentToken == TokenCategory.ELSE) {
            //     Expect(TokenCategory.ELSE);
            //     while (firstOfStatement.Contains(CurrentToken)) {
            //         stmtList.Add(Statement());

            //     }
            // }
            // Expect(TokenCategory.END);
            // Expect(TokenCategory.ENDLINE);
            // var result = new If() { exprList, stmtList };
            // result.AnchorToken = ifToken;
            // return result;
        }