├── AngularJS Example ├── complie.bat ├── index.html ├── script.pyj ├── static │ └── rapydscript │ │ ├── 0.3.6 │ │ ├── fis-conf.js │ │ ├── lib │ │ │ ├── ast.js │ │ │ ├── baselib.js │ │ │ ├── output.js │ │ │ ├── parse.js │ │ │ └── utils.js │ │ ├── rapydscript.js │ │ ├── rapydscript.min.js │ │ └── stdlib.js │ │ └── pyjTransformer.js └── style.css ├── README.md ├── ReactJS Example ├── complie.bat ├── helloworld.js ├── helloworld.pyj ├── index.html └── static │ ├── rapydscript │ ├── 0.3.6 │ │ ├── fis-conf.js │ │ ├── lib │ │ │ ├── ast.js │ │ │ ├── baselib.js │ │ │ ├── output.js │ │ │ ├── parse.js │ │ │ └── utils.js │ │ ├── rapydscript.js │ │ ├── rapydscript.min.js │ │ └── stdlib.js │ └── pyjTransformer.js │ └── react │ ├── JSXTransformer.js │ └── react.js └── jQuery Example ├── change.pyj ├── complie.bat ├── index.html └── static └── rapydscript ├── 0.3.6 ├── fis-conf.js ├── lib │ ├── ast.js │ ├── baselib.js │ ├── output.js │ ├── parse.js │ └── utils.js ├── rapydscript.js ├── rapydscript.min.js └── stdlib.js └── pyjTransformer.js /AngularJS Example/complie.bat: -------------------------------------------------------------------------------- 1 | @call rapydscript helloworld.pyj -o helloworld.js -p -b 2 | pause -------------------------------------------------------------------------------- /AngularJS Example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Learn AngularJS - Inline Editor 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
31 | 32 | 35 | 36 | 37 |
38 | 39 | 41 |

{{value}}

42 | 43 |
44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /AngularJS Example/script.pyj: -------------------------------------------------------------------------------- 1 | def InlineEditorController($scope): 2 | # $scope is a special object that makes 3 | # its properties available to the view as 4 | # variables. Here we set some default values: 5 | $scope.showtooltip = False 6 | $scope.value = 'Edit me.' 7 | 8 | # Some helper functions that will be 9 | # available in the angular declarations 10 | 11 | $scope.hideTooltip = def(): 12 | # When a model is changed, the view will be automatically 13 | # updated by by AngularJS. In this case it will hide the tooltip. 14 | $scope.showtooltip = False 15 | 16 | $scope.toggleTooltip = def(e): 17 | e.stopPropagation() 18 | $scope.showtooltip = not $scope.showtooltip 19 | -------------------------------------------------------------------------------- /AngularJS Example/static/rapydscript/0.3.6/fis-conf.js: -------------------------------------------------------------------------------- 1 | //use baidu fis3 to compress .js files 2 | // 3 | fis.set('project.ignore',[ 4 | '*.js', //bourbon 5 | 'output/**' 6 | ]); 7 | 8 | fis.match('lib/*.js', { 9 | deploy: fis.plugin('local-deliver', { 10 | to: 'output/' 11 | }), 12 | packTo: 'rapydscript.min.js', 13 | }); 14 | 15 | fis.match('lib/*.js', { 16 | optimizer: fis.plugin('uglify-js'), 17 | useHash: false, 18 | }); 19 | 20 | 21 | -------------------------------------------------------------------------------- /AngularJS Example/static/rapydscript/0.3.6/lib/ast.js: -------------------------------------------------------------------------------- 1 | var AST_Token, AST_Node, AST_Statement, AST_Debugger, AST_Directive, AST_SimpleStatement, AST_Block, AST_BlockStatement, AST_EmptyStatement, AST_StatementWithBody, AST_LabeledStatement, AST_DWLoop, AST_Do, AST_While, AST_ForIn, AST_ForJS, AST_ListComprehension, AST_With, AST_Scope, AST_Toplevel, AST_Import, AST_Decorator, AST_Lambda, AST_Accessor, AST_Function, AST_Class, AST_Module, AST_Method, AST_Jump, AST_Exit, AST_Return, AST_Throw, AST_LoopControl, AST_Break, AST_Continue, AST_If, AST_Switch, AST_SwitchBranch, AST_Default, AST_Case, AST_Try, AST_Catch, AST_Except, AST_Finally, AST_Definitions, AST_Var, AST_Const, AST_VarDef, AST_BaseCall, AST_Call, AST_ClassCall, AST_New, AST_Seq, AST_PropAccess, AST_Dot, AST_Sub, AST_Splice, AST_Unary, AST_UnaryPrefix, AST_UnaryPostfix, AST_Binary, AST_Conditional, AST_Assign, AST_Array, AST_TupleUnpack, AST_Object, AST_ObjectProperty, AST_ObjectKeyVal, AST_ObjectSetter, AST_ObjectGetter, AST_Symbol, AST_SymbolAccessor, AST_SymbolDeclaration, AST_SymbolVar, AST_SymbolConst, AST_SymbolFunarg, AST_SymbolDefun, AST_SymbolLambda, AST_SymbolCatch, AST_Label, AST_SymbolRef, AST_LabelRef, AST_This, AST_Constant, AST_String, AST_Verbatim, AST_Number, AST_RegExp, AST_Atom, AST_Null, AST_NaN, AST_Undefined, AST_Hole, AST_Infinity, AST_Boolean, AST_False, AST_True; 2 | "\n**********************************************************************\n\n A RapydScript to JavaScript compiler.\n https://github.com/atsepkov/RapydScript\n\n -------------------------------- (C) ---------------------------------\n\n Author: Alexander Tsepkov\n \n http://www.pyjeon.com\n\n Distributed under Apache 2.0 license:\n Copyright 2013 (c) Alexander Tsepkov \n\n RapydScript source code is originally based on UglifyJS2 (covered\n by BSD license). UglifyJS2 was written by Mihai Bazon\n , who is its respective copyright holder.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions\n are met:\n\n * Redistributions of source code must retain the above\n copyright notice, this list of conditions and the following\n disclaimer.\n\n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials\n provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY\n EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE\n LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\n TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\n THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n SUCH DAMAGE.\n\n **********************************************************************\n"; 3 | "use strict"; 4 | function DEFNODE(type, props, methods, base) { 5 | var self_props, proto, code, ctor, i; 6 | if (arguments.length < 4) { 7 | base = AST_Node; 8 | } 9 | if (!props) { 10 | props = []; 11 | } else { 12 | props = props.split(/\s+/); 13 | } 14 | self_props = props; 15 | if (base && base.PROPS) { 16 | props = props.concat(base.PROPS); 17 | } 18 | code = "return function AST_" + type + "(props){ if (props) { "; 19 | for (i = props.length - 1; i > -1; i-=1) { 20 | code += "this." + props[i] + " = props." + props[i] + ";"; 21 | } 22 | proto = base && new base(); 23 | if (proto && proto.initialize || methods && methods.initialize) { 24 | code += "this.initialize();"; 25 | } 26 | code += "}}"; 27 | ctor = new Function(code)(); 28 | if (proto) { 29 | ctor.prototype = proto; 30 | ctor.BASE = base; 31 | } 32 | if (base) { 33 | base.SUBCLASSES.push(ctor); 34 | } 35 | ctor.prototype.CTOR = ctor; 36 | ctor.PROPS = props || null; 37 | ctor.SELF_PROPS = self_props; 38 | ctor.SUBCLASSES = []; 39 | if (type) { 40 | ctor.prototype.TYPE = ctor.TYPE = type; 41 | } 42 | if (methods) { 43 | for (i in methods) { 44 | if (methods.hasOwnProperty(i)) { 45 | if (/^\$/.test(i)) { 46 | ctor[i.substr(1)] = methods[i]; 47 | } else { 48 | ctor.prototype[i] = methods[i]; 49 | } 50 | } 51 | } 52 | } 53 | ctor.DEFMETHOD = function(name, method) { 54 | this.prototype[name] = method; 55 | }; 56 | return ctor; 57 | } 58 | AST_Token = DEFNODE("Token", "type value line col pos endpos nlb comments_before file", {}, null); 59 | AST_Node = DEFNODE("Node", "start end", { 60 | clone: function() { 61 | return new this.CTOR(this); 62 | }, 63 | $documentation: "Base class of all AST nodes", 64 | $propdoc: { 65 | start: "[AST_Token] The first token of this node", 66 | end: "[AST_Token] The last token of this node" 67 | }, 68 | _walk: function(visitor) { 69 | return visitor._visit(this); 70 | }, 71 | walk: function(visitor) { 72 | return this._walk(visitor); 73 | } 74 | }, null); 75 | AST_Node.warn_function = null; 76 | AST_Node.warn = function(txt, props) { 77 | if (AST_Node.warn_function) { 78 | AST_Node.warn_function(string_template(txt, props)); 79 | } 80 | }; 81 | AST_Statement = DEFNODE("Statement", null, { 82 | $documentation: "Base class of all statements" 83 | }); 84 | AST_Debugger = DEFNODE("Debugger", null, { 85 | $documentation: "Represents a debugger statement" 86 | }, AST_Statement); 87 | AST_Directive = DEFNODE("Directive", "value scope", { 88 | $documentation: "Represents a directive, like \"use strict\";", 89 | $propdoc: { 90 | value: "[string] The value of this directive as a plain string (it's not an AST_String!)", 91 | scope: "[AST_Scope/S] The scope that this directive affects" 92 | } 93 | }, AST_Statement); 94 | AST_SimpleStatement = DEFNODE("SimpleStatement", "body", { 95 | $documentation: "A statement consisting of an expression, i.e. a = 1 + 2", 96 | $propdoc: { 97 | body: "[AST_Node] an expression node (should not be instanceof AST_Statement)" 98 | }, 99 | _walk: function(visitor) { 100 | return visitor._visit(this, function() { 101 | this.body._walk(visitor); 102 | }); 103 | } 104 | }, AST_Statement); 105 | function walk_body(node, visitor) { 106 | if (node.body instanceof AST_Statement) { 107 | node.body._walk(visitor); 108 | } else { 109 | node.body.forEach(function(stat) { 110 | stat._walk(visitor); 111 | }); 112 | } 113 | } 114 | AST_Block = DEFNODE("Block", "body", { 115 | $documentation: "A body of statements (usually bracketed)", 116 | $propdoc: { 117 | body: "[AST_Statement*] an array of statements" 118 | }, 119 | _walk: function(visitor) { 120 | return visitor._visit(this, function() { 121 | walk_body(this, visitor); 122 | }); 123 | } 124 | }, AST_Statement); 125 | AST_BlockStatement = DEFNODE("BlockStatement", null, { 126 | $documentation: "A block statement" 127 | }, AST_Block); 128 | AST_EmptyStatement = DEFNODE("EmptyStatement", null, { 129 | $documentation: "The empty statement (empty block or simply a semicolon)", 130 | _walk: function(visitor) { 131 | return visitor._visit(this); 132 | } 133 | }, AST_Statement); 134 | AST_StatementWithBody = DEFNODE("StatementWithBody", "body", { 135 | $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`", 136 | $propdoc: { 137 | body: "[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement" 138 | }, 139 | _walk: function(visitor) { 140 | return visitor._visit(this, function() { 141 | this.body._walk(visitor); 142 | }); 143 | } 144 | }, AST_Statement); 145 | AST_LabeledStatement = DEFNODE("LabeledStatement", "label", { 146 | $documentation: "Statement with a label", 147 | $propdoc: { 148 | label: "[AST_Label] a label definition" 149 | }, 150 | _walk: function(visitor) { 151 | return visitor._visit(this, function() { 152 | this.label._walk(visitor); 153 | this.body._walk(visitor); 154 | }); 155 | } 156 | }, AST_StatementWithBody); 157 | AST_DWLoop = DEFNODE("DWLoop", "condition", { 158 | $documentation: "Base class for do/while statements", 159 | $propdoc: { 160 | condition: "[AST_Node] the loop condition. Should not be instanceof AST_Statement" 161 | }, 162 | _walk: function(visitor) { 163 | return visitor._visit(this, function() { 164 | this.condition._walk(visitor); 165 | this.body._walk(visitor); 166 | }); 167 | } 168 | }, AST_StatementWithBody); 169 | AST_Do = DEFNODE("Do", null, { 170 | $documentation: "A `do` statement" 171 | }, AST_DWLoop); 172 | AST_While = DEFNODE("While", null, { 173 | $documentation: "A `while` statement" 174 | }, AST_DWLoop); 175 | AST_ForIn = DEFNODE("ForIn", "init name object", { 176 | $documentation: "A `for ... in` statement", 177 | $propdoc: { 178 | init: "[AST_Node] the `for/in` initialization code", 179 | name: "[AST_SymbolRef?] the loop variable, only if `init` is AST_Var", 180 | object: "[AST_Node] the object that we're looping through" 181 | }, 182 | _walk: function(visitor) { 183 | return visitor._visit(this, function() { 184 | this.init._walk(visitor); 185 | this.object._walk(visitor); 186 | this.body._walk(visitor); 187 | }); 188 | } 189 | }, AST_StatementWithBody); 190 | AST_ForJS = DEFNODE("ForJS", "condition", { 191 | $documentation: "A `for ... in` statement", 192 | $propdoc: { 193 | condition: "[AST_Verbatim] raw JavaScript conditional" 194 | } 195 | }, AST_StatementWithBody); 196 | AST_ListComprehension = DEFNODE("ListComprehension", "condition statement", { 197 | $documentation: "A list comprehension expression", 198 | $propdoc: { 199 | condition: "[AST_Node] the `if` condition", 200 | statement: "[AST_Node] statement to perform on each element before returning it" 201 | } 202 | }, AST_ForIn); 203 | AST_With = DEFNODE("With", "expression", { 204 | $documentation: "A `with` statement", 205 | $propdoc: { 206 | expression: "[AST_Node] the `with` expression" 207 | }, 208 | _walk: function(visitor) { 209 | return visitor._visit(this, function() { 210 | this.expression._walk(visitor); 211 | this.body._walk(visitor); 212 | }); 213 | } 214 | }, AST_StatementWithBody); 215 | AST_Scope = DEFNODE("Scope", "directives variables localvars functions uses_with uses_eval parent_scope enclosed cname", { 216 | $documentation: "Base class for all statements introducing a lexical scope", 217 | $propdoc: { 218 | directives: "[string*/S] an array of directives declared in this scope", 219 | variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope", 220 | localvars: "[SymbolDef*] list of variables local to this scope", 221 | functions: "[Object/S] like `variables`, but only lists function declarations", 222 | uses_with: "[boolean/S] tells whether this scope uses the `with` statement", 223 | uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`", 224 | parent_scope: "[AST_Scope?/S] link to the parent scope", 225 | enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes", 226 | cname: "[integer/S] current index for mangling variables (used internally by the mangler)" 227 | } 228 | }, AST_Block); 229 | AST_Toplevel = DEFNODE("Toplevel", "globals baselib imports strict shebang import_order module_id exports submodules classes", { 230 | $documentation: "The toplevel scope", 231 | $propdoc: { 232 | globals: "[Object/S] a map of name -> SymbolDef for all undeclared names", 233 | baselib: "[Object/s] a collection of used parts of baselib", 234 | imports: "[Object/S] a map of module_id->AST_Toplevel for all imported modules", 235 | nonlocalvars: "[String*] a list of all non-local variable names (names that come from the global scope)", 236 | strict: "[boolean/S] true if strict directive is in scope", 237 | shebang: "[string] If #! line is present, it will be stored here", 238 | import_order: "[number] The global order in which this scope was imported", 239 | module_id: "[string] The id of this module", 240 | exports: "[SymbolDef*] list of names exported from this module", 241 | submodules: "[string*] list of names exported from this module", 242 | classes: "[Object/S] a map of class names to AST_Class for classes defined in this module" 243 | }, 244 | wrap_enclose: function(arg_parameter_pairs) { 245 | var self, args, parameters, wrapped_tl; 246 | self = this; 247 | args = []; 248 | parameters = []; 249 | arg_parameter_pairs.forEach(function(pair) { 250 | var split; 251 | split = pair.split(":"); 252 | args.push(split[0]); 253 | parameters.push(split[1]); 254 | }); 255 | wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")"; 256 | wrapped_tl = parse(wrapped_tl); 257 | wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node) { 258 | if (node instanceof AST_Directive && node.value === "$ORIG") { 259 | return MAP.splice(self.body); 260 | } 261 | })); 262 | return wrapped_tl; 263 | }, 264 | wrap_commonjs: function(name, export_all) { 265 | var self, to_export, wrapped_tl; 266 | self = this; 267 | to_export = []; 268 | if (export_all) { 269 | self.figure_out_scope(); 270 | self.walk(new TreeWalker(function(node) { 271 | if (node instanceof AST_SymbolDeclaration && node.definition().global) { 272 | if (!find_if(function(n) { 273 | return n.name === node.name; 274 | }, to_export)) { 275 | to_export.push(node); 276 | } 277 | } 278 | })); 279 | } 280 | wrapped_tl = "(function(exports, global){ global['" + name + "'] = exports; '$ORIG'; '$EXPORTS'; }({}, (function(){return this}())))"; 281 | wrapped_tl = parse(wrapped_tl); 282 | wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node) { 283 | var tmp_, body; 284 | if (node instanceof AST_SimpleStatement) { 285 | node = node.body; 286 | if (node instanceof AST_String) { 287 | tmp_ = node.getValue(); 288 | if (tmp_ === "$ORIG") { 289 | return MAP.splice(self.body); 290 | } else if (tmp_ === "$EXPORTS") { 291 | body = []; 292 | to_export.forEach(function(sym) { 293 | body.push(new AST_SimpleStatement({ 294 | body: new AST_Assign({ 295 | left: new AST_Sub({ 296 | expression: new AST_SymbolRef({ 297 | name: "exports" 298 | }), 299 | property: new AST_String({ 300 | value: sym.name 301 | }) 302 | }), 303 | operator: "=", 304 | right: new AST_SymbolRef(sym) 305 | }) 306 | })); 307 | }); 308 | return MAP.splice(body); 309 | } 310 | } 311 | } 312 | })); 313 | return wrapped_tl; 314 | } 315 | }, AST_Scope); 316 | AST_Import = DEFNODE("Import", "module key argnames body", { 317 | $documentation: "Container for imports", 318 | $propdoc: { 319 | module: "[AST_SymbolVar] name of the module we're importing", 320 | key: "[string] The key by which this module is stored in the global modules mapping", 321 | argnames: "[AST_SymbolVar*] names of objects to be imported", 322 | body: "[AST_TopLevel] parsed contents of the imported file" 323 | } 324 | }, AST_Statement); 325 | AST_Decorator = DEFNODE("Decorator", "name", { 326 | $documentation: "Class for function decorators", 327 | $propdoc: { 328 | name: "[string] decorator name" 329 | } 330 | }); 331 | AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments decorators", { 332 | $documentation: "Base class for functions", 333 | $propdoc: { 334 | name: "[AST_SymbolDeclaration?] the name of this function", 335 | argnames: "[AST_SymbolFunarg*] array of function arguments", 336 | uses_arguments: "[boolean/S] tells whether this function accesses the arguments array", 337 | decorators: "[AST_Decorator*] function decorators, if any" 338 | }, 339 | _walk: function(visitor) { 340 | return visitor._visit(this, function() { 341 | if (this.name) { 342 | this.name._walk(visitor); 343 | } 344 | this.argnames.forEach(function(arg) { 345 | arg._walk(visitor); 346 | }); 347 | walk_body(this, visitor); 348 | }); 349 | } 350 | }, AST_Scope); 351 | AST_Accessor = DEFNODE("Accessor", null, { 352 | $documentation: "A setter/getter function" 353 | }, AST_Lambda); 354 | AST_Function = DEFNODE("Function", null, { 355 | $documentation: "A function expression" 356 | }, AST_Lambda); 357 | AST_Class = DEFNODE("Class", "init name parent static external bound decorators module_id", { 358 | $documentation: "A class declaration", 359 | $propdoc: { 360 | name: "[AST_SymbolDeclaration?] the name of this class", 361 | init: "[AST_Function] constructor for the class", 362 | parent: "[AST_Class?] parent class this class inherits from", 363 | "static": "[string*] list of static methods", 364 | external: "[boolean] true if class is declared elsewhere, but will be within current scope at runtime", 365 | bound: "[string*] list of methods that need to be bound to behave correctly (function pointers)", 366 | decorators: "[AST_Decorator*] function decorators, if any", 367 | module_id: "[string] The id of the module this class is defined in" 368 | }, 369 | _walk: function(visitor) { 370 | return visitor._visit(this, function() { 371 | this.name._walk(visitor); 372 | walk_body(this, visitor); 373 | this.parent._walk(visitor); 374 | }); 375 | } 376 | }, AST_Scope); 377 | AST_Module = DEFNODE("Module", "name external decorators", { 378 | $documentation: "A module definition, meant to abstract a group of related classes and/or functions", 379 | $propdoc: { 380 | name: "[AST_SymbolDeclaration?] the name of this class", 381 | external: "[boolean] true if module is declared elsewhere, but will be within current scope at runtime", 382 | decorators: "[AST_Decorator*] module decorators, if any" 383 | } 384 | }, AST_Scope); 385 | AST_Method = DEFNODE("Defun", "static", { 386 | $documentation: "A class method definition", 387 | $propdoc: { 388 | "static": "[boolean] true if method is static" 389 | } 390 | }, AST_Lambda); 391 | AST_Jump = DEFNODE("Jump", null, { 392 | $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)" 393 | }, AST_Statement); 394 | AST_Exit = DEFNODE("Exit", "value", { 395 | $documentation: "Base class for “exits” (`return` and `throw`)", 396 | $propdoc: { 397 | value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return" 398 | }, 399 | _walk: function(visitor) { 400 | return visitor._visit(this, this.value && function() { 401 | this.value._walk(visitor); 402 | }); 403 | } 404 | }, AST_Jump); 405 | AST_Return = DEFNODE("Return", null, { 406 | $documentation: "A `return` statement" 407 | }, AST_Exit); 408 | AST_Throw = DEFNODE("Throw", null, { 409 | $documentation: "A `throw` statement" 410 | }, AST_Exit); 411 | AST_LoopControl = DEFNODE("LoopControl", "label", { 412 | $documentation: "Base class for loop control statements (`break` and `continue`)", 413 | $propdoc: { 414 | label: "[AST_LabelRef?] the label, or null if none" 415 | }, 416 | _walk: function(visitor) { 417 | return visitor._visit(this, this.label && function() { 418 | this.label._walk(visitor); 419 | }); 420 | } 421 | }, AST_Jump); 422 | AST_Break = DEFNODE("Break", null, { 423 | $documentation: "A `break` statement" 424 | }, AST_LoopControl); 425 | AST_Continue = DEFNODE("Continue", null, { 426 | $documentation: "A `continue` statement" 427 | }, AST_LoopControl); 428 | AST_If = DEFNODE("If", "condition alternative", { 429 | $documentation: "A `if` statement", 430 | $propdoc: { 431 | condition: "[AST_Node] the `if` condition", 432 | alternative: "[AST_Statement?] the `else` part, or null if not present" 433 | }, 434 | _walk: function(visitor) { 435 | return visitor._visit(this, function() { 436 | this.condition._walk(visitor); 437 | this.body._walk(visitor); 438 | if (this.alternative) { 439 | this.alternative._walk(visitor); 440 | } 441 | }); 442 | } 443 | }, AST_StatementWithBody); 444 | AST_Switch = DEFNODE("Switch", "expression", { 445 | $documentation: "A `switch` statement", 446 | $propdoc: { 447 | expression: "[AST_Node] the `switch` “discriminant”" 448 | }, 449 | _walk: function(visitor) { 450 | return visitor._visit(this, function() { 451 | this.expression._walk(visitor); 452 | walk_body(this, visitor); 453 | }); 454 | } 455 | }, AST_Block); 456 | AST_SwitchBranch = DEFNODE("SwitchBranch", null, { 457 | $documentation: "Base class for `switch` branches" 458 | }, AST_Block); 459 | AST_Default = DEFNODE("Default", null, { 460 | $documentation: "A `default` switch branch" 461 | }, AST_SwitchBranch); 462 | AST_Case = DEFNODE("Case", "expression", { 463 | $documentation: "A `case` switch branch", 464 | $propdoc: { 465 | expression: "[AST_Node] the `case` expression" 466 | }, 467 | _walk: function(visitor) { 468 | return visitor._visit(this, function() { 469 | this.expression._walk(visitor); 470 | walk_body(this, visitor); 471 | }); 472 | } 473 | }, AST_SwitchBranch); 474 | AST_Try = DEFNODE("Try", "bcatch bfinally", { 475 | $documentation: "A `try` statement", 476 | $propdoc: { 477 | bcatch: "[AST_Catch?] the catch block, or null if not present", 478 | bfinally: "[AST_Finally?] the finally block, or null if not present" 479 | }, 480 | _walk: function(visitor) { 481 | return visitor._visit(this, function() { 482 | walk_body(this, visitor); 483 | if (this.bcatch) { 484 | this.bcatch._walk(visitor); 485 | } 486 | if (this.bfinally) { 487 | this.bfinally._walk(visitor); 488 | } 489 | }); 490 | } 491 | }, AST_Block); 492 | AST_Catch = DEFNODE("Catch", null, { 493 | $documentation: "A `catch` node; only makes sense as part of a `try` statement", 494 | $propdoc: {}, 495 | _walk: function(visitor) { 496 | return visitor._visit(this, function() { 497 | this.argname._walk(visitor); 498 | walk_body(this, visitor); 499 | }); 500 | } 501 | }, AST_Block); 502 | AST_Except = DEFNODE("Except", "argname errors", { 503 | $documentation: "An `except` node for RapydScript, which resides inside the catch block", 504 | $propdoc: { 505 | argname: "[AST_SymbolCatch] symbol for the exception", 506 | errors: "[AST_SymbolVar*] error classes to catch in this block" 507 | } 508 | }, AST_Block); 509 | AST_Finally = DEFNODE("Finally", null, { 510 | $documentation: "A `finally` node; only makes sense as part of a `try` statement" 511 | }, AST_Block); 512 | AST_Definitions = DEFNODE("Definitions", "definitions", { 513 | $documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)", 514 | $propdoc: { 515 | definitions: "[AST_VarDef*] array of variable definitions" 516 | }, 517 | _walk: function(visitor) { 518 | return visitor._visit(this, function() { 519 | this.definitions.forEach(function(def_) { 520 | def_._walk(visitor); 521 | }); 522 | }); 523 | } 524 | }, AST_Statement); 525 | AST_Var = DEFNODE("Var", null, { 526 | $documentation: "A `var` statement" 527 | }, AST_Definitions); 528 | AST_Const = DEFNODE("Const", null, { 529 | $documentation: "A `const` statement" 530 | }, AST_Definitions); 531 | AST_VarDef = DEFNODE("VarDef", "name value", { 532 | $documentation: "A variable declaration; only appears in a AST_Definitions node", 533 | $propdoc: { 534 | name: "[AST_SymbolVar|AST_SymbolConst] name of the variable", 535 | value: "[AST_Node?] initializer, or null if there's no initializer" 536 | }, 537 | _walk: function(visitor) { 538 | return visitor._visit(this, function() { 539 | this.name._walk(visitor); 540 | if (this.value) { 541 | this.value._walk(visitor); 542 | } 543 | }); 544 | } 545 | }); 546 | AST_BaseCall = DEFNODE("BaseCall", "args", { 547 | $documentation: "A base class for function calls", 548 | $propdoc: { 549 | args: "[AST_Node*] array of arguments" 550 | } 551 | }); 552 | AST_Call = DEFNODE("Call", "expression", { 553 | $documentation: "A function call expression", 554 | $propdoc: { 555 | expression: "[AST_Node] expression to invoke as function" 556 | }, 557 | _walk: function(visitor) { 558 | return visitor._visit(this, function() { 559 | this.expression._walk(visitor); 560 | this.args.forEach(function(arg) { 561 | arg._walk(visitor); 562 | }); 563 | }); 564 | } 565 | }, AST_BaseCall); 566 | AST_ClassCall = DEFNODE("ClassCall", "class method static", { 567 | $documentation: "A function call expression", 568 | $propdoc: { 569 | "class": "[string] name of the class method belongs to", 570 | method: "[string] class method being called", 571 | "static": "[boolean] defines whether the method is static" 572 | }, 573 | _walk: function(visitor) { 574 | return visitor._visit(this, function() { 575 | this.expression._walk(visitor); 576 | this.args.forEach(function(arg) { 577 | arg._walk(visitor); 578 | }); 579 | }); 580 | } 581 | }, AST_BaseCall); 582 | AST_New = DEFNODE("New", null, { 583 | $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties" 584 | }, AST_Call); 585 | AST_Seq = DEFNODE("Seq", "car cdr", { 586 | $documentation: "A sequence expression (two comma-separated expressions)", 587 | $propdoc: { 588 | car: "[AST_Node] first element in sequence", 589 | cdr: "[AST_Node] second element in sequence" 590 | }, 591 | $cons: function(x, y) { 592 | var seq; 593 | seq = new AST_Seq(x); 594 | seq.car = x; 595 | seq.cdr = y; 596 | return seq; 597 | }, 598 | $from_array: function(array) { 599 | var list, i, p; 600 | if (array.length === 0) { 601 | return null; 602 | } 603 | if (array.length === 1) { 604 | return array[0].clone(); 605 | } 606 | list = null; 607 | for (i = array.length - 1; i > -1; i-=1) { 608 | list = AST_Seq.cons(array[i], list); 609 | } 610 | p = list; 611 | while (p) { 612 | if (p.cdr && !p.cdr.cdr) { 613 | p.cdr = p.cdr.car; 614 | break; 615 | } 616 | p = p.cdr; 617 | } 618 | return list; 619 | }, 620 | to_array: function() { 621 | var a, p; 622 | p = this; 623 | a = []; 624 | while (p) { 625 | a.push(p.car); 626 | if (p.cdr && !(p.cdr instanceof AST_Seq)) { 627 | a.push(p.cdr); 628 | break; 629 | } 630 | p = p.cdr; 631 | } 632 | return a; 633 | }, 634 | add: function(node) { 635 | var cell, p; 636 | p = this; 637 | while (p) { 638 | if (!(p.cdr instanceof AST_Seq)) { 639 | cell = AST_Seq.cons(p.cdr, node); 640 | return p.cdr = cell; 641 | } 642 | p = p.cdr; 643 | } 644 | }, 645 | _walk: function(visitor) { 646 | return visitor._visit(this, function() { 647 | this.car._walk(visitor); 648 | if (this.cdr) { 649 | this.cdr._walk(visitor); 650 | } 651 | }); 652 | } 653 | }); 654 | AST_PropAccess = DEFNODE("PropAccess", "expression property", { 655 | $documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`", 656 | $propdoc: { 657 | expression: "[AST_Node] the “container” expression", 658 | property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node" 659 | } 660 | }); 661 | AST_Dot = DEFNODE("Dot", null, { 662 | $documentation: "A dotted property access expression", 663 | _walk: function(visitor) { 664 | return visitor._visit(this, function() { 665 | this.expression._walk(visitor); 666 | }); 667 | } 668 | }, AST_PropAccess); 669 | AST_Sub = DEFNODE("Sub", null, { 670 | $documentation: "Index-style property access, i.e. `a[\"foo\"]`", 671 | _walk: function(visitor) { 672 | return visitor._visit(this, function() { 673 | this.expression._walk(visitor); 674 | this.property._walk(visitor); 675 | }); 676 | } 677 | }, AST_PropAccess); 678 | AST_Splice = DEFNODE("Slice", "property2 assignment", { 679 | $documentation: "Index-style property access, i.e. `a[3:5]`", 680 | $propdoc: { 681 | property2: "[AST_Node] the 2nd property to access - typically ending index for the array.", 682 | assignment: "[AST_Node] The data being spliced in." 683 | }, 684 | _walk: function(visitor) { 685 | return visitor._visit(this, function() { 686 | this.expression._walk(visitor); 687 | this.property._walk(visitor); 688 | this.property2._walk(visitor); 689 | }); 690 | } 691 | }, AST_PropAccess); 692 | AST_Unary = DEFNODE("Unary", "operator expression", { 693 | $documentation: "Base class for unary expressions", 694 | $propdoc: { 695 | operator: "[string] the operator", 696 | expression: "[AST_Node] expression that this unary operator applies to" 697 | }, 698 | _walk: function(visitor) { 699 | return visitor._visit(this, function() { 700 | this.expression._walk(visitor); 701 | }); 702 | } 703 | }); 704 | AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, { 705 | $documentation: "Unary prefix expression, i.e. `typeof i` or `++i`" 706 | }, AST_Unary); 707 | AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, { 708 | $documentation: "Unary postfix expression, i.e. `i++`" 709 | }, AST_Unary); 710 | AST_Binary = DEFNODE("Binary", "left operator right", { 711 | $documentation: "Binary expression, i.e. `a + b`", 712 | $propdoc: { 713 | left: "[AST_Node] left-hand side expression", 714 | operator: "[string] the operator", 715 | right: "[AST_Node] right-hand side expression" 716 | }, 717 | _walk: function(visitor) { 718 | return visitor._visit(this, function() { 719 | this.left._walk(visitor); 720 | this.right._walk(visitor); 721 | }); 722 | } 723 | }); 724 | AST_Conditional = DEFNODE("Conditional", "condition consequent alternative", { 725 | $documentation: "Conditional expression using the ternary operator, i.e. `a ? b : c`", 726 | $propdoc: { 727 | condition: "[AST_Node]", 728 | consequent: "[AST_Node]", 729 | alternative: "[AST_Node]" 730 | }, 731 | _walk: function(visitor) { 732 | return visitor._visit(this, function() { 733 | this.condition._walk(visitor); 734 | this.consequent._walk(visitor); 735 | this.alternative._walk(visitor); 736 | }); 737 | } 738 | }); 739 | AST_Assign = DEFNODE("Assign", null, { 740 | $documentation: "An assignment expression — `a = b + 5`" 741 | }, AST_Binary); 742 | AST_Array = DEFNODE("Array", "elements", { 743 | $documentation: "An array literal", 744 | $propdoc: { 745 | elements: "[AST_Node*] array of elements" 746 | }, 747 | _walk: function(visitor) { 748 | return visitor._visit(this, function() { 749 | this.elements.forEach(function(el) { 750 | el._walk(visitor); 751 | }); 752 | }); 753 | } 754 | }); 755 | AST_TupleUnpack = DEFNODE("TupleUnpack", "elements right", { 756 | $documentation: "An object used to represent tuple unpacking", 757 | $propdoc: { 758 | elements: "[AST_Node*] array of elements being assigned to", 759 | right: "[AST_Node] right-hand side expression" 760 | }, 761 | _walk: function(visitor) { 762 | return visitor._visit(this, function() { 763 | this.elements.forEach(function(el) { 764 | el._walk(visitor); 765 | }); 766 | this.right._walk(visitor); 767 | }); 768 | } 769 | }); 770 | AST_Object = DEFNODE("Object", "properties", { 771 | $documentation: "An object literal", 772 | $propdoc: { 773 | properties: "[AST_ObjectProperty*] array of properties" 774 | }, 775 | _walk: function(visitor) { 776 | return visitor._visit(this, function() { 777 | this.properties.forEach(function(prop) { 778 | prop._walk(visitor); 779 | }); 780 | }); 781 | } 782 | }); 783 | AST_ObjectProperty = DEFNODE("ObjectProperty", "key value quoted", { 784 | $documentation: "Base class for literal object properties", 785 | $propdoc: { 786 | key: "[string] the property name; it's always a plain string in our AST, no matter if it was a string, number or identifier in original code", 787 | value: "[AST_Node] property value. For setters and getters this is an AST_Function.", 788 | quoted: "[true/false] keeps track whether the property was quoted in original code." 789 | }, 790 | _walk: function(visitor) { 791 | return visitor._visit(this, function() { 792 | this.value._walk(visitor); 793 | }); 794 | } 795 | }); 796 | AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", null, { 797 | $documentation: "A key: value object property" 798 | }, AST_ObjectProperty); 799 | AST_ObjectSetter = DEFNODE("ObjectSetter", null, { 800 | $documentation: "An object setter property" 801 | }, AST_ObjectProperty); 802 | AST_ObjectGetter = DEFNODE("ObjectGetter", null, { 803 | $documentation: "An object getter property" 804 | }, AST_ObjectProperty); 805 | AST_Symbol = DEFNODE("Symbol", "scope name thedef", { 806 | $propdoc: { 807 | name: "[string] name of this symbol", 808 | scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)", 809 | thedef: "[SymbolDef/S] the definition of this symbol" 810 | }, 811 | $documentation: "Base class for all symbols" 812 | }); 813 | AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, { 814 | $documentation: "The name of a property accessor (setter/getter function)" 815 | }, AST_Symbol); 816 | AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", { 817 | $documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)", 818 | $propdoc: { 819 | init: "[AST_Node*/S] array of initializers for this declaration." 820 | } 821 | }, AST_Symbol); 822 | AST_SymbolVar = DEFNODE("SymbolVar", null, { 823 | $documentation: "Symbol defining a variable" 824 | }, AST_SymbolDeclaration); 825 | AST_SymbolConst = DEFNODE("SymbolConst", null, { 826 | $documentation: "A constant declaration" 827 | }, AST_SymbolDeclaration); 828 | AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, { 829 | $documentation: "Symbol naming a function argument" 830 | }, AST_SymbolVar); 831 | AST_SymbolDefun = DEFNODE("SymbolDefun", null, { 832 | $documentation: "Symbol defining a function" 833 | }, AST_SymbolDeclaration); 834 | AST_SymbolLambda = DEFNODE("SymbolLambda", null, { 835 | $documentation: "Symbol naming a function expression" 836 | }, AST_SymbolDeclaration); 837 | AST_SymbolCatch = DEFNODE("SymbolCatch", null, { 838 | $documentation: "Symbol naming the exception in catch" 839 | }, AST_SymbolDeclaration); 840 | AST_Label = DEFNODE("Label", "references", { 841 | $documentation: "Symbol naming a label (declaration)", 842 | $propdoc: { 843 | references: "[AST_LabelRef*] a list of nodes referring to this label" 844 | } 845 | }, AST_Symbol); 846 | AST_SymbolRef = DEFNODE("SymbolRef", "parens", { 847 | $documentation: "Reference to some symbol (not definition/declaration)", 848 | $propdoc: { 849 | parens: "[boolean/S] if true, this variable is wrapped in parentheses" 850 | } 851 | }, AST_Symbol); 852 | AST_LabelRef = DEFNODE("LabelRef", null, { 853 | $documentation: "Reference to a label symbol" 854 | }, AST_Symbol); 855 | AST_This = DEFNODE("This", null, { 856 | $documentation: "The `this` symbol" 857 | }, AST_Symbol); 858 | AST_Constant = DEFNODE("Constant", null, { 859 | $documentation: "Base class for all constants", 860 | getValue: function() { 861 | return this.value; 862 | } 863 | }); 864 | AST_String = DEFNODE("String", "value", { 865 | $documentation: "A string literal", 866 | $propdoc: { 867 | value: "[string] the contents of this string" 868 | } 869 | }, AST_Constant); 870 | AST_Verbatim = DEFNODE("Verbatim", "value", { 871 | $documentation: "Raw JavaScript code", 872 | $propdoc: { 873 | value: "[string] A string of raw JS code" 874 | } 875 | }, AST_Constant); 876 | AST_Number = DEFNODE("Number", "value", { 877 | $documentation: "A number literal", 878 | $propdoc: { 879 | value: "[number] the numeric value" 880 | } 881 | }, AST_Constant); 882 | AST_RegExp = DEFNODE("RegExp", "value", { 883 | $documentation: "A regexp literal", 884 | $propdoc: { 885 | value: "[RegExp] the actual regexp" 886 | } 887 | }, AST_Constant); 888 | AST_Atom = DEFNODE("Atom", null, { 889 | $documentation: "Base class for atoms" 890 | }, AST_Constant); 891 | AST_Null = DEFNODE("Null", null, { 892 | $documentation: "The `null` atom", 893 | value: null 894 | }, AST_Atom); 895 | AST_NaN = DEFNODE("NaN", null, { 896 | $documentation: "The impossible value", 897 | value: 0 / 0 898 | }, AST_Atom); 899 | AST_Undefined = DEFNODE("Undefined", null, { 900 | $documentation: "The `undefined` value", 901 | value: function() { 902 | }.call(this) 903 | }, AST_Atom); 904 | AST_Hole = DEFNODE("Hole", null, { 905 | $documentation: "A hole in an array", 906 | value: function() { 907 | }.call(this) 908 | }, AST_Atom); 909 | AST_Infinity = DEFNODE("Infinity", null, { 910 | $documentation: "The `Infinity` value", 911 | value: 1 / 0 912 | }, AST_Atom); 913 | AST_Boolean = DEFNODE("Boolean", null, { 914 | $documentation: "Base class for booleans" 915 | }, AST_Atom); 916 | AST_False = DEFNODE("False", null, { 917 | $documentation: "The `false` atom", 918 | value: false 919 | }, AST_Boolean); 920 | AST_True = DEFNODE("True", null, { 921 | $documentation: "The `true` atom", 922 | value: true 923 | }, AST_Boolean); 924 | function TreeWalker(callback) { 925 | this.visit = callback; 926 | this.stack = []; 927 | } 928 | TreeWalker.prototype = { 929 | _visit: function(node, descend) { 930 | var ret; 931 | this.stack.push(node); 932 | ret = this.visit(node, descend ? function() { 933 | descend.call(node); 934 | } : noop); 935 | if (!ret && descend) { 936 | descend.call(node); 937 | } 938 | this.stack.pop(); 939 | return ret; 940 | }, 941 | parent: function(n) { 942 | return this.stack[this.stack.length - 2 - (n || 0)]; 943 | }, 944 | push: function(node) { 945 | this.stack.push(node); 946 | }, 947 | pop: function() { 948 | return this.stack.pop(); 949 | }, 950 | self: function() { 951 | return this.stack[this.stack.length - 1]; 952 | }, 953 | find_parent: function(type) { 954 | var stack, x, i; 955 | stack = this.stack; 956 | for (i = stack.length - 1; i > -1; i-=1) { 957 | x = stack[i]; 958 | if (x instanceof type) { 959 | return x; 960 | } 961 | } 962 | }, 963 | in_boolean_context: function() { 964 | var stack, i, p, self; 965 | stack = this.stack; 966 | i = stack.length; 967 | self = stack[i -= 1]; 968 | while (i > 0) { 969 | p = stack[i -= 1]; 970 | if (p instanceof AST_If && p.condition === self || p instanceof AST_Conditional && p.condition === self || p instanceof AST_DWLoop && p.condition === self || p instanceof AST_UnaryPrefix && p.operator === "!" && p.expression === self) { 971 | return true; 972 | } 973 | if (!(p instanceof AST_Binary && (p.operator === "&&" || p.operator === "||"))) { 974 | return false; 975 | } 976 | self = p; 977 | } 978 | }, 979 | loopcontrol_target: function(label) { 980 | var stack, x, i; 981 | stack = this.stack; 982 | if (label) { 983 | for (i = stack.length - 1; i > -1; i-=1) { 984 | x = stack[i]; 985 | if (x instanceof AST_LabeledStatement && x.label.name === label.name) { 986 | return x.body; 987 | } 988 | } 989 | } else { 990 | for (i = stack.length - 1; i > -1; i-=1) { 991 | x = stack[i]; 992 | if (x instanceof AST_Switch || x instanceof AST_ForIn || x instanceof AST_DWLoop) { 993 | return x; 994 | } 995 | } 996 | } 997 | } 998 | }; -------------------------------------------------------------------------------- /AngularJS Example/static/rapydscript/0.3.6/lib/baselib.js: -------------------------------------------------------------------------------- 1 | function abs(n) { 2 | return Math.abs(n); 3 | } 4 | 5 | function _$rapyd$_bind(fn, thisArg) { 6 | var ret; 7 | if (fn.orig) { 8 | fn = fn.orig; 9 | } 10 | if (thisArg === false) { 11 | return fn; 12 | } 13 | ret = function() { 14 | return fn.apply(thisArg, arguments); 15 | }; 16 | ret.orig = fn; 17 | return ret; 18 | } 19 | 20 | function _$rapyd$_rebindAll(thisArg, rebind) { 21 | if (typeof rebind === "undefined") { 22 | rebind = true; 23 | } 24 | for (var p in thisArg) { 25 | if (thisArg[p] && thisArg[p].orig) { 26 | if (rebind) { 27 | thisArg[p] = _$rapyd$_bind(thisArg[p], thisArg); 28 | } else { 29 | thisArg[p] = thisArg[p].orig; 30 | } 31 | } 32 | } 33 | } 34 | 35 | function dir(item) { 36 | var arr; 37 | arr = []; 38 | for (var i in item) { 39 | arr.push(i); 40 | } 41 | return arr; 42 | } 43 | 44 | function enumerate(item) { 45 | var arr; 46 | arr = []; 47 | for (var i=0;i\n http://www.pyjeon.com\n\n Distributed under Apache 2.0 license:\n Copyright 2013 (c) Alexander Tsepkov \n\n RapydScript source code is originally based on UglifyJS2 (covered\n by BSD license). UglifyJS2 was written by Mihai Bazon\n , who is its respective copyright holder.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions\n are met:\n\n * Redistributions of source code must retain the above\n copyright notice, this list of conditions and the following\n disclaimer.\n\n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials\n provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY\n EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE\n LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\n TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\n THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n SUCH DAMAGE.\n\n **********************************************************************\n"; 3 | "use strict"; 4 | function array_to_hash(a) { 5 | var ret, i; 6 | ret = Object.create(null); 7 | for (i = 0; i < len(a); i++) { 8 | ret[a[i]] = true; 9 | } 10 | return ret; 11 | } 12 | function slice(a, start) { 13 | return Array.prototype.slice.call(a, start || 0); 14 | } 15 | function characters(str_) { 16 | return str_.split(""); 17 | } 18 | function member(name, array) { 19 | var i; 20 | for (i = array.length - 1; i > -1; i-=1) { 21 | if (array[i] === name) { 22 | return true; 23 | } 24 | } 25 | return false; 26 | } 27 | function find_if(func, array) { 28 | var i; 29 | for (i = 0; i < len(array); i++) { 30 | if (func(array[i])) { 31 | return array[i]; 32 | } 33 | } 34 | } 35 | function repeat_string(str_, i) { 36 | var d; 37 | if (i <= 0) { 38 | return ""; 39 | } 40 | if (i === 1) { 41 | return str_; 42 | } 43 | d = repeat_string(str_, i >> 1); 44 | d += d; 45 | if (i & 1) { 46 | d += str_; 47 | } 48 | return d; 49 | } 50 | function DefaultsError(msg, defs) { 51 | this.msg = msg; 52 | this.defs = defs; 53 | } 54 | function defaults(args, defs, croak) { 55 | var ret, i; 56 | if (args === true) { 57 | args = {}; 58 | } 59 | ret = args || {}; 60 | if (croak) { 61 | for (i in ret) { 62 | if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i)) { 63 | throw new DefaultsError("`" + i + "` is not a supported option", defs); 64 | } 65 | } 66 | } 67 | for (i in defs) { 68 | if (defs.hasOwnProperty(i)) { 69 | ret[i] = args && args.hasOwnProperty(i) ? args[i] : defs[i]; 70 | } 71 | } 72 | return ret; 73 | } 74 | function merge(obj, ext) { 75 | var i; 76 | for (i in ext) { 77 | if (ext.hasOwnProperty(i)) { 78 | obj[i] = ext[i]; 79 | } 80 | } 81 | return obj; 82 | } 83 | function noop() { 84 | } 85 | MAP = function() { 86 | var skip; 87 | function MAP(a, f, backwards) { 88 | var ret, top, i; 89 | ret = []; 90 | top = []; 91 | function doit() { 92 | var is_last, val; 93 | val = f(a[i], i); 94 | is_last = val instanceof Last; 95 | if (is_last) { 96 | val = val.v; 97 | } 98 | if (val instanceof AtTop) { 99 | val = val.v; 100 | if (val instanceof Splice) { 101 | top.push.apply(top, backwards ? val.v.slice().reverse() : val.v); 102 | } else { 103 | top.push(val); 104 | } 105 | } else if (val !== skip) { 106 | if (val instanceof Splice) { 107 | ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v); 108 | } else { 109 | ret.push(val); 110 | } 111 | } 112 | return is_last; 113 | } 114 | if (Array.isArray(a)) { 115 | if (backwards) { 116 | for (i = a.length - 1; i > -1; i-=1) { 117 | if (doit()) { 118 | break; 119 | } 120 | } 121 | ret.reverse(); 122 | top.reverse(); 123 | } else { 124 | for (i = 0; i < len(a); i++) { 125 | if (doit()) { 126 | break; 127 | } 128 | } 129 | } 130 | } else { 131 | for (i in a) { 132 | if (a.hasOwnProperty(i)) { 133 | if (doit()) { 134 | break; 135 | } 136 | } 137 | } 138 | } 139 | return top.concat(ret); 140 | } 141 | MAP.at_top = function(val) { 142 | return new AtTop(val); 143 | }; 144 | MAP.splice = function(val) { 145 | return new Splice(val); 146 | }; 147 | MAP.last = function(val) { 148 | return new Last(val); 149 | }; 150 | skip = MAP.skip = {}; 151 | function AtTop(val) { 152 | this.v = val; 153 | } 154 | function Splice(val) { 155 | this.v = val; 156 | } 157 | function Last(val) { 158 | this.v = val; 159 | } 160 | return MAP; 161 | }.call(this); 162 | function push_uniq(array, el) { 163 | if (array.indexOf(el) < 0) { 164 | array.push(el); 165 | } 166 | } 167 | function string_template(text, props) { 168 | return text.replace(/\{(.+?)\}/g, function(str_, p) { 169 | return props[p]; 170 | }); 171 | } 172 | function remove(array, el) { 173 | var i; 174 | for (i = array.length - 1; i > -1; i-=1) { 175 | if (array[i] === el) { 176 | array.splice(i, 1); 177 | } 178 | } 179 | } 180 | function mergeSort(array, cmp) { 181 | if (array.length < 2) { 182 | return array.slice(); 183 | } 184 | function merge(a, b) { 185 | var r, ai, bi, i; 186 | r = []; 187 | ai = 0; 188 | bi = 0; 189 | i = 0; 190 | while (ai < a.length && bi < b.length) { 191 | if (cmp(a[ai], b[bi]) <= 0) { 192 | r[i] = a[ai]; 193 | ai += 1; 194 | } else { 195 | r[i] = b[bi]; 196 | bi += 1; 197 | } 198 | i += 1; 199 | } 200 | if (ai < a.length) { 201 | r.push.apply(r, a.slice(ai)); 202 | } 203 | if (bi < b.length) { 204 | r.push.apply(r, b.slice(bi)); 205 | } 206 | return r; 207 | } 208 | function _ms(a) { 209 | var m, left, right; 210 | if (a.length <= 1) { 211 | return a; 212 | } 213 | m = Math.floor(a.length / 2); 214 | left = a.slice(0, m); 215 | right = a.slice(m); 216 | left = _ms(left); 217 | right = _ms(right); 218 | return merge(left, right); 219 | } 220 | return _ms(array); 221 | } 222 | function set_difference(a, b) { 223 | return a.filter(function(el) { 224 | return b.indexOf(el) < 0; 225 | }); 226 | } 227 | function set_intersection(a, b) { 228 | return a.filter(function(el) { 229 | return b.indexOf(el) >= 0; 230 | }); 231 | } 232 | function makePredicate(words) { 233 | var cats, skip, j, cat, i, f; 234 | if (!Array.isArray(words)) { 235 | words = words.split(" "); 236 | } 237 | f = ""; 238 | cats = []; 239 | for (i = 0; i < len(words); i++) { 240 | skip = false; 241 | for (j = 0; j < len(cats); j++) { 242 | if (cats[j][0].length === words[i].length) { 243 | cats[j].push(words[i]); 244 | skip = true; 245 | break; 246 | } 247 | } 248 | if (!skip) { 249 | cats.push([ words[i] ]); 250 | } 251 | } 252 | function compareTo(arr) { 253 | var i; 254 | if (arr.length === 1) { 255 | return f += "return str === " + JSON.stringify(arr[0]) + ";"; 256 | } 257 | f += "switch(str){"; 258 | for (i = 0; i < len(arr); i++) { 259 | f += "case " + JSON.stringify(arr[i]) + ":"; 260 | } 261 | f += "return true}return false;"; 262 | } 263 | if (cats.length > 3) { 264 | cats.sort(function(a, b) { 265 | return b.length - a.length; 266 | }); 267 | f += "switch(str.length){"; 268 | for (i = 0; i < len(cats); i++) { 269 | cat = cats[i]; 270 | f += "case " + cat[0].length + ":"; 271 | compareTo(cat); 272 | } 273 | f += "}"; 274 | } else { 275 | compareTo(words); 276 | } 277 | return new Function("str", f); 278 | } 279 | function Dictionary() { 280 | this._values = Object.create(null); 281 | this._size = 0; 282 | } 283 | Dictionary.prototype = { 284 | set: function(key, val) { 285 | if (!this.has(key)) { 286 | this._size += 1; 287 | } 288 | this._values["$" + key] = val; 289 | return this; 290 | }, 291 | add: function(key, val) { 292 | if (this.has(key)) { 293 | this.get(key).push(val); 294 | } else { 295 | this.set(key, [ val ]); 296 | } 297 | return this; 298 | }, 299 | get: function(key) { 300 | return this._values["$" + key]; 301 | }, 302 | del_: function(key) { 303 | if (this.has(key)) { 304 | this._size -= 1; 305 | delete this._values["$" + key]; 306 | } 307 | return this; 308 | }, 309 | has: function(key) { 310 | return _$rapyd$_in("$" + key, this._values); 311 | }, 312 | each: function(f) { 313 | var i; 314 | for (i in this._values) { 315 | f(this._values[i], i.substr(1)); 316 | } 317 | }, 318 | size: function() { 319 | return this._size; 320 | }, 321 | map: function(f) { 322 | var ret, i; 323 | ret = []; 324 | for (i in this._values) { 325 | ret.push(f(this._values[i], i.substr(1))); 326 | } 327 | return ret; 328 | } 329 | }; -------------------------------------------------------------------------------- /AngularJS Example/static/rapydscript/0.3.6/stdlib.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var _$rapyd$_Temp; 3 | function range(start, stop, step) { 4 | var length, idx, range; 5 | if (arguments.length <= 1) { 6 | stop = start || 0; 7 | start = 0; 8 | } 9 | step = arguments[2] || 1; 10 | length = Math.max(Math.ceil((stop - start) / step), 0); 11 | idx = 0; 12 | range = new Array(length); 13 | while (idx < length) { 14 | range[idx++] = start; 15 | start += step; 16 | } 17 | return range; 18 | } 19 | function _$rapyd$_Iterable(iterable) { 20 | if (iterable instanceof Array || iterable instanceof String || typeof iterable === "string") { 21 | return iterable; 22 | } 23 | return Object.keys(iterable); 24 | } 25 | function _$rapyd$_in(val, arr) { 26 | if (arr instanceof Array || typeof arr === "string") { 27 | return arr.indexOf(val) !== -1; 28 | } else { 29 | if (arr.hasOwnProperty(val)) { 30 | return true; 31 | } 32 | return false; 33 | } 34 | } 35 | function dir(item) { 36 | var arr; 37 | arr = []; 38 | for (var i in item) { 39 | arr.push(i); 40 | } 41 | return arr; 42 | } 43 | function _$rapyd$_extends(child, parent) { 44 | child.prototype = Object.create(parent.prototype); 45 | child.prototype.constructor = child; 46 | } 47 | var str; 48 | str = JSON.stringify; 49 | function kwargs(f) { 50 | var argNames; 51 | argNames = f.toString().match(/\(([^\)]+)/)[1]; 52 | argNames = argNames ? argNames.split(",").map(function(s) { 53 | return s.trim(); 54 | }) : []; 55 | return function() { 56 | var args, kw, i; 57 | args = [].slice.call(arguments); 58 | if (args.length) { 59 | kw = args.pop(); 60 | if (typeof kw === "object") { 61 | for (i = 0; i < argNames.length; i++) { 62 | if (_$rapyd$_in(argNames[i], dir(kw))) { 63 | args[i] = kw[argNames[i]]; 64 | } 65 | } 66 | } else { 67 | args.push(kw); 68 | } 69 | } 70 | return f.apply(this, args); 71 | }; 72 | } 73 | function IndexError() { 74 | IndexError.prototype.__init__.apply(this, arguments); 75 | } 76 | _$rapyd$_extends(IndexError, Error); 77 | IndexError.prototype.__init__ = function __init__(message){ 78 | var self = this; 79 | if (typeof message === "undefined") message = "list index out of range"; 80 | self.name = "IndexError"; 81 | self.message = message; 82 | }; 83 | 84 | function TypeError() { 85 | TypeError.prototype.__init__.apply(this, arguments); 86 | } 87 | _$rapyd$_extends(TypeError, Error); 88 | TypeError.prototype.__init__ = function __init__(message){ 89 | var self = this; 90 | self.name = "TypeError"; 91 | self.message = message; 92 | }; 93 | 94 | function ValueError() { 95 | ValueError.prototype.__init__.apply(this, arguments); 96 | } 97 | _$rapyd$_extends(ValueError, Error); 98 | ValueError.prototype.__init__ = function __init__(message){ 99 | var self = this; 100 | self.name = "ValueError"; 101 | self.message = message; 102 | }; 103 | 104 | function AssertionError() { 105 | AssertionError.prototype.__init__.apply(this, arguments); 106 | } 107 | _$rapyd$_extends(AssertionError, Error); 108 | AssertionError.prototype.__init__ = function __init__(message){ 109 | var self = this; 110 | if (typeof message === "undefined") message = ""; 111 | self.name = "AssertionError"; 112 | self.message = message; 113 | }; 114 | 115 | function map(oper, arr) { 116 | return list(arr.map(oper)); 117 | } 118 | function filter(oper, arr) { 119 | return list(arr.filter(oper)); 120 | } 121 | function sum(arr, start) { 122 | if (typeof start === "undefined") start = 0; 123 | return arr.reduce(function(prev, cur) { 124 | return prev + cur; 125 | }, start); 126 | } 127 | function deep_eq(a, b) { 128 | var i; 129 | "\n Equality comparison that works with all data types, returns true if structure and\n contents of first object equal to those of second object\n\n Arguments:\n a: first object\n b: second object\n "; 130 | if (a === b) { 131 | return true; 132 | } 133 | if (a instanceof Array && b instanceof Array || a instanceof Object && b instanceof Object) { 134 | if (a.constructor !== b.constructor || a.length !== b.length) { 135 | return false; 136 | } 137 | var _$rapyd$_Iter0 = _$rapyd$_Iterable(dict.keys(a)); 138 | for (var _$rapyd$_Index0 = 0; _$rapyd$_Index0 < _$rapyd$_Iter0.length; _$rapyd$_Index0++) { 139 | i = _$rapyd$_Iter0[_$rapyd$_Index0]; 140 | if (b.hasOwnProperty(i)) { 141 | if (!deep_eq(a[i], b[i])) { 142 | return false; 143 | } 144 | } else { 145 | return false; 146 | } 147 | } 148 | return true; 149 | } 150 | return false; 151 | } 152 | String.prototype.find = String.prototype.indexOf; 153 | String.prototype.strip = String.prototype.trim; 154 | String.prototype.lstrip = String.prototype.trimLeft; 155 | String.prototype.rstrip = String.prototype.trimRight; 156 | String.prototype.join = function(iterable) { 157 | return iterable.join(this); 158 | }; 159 | String.prototype.zfill = function(size) { 160 | var s; 161 | s = this; 162 | while (s.length < size) { 163 | s = "0" + s; 164 | } 165 | return s; 166 | }; 167 | function list(iterable) { 168 | if (typeof iterable === "undefined") iterable = []; 169 | var result, i; 170 | result = []; 171 | var _$rapyd$_Iter1 = _$rapyd$_Iterable(iterable); 172 | for (var _$rapyd$_Index1 = 0; _$rapyd$_Index1 < _$rapyd$_Iter1.length; _$rapyd$_Index1++) { 173 | i = _$rapyd$_Iter1[_$rapyd$_Index1]; 174 | result.append(i); 175 | } 176 | return result; 177 | } 178 | Array.prototype.append = Array.prototype.push; 179 | Array.prototype.find = Array.prototype.indexOf; 180 | Array.prototype.index = function(index) { 181 | var val; 182 | val = this.find(index); 183 | if (val === -1) { 184 | throw new ValueError(str(index) + " is not in list"); 185 | } 186 | return val; 187 | }; 188 | Array.prototype.insert = function(index, item) { 189 | this.splice(index, 0, item); 190 | }; 191 | Array.prototype.pop = function(index) { 192 | if (typeof index === "undefined") index = this.length - 1; 193 | return this.splice(index, 1)[0]; 194 | }; 195 | Array.prototype.extend = function(array2) { 196 | this.push.apply(this, array2); 197 | }; 198 | Array.prototype.remove = function(item) { 199 | var index; 200 | index = this.find(item); 201 | this.splice(index, 1); 202 | }; 203 | Array.prototype.copy = function() { 204 | return this.slice(0); 205 | }; 206 | function dict(iterable) { 207 | var result, key; 208 | result = {}; 209 | var _$rapyd$_Iter2 = _$rapyd$_Iterable(iterable); 210 | for (var _$rapyd$_Index2 = 0; _$rapyd$_Index2 < _$rapyd$_Iter2.length; _$rapyd$_Index2++) { 211 | key = _$rapyd$_Iter2[_$rapyd$_Index2]; 212 | result[key] = iterable[key]; 213 | } 214 | return result; 215 | } 216 | if (typeof Object.getOwnPropertyNames !== "function") { 217 | dict.keys = function(hash) { 218 | var keys; 219 | keys = []; 220 | 221 | for (var x in hash) { 222 | if (hash.hasOwnProperty(x)) { 223 | keys.push(x); 224 | } 225 | } 226 | ; 227 | return keys; 228 | }; 229 | } else { 230 | dict.keys = function(hash) { 231 | return Object.getOwnPropertyNames(hash); 232 | }; 233 | } 234 | dict.values = function(hash) { 235 | var vals, key; 236 | vals = []; 237 | var _$rapyd$_Iter3 = _$rapyd$_Iterable(dict.keys(hash)); 238 | for (var _$rapyd$_Index3 = 0; _$rapyd$_Index3 < _$rapyd$_Iter3.length; _$rapyd$_Index3++) { 239 | key = _$rapyd$_Iter3[_$rapyd$_Index3]; 240 | vals.append(hash[key]); 241 | } 242 | return vals; 243 | }; 244 | dict.items = function(hash) { 245 | var items, key; 246 | items = []; 247 | var _$rapyd$_Iter4 = _$rapyd$_Iterable(dict.keys(hash)); 248 | for (var _$rapyd$_Index4 = 0; _$rapyd$_Index4 < _$rapyd$_Iter4.length; _$rapyd$_Index4++) { 249 | key = _$rapyd$_Iter4[_$rapyd$_Index4]; 250 | items.append([key, hash[key]]); 251 | } 252 | return items; 253 | }; 254 | dict.copy = dict; 255 | dict.clear = function(hash) { 256 | var key; 257 | var _$rapyd$_Iter5 = _$rapyd$_Iterable(dict.keys(hash)); 258 | for (var _$rapyd$_Index5 = 0; _$rapyd$_Index5 < _$rapyd$_Iter5.length; _$rapyd$_Index5++) { 259 | key = _$rapyd$_Iter5[_$rapyd$_Index5]; 260 | delete hash[key]; 261 | } 262 | }; 263 | -------------------------------------------------------------------------------- /AngularJS Example/static/rapydscript/pyjTransformer.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 3 | /** 4 | * Actually transform the code. 5 | * 6 | * @param {string} code 7 | * @param {string?} url 8 | * @param {object?} options 9 | * @return {string} The transformed code. 10 | * @internal 11 | */ 12 | function transformCode(code, url, options) { 13 | //RapydScript options 14 | var rs_options = { 15 | "filename":"demo", 16 | "toplevel":null, 17 | "basedir": null, 18 | "libdir": null 19 | }; 20 | var output_opts = { 21 | "beautify":true, 22 | "private_scope":false, 23 | "omit_baselib":true, 24 | "comments" : true 25 | }; 26 | 27 | var rapydscript_string = code; 28 | output = OutputStream(output_opts) 29 | rapydscript_string += '\n'; //just to be safe 30 | 31 | try { 32 | TOPLEVEL = parse(rapydscript_string, rs_options); 33 | TOPLEVEL.print(output); 34 | //(new Function(String(output) + '\n'))(); 35 | var js_code = String(output) + '\n' 36 | js_code = js_code.replace('var __name__ = "__main__";', ''); 37 | return js_code 38 | 39 | } catch(err) { 40 | console.log("ERROR: " + err.message + ". Line " + err.line + ", column " + err.col + "."); 41 | } 42 | } 43 | 44 | /** 45 | * Appends a script element at the end of the with the content of code, 46 | * after transforming it. 47 | * 48 | * @param {string} code The original source code 49 | * @param {string?} url Where the code came from. null if inline 50 | * @param {object?} options Options to pass to jstransform 51 | * @internal 52 | */ 53 | function run(code, url, options) { 54 | var scriptEl = document.createElement('script'); 55 | scriptEl.text = transformCode(code, url, options); 56 | if (options.otype) { 57 | scriptEl.type = options.otype 58 | } 59 | headEl.appendChild(scriptEl); 60 | } 61 | 62 | /** 63 | * Load script from the provided url and pass the content to the callback. 64 | * 65 | * @param {string} script The script 66 | * @param {function} callback Function to call with the content of url 67 | * @internal 68 | */ 69 | function load(script, successCallback, errorCallback) { 70 | var xhr; 71 | xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') 72 | : new XMLHttpRequest(); 73 | 74 | // async, however scripts will be executed in the order they are in the 75 | // DOM to mirror normal script loading. 76 | xhr.open('GET', 77 | script.src, 78 | script.options.async 79 | ); 80 | if ('overrideMimeType' in xhr) { 81 | xhr.overrideMimeType('text/plain'); 82 | } 83 | xhr.onreadystatechange = function() { 84 | if (xhr.readyState === 4) { 85 | if (xhr.status === 0 || xhr.status === 200) { 86 | successCallback(xhr.responseText); 87 | } else { 88 | errorCallback(); 89 | throw new Error("Could not load " + script.src); 90 | } 91 | } 92 | }; 93 | return xhr.send(null); 94 | } 95 | 96 | /** 97 | * Loop over provided script tags and get the content, via innerHTML if an 98 | * inline script, or by using XHR. Transforms are applied if needed. The scripts 99 | * are executed in the order they are found on the page. 100 | * 101 | * @param {array} scripts The 22 | 23 | ``` 24 | 25 | ## RapydScript introduction 26 | 27 | Rapydscript is a pre-compiler for JavaScript, similar to CoffeeScript, but with cleaner, more readable python-like syntax. 28 | 29 | 30 | ## links 31 | 32 | * [RapydScript on Github](https://github.com/atsepkov/RapydScript) 33 | * [RapydScript.com](http://RapydScript.com) 34 | * [RapydScript.cn](http://RapydScript.cn/docs) simplified chinese docs online for RapydScript 35 | * [Yoeman angularjs generator, surpport for RapydScript, Angular and Angular-ui](https://github.com/loolmeh/generator-rui-angular) 36 | * [Django package for using the RapydScript javascript pre-compiler](https://github.com/pztrick/DjScript) 37 | * [Language support for rapydscript (.pyj) in the Atom editor](https://github.com/tgienger/language-rapydscript) 38 | * [auto compiles rapydscript .pyj files to .js on save](https://github.com/tgienger/Atom-rapydscript-auto-compile) 39 | 40 | 41 | ## demo 42 | 43 | * [RapydLab](http://rapydscript.cn/rapydlab) 44 | * [RapydScript ShowCases](http://salvatore.pythonanywhere.com/RapydScript) 45 | * [RapydBox](http://salvatore.pythonanywhere.com/RapydBox/default/editor) 46 | 47 | ## others 48 | 49 | * [glowscript:a project done by a member of community, surppot for webGL](http://www.glowscript.org/) 50 | 51 | 52 | # 说明文档(中文) 53 | 54 | ``pyjTransformer.js`` 的代码是从ReactJS中的 [JSXTransformer](http://facebook.github.io/react/downloads.html) 改的。 55 | 56 | ## 实现的功能: 57 | 58 | 1. 自动将浏览器中的.pyj文件或页面上的RapydScript代码编译成javascript代码。 59 | 2. 可以与jQuery、AngularJS、ReactJS等外部框架共同工作。 60 | 61 | > **注意:** 要使RapydScript在浏览器中与AngularJS正确地工作(即保证rapydscript代码的编译和运行在AngularJS之前),你需要在 `` 70 | 71 | ``` 72 | 73 | ## RapydScript简介 74 | 75 | RapydScript是一个可以被预编译为JavaScript的脚本语言。 76 | RapydScript与CoffeeScript很相似,但是由于它采用的是Python的语法,因而更加容易阅读。 77 | 78 | ## links 79 | 80 | * [RapydScript on Github](https://github.com/atsepkov/RapydScript) 81 | * [RapydScript.com](http://RapydScript.com) 82 | * [RapydScript.cn](http://RapydScript.cn/docs) 中文在线文档 83 | * [Yeoman的项目生成工具,支持RapydScript,Angular,Angular-ui](https://github.com/loolmeh/generator-rui-angular) 84 | * [在Django中使用RapydScript的python扩展程序包](https://github.com/pztrick/DjScript) 85 | * [Atom编辑器的RapydScript语言支持包](https://github.com/tgienger/language-rapydscript) 86 | * [Atom编辑器的RapydScript脚本文件自动编译插件](https://github.com/tgienger/Atom-rapydscript-auto-compile) 87 | 88 | 89 | ## 在线演示项目 90 | 91 | * [RapydLab](http://rapydscript.cn/rapydlab) 92 | * [RapydScript ShowCases](http://salvatore.pythonanywhere.com/RapydScript) 93 | * [RapydBox](http://salvatore.pythonanywhere.com/RapydBox/default/editor) 94 | 95 | ## 相关项目 96 | 97 | * [glowscript:RapydScript社区的项目,用于支持webGL编程](http://www.glowscript.org/) 98 | -------------------------------------------------------------------------------- /ReactJS Example/complie.bat: -------------------------------------------------------------------------------- 1 | @call rapydscript helloworld.pyj -o helloworld.js -p -b 2 | pause -------------------------------------------------------------------------------- /ReactJS Example/helloworld.js: -------------------------------------------------------------------------------- 1 | HelloWorld = React.createClass({ 2 | render: function() { 3 | return ( 4 |
5 |

6 | helloworld! 7 |

8 |
9 | ); 10 | } 11 | }); 12 | React.render( 13 | , 14 | document.getElementById('content') 15 | ); -------------------------------------------------------------------------------- /ReactJS Example/helloworld.pyj: -------------------------------------------------------------------------------- 1 | HelloWorld = React.createClass({ 2 | render: def(): 3 | return JS("""( 4 |
5 |

6 | helloworld! 7 |

8 |
9 | )""") 10 | }) 11 | 12 | ########################################################### 13 | # React render 14 | ########################################################### 15 | React.render( 16 | JS(""" 17 | , 18 | document.getElementById('content') 19 | """) 20 | ) 21 | -------------------------------------------------------------------------------- /ReactJS Example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | test 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /ReactJS Example/static/rapydscript/0.3.6/fis-conf.js: -------------------------------------------------------------------------------- 1 | //use baidu fis3 to compress .js files 2 | // 3 | fis.set('project.ignore',[ 4 | '*.js', //bourbon 5 | 'output/**' 6 | ]); 7 | 8 | fis.match('lib/*.js', { 9 | deploy: fis.plugin('local-deliver', { 10 | to: 'output/' 11 | }), 12 | packTo: 'rapydscript.min.js', 13 | }); 14 | 15 | fis.match('lib/*.js', { 16 | optimizer: fis.plugin('uglify-js'), 17 | useHash: false, 18 | }); 19 | 20 | 21 | -------------------------------------------------------------------------------- /ReactJS Example/static/rapydscript/0.3.6/lib/ast.js: -------------------------------------------------------------------------------- 1 | var AST_Token, AST_Node, AST_Statement, AST_Debugger, AST_Directive, AST_SimpleStatement, AST_Block, AST_BlockStatement, AST_EmptyStatement, AST_StatementWithBody, AST_LabeledStatement, AST_DWLoop, AST_Do, AST_While, AST_ForIn, AST_ForJS, AST_ListComprehension, AST_With, AST_Scope, AST_Toplevel, AST_Import, AST_Decorator, AST_Lambda, AST_Accessor, AST_Function, AST_Class, AST_Module, AST_Method, AST_Jump, AST_Exit, AST_Return, AST_Throw, AST_LoopControl, AST_Break, AST_Continue, AST_If, AST_Switch, AST_SwitchBranch, AST_Default, AST_Case, AST_Try, AST_Catch, AST_Except, AST_Finally, AST_Definitions, AST_Var, AST_Const, AST_VarDef, AST_BaseCall, AST_Call, AST_ClassCall, AST_New, AST_Seq, AST_PropAccess, AST_Dot, AST_Sub, AST_Splice, AST_Unary, AST_UnaryPrefix, AST_UnaryPostfix, AST_Binary, AST_Conditional, AST_Assign, AST_Array, AST_TupleUnpack, AST_Object, AST_ObjectProperty, AST_ObjectKeyVal, AST_ObjectSetter, AST_ObjectGetter, AST_Symbol, AST_SymbolAccessor, AST_SymbolDeclaration, AST_SymbolVar, AST_SymbolConst, AST_SymbolFunarg, AST_SymbolDefun, AST_SymbolLambda, AST_SymbolCatch, AST_Label, AST_SymbolRef, AST_LabelRef, AST_This, AST_Constant, AST_String, AST_Verbatim, AST_Number, AST_RegExp, AST_Atom, AST_Null, AST_NaN, AST_Undefined, AST_Hole, AST_Infinity, AST_Boolean, AST_False, AST_True; 2 | "\n**********************************************************************\n\n A RapydScript to JavaScript compiler.\n https://github.com/atsepkov/RapydScript\n\n -------------------------------- (C) ---------------------------------\n\n Author: Alexander Tsepkov\n \n http://www.pyjeon.com\n\n Distributed under Apache 2.0 license:\n Copyright 2013 (c) Alexander Tsepkov \n\n RapydScript source code is originally based on UglifyJS2 (covered\n by BSD license). UglifyJS2 was written by Mihai Bazon\n , who is its respective copyright holder.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions\n are met:\n\n * Redistributions of source code must retain the above\n copyright notice, this list of conditions and the following\n disclaimer.\n\n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials\n provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY\n EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE\n LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\n TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\n THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n SUCH DAMAGE.\n\n **********************************************************************\n"; 3 | "use strict"; 4 | function DEFNODE(type, props, methods, base) { 5 | var self_props, proto, code, ctor, i; 6 | if (arguments.length < 4) { 7 | base = AST_Node; 8 | } 9 | if (!props) { 10 | props = []; 11 | } else { 12 | props = props.split(/\s+/); 13 | } 14 | self_props = props; 15 | if (base && base.PROPS) { 16 | props = props.concat(base.PROPS); 17 | } 18 | code = "return function AST_" + type + "(props){ if (props) { "; 19 | for (i = props.length - 1; i > -1; i-=1) { 20 | code += "this." + props[i] + " = props." + props[i] + ";"; 21 | } 22 | proto = base && new base(); 23 | if (proto && proto.initialize || methods && methods.initialize) { 24 | code += "this.initialize();"; 25 | } 26 | code += "}}"; 27 | ctor = new Function(code)(); 28 | if (proto) { 29 | ctor.prototype = proto; 30 | ctor.BASE = base; 31 | } 32 | if (base) { 33 | base.SUBCLASSES.push(ctor); 34 | } 35 | ctor.prototype.CTOR = ctor; 36 | ctor.PROPS = props || null; 37 | ctor.SELF_PROPS = self_props; 38 | ctor.SUBCLASSES = []; 39 | if (type) { 40 | ctor.prototype.TYPE = ctor.TYPE = type; 41 | } 42 | if (methods) { 43 | for (i in methods) { 44 | if (methods.hasOwnProperty(i)) { 45 | if (/^\$/.test(i)) { 46 | ctor[i.substr(1)] = methods[i]; 47 | } else { 48 | ctor.prototype[i] = methods[i]; 49 | } 50 | } 51 | } 52 | } 53 | ctor.DEFMETHOD = function(name, method) { 54 | this.prototype[name] = method; 55 | }; 56 | return ctor; 57 | } 58 | AST_Token = DEFNODE("Token", "type value line col pos endpos nlb comments_before file", {}, null); 59 | AST_Node = DEFNODE("Node", "start end", { 60 | clone: function() { 61 | return new this.CTOR(this); 62 | }, 63 | $documentation: "Base class of all AST nodes", 64 | $propdoc: { 65 | start: "[AST_Token] The first token of this node", 66 | end: "[AST_Token] The last token of this node" 67 | }, 68 | _walk: function(visitor) { 69 | return visitor._visit(this); 70 | }, 71 | walk: function(visitor) { 72 | return this._walk(visitor); 73 | } 74 | }, null); 75 | AST_Node.warn_function = null; 76 | AST_Node.warn = function(txt, props) { 77 | if (AST_Node.warn_function) { 78 | AST_Node.warn_function(string_template(txt, props)); 79 | } 80 | }; 81 | AST_Statement = DEFNODE("Statement", null, { 82 | $documentation: "Base class of all statements" 83 | }); 84 | AST_Debugger = DEFNODE("Debugger", null, { 85 | $documentation: "Represents a debugger statement" 86 | }, AST_Statement); 87 | AST_Directive = DEFNODE("Directive", "value scope", { 88 | $documentation: "Represents a directive, like \"use strict\";", 89 | $propdoc: { 90 | value: "[string] The value of this directive as a plain string (it's not an AST_String!)", 91 | scope: "[AST_Scope/S] The scope that this directive affects" 92 | } 93 | }, AST_Statement); 94 | AST_SimpleStatement = DEFNODE("SimpleStatement", "body", { 95 | $documentation: "A statement consisting of an expression, i.e. a = 1 + 2", 96 | $propdoc: { 97 | body: "[AST_Node] an expression node (should not be instanceof AST_Statement)" 98 | }, 99 | _walk: function(visitor) { 100 | return visitor._visit(this, function() { 101 | this.body._walk(visitor); 102 | }); 103 | } 104 | }, AST_Statement); 105 | function walk_body(node, visitor) { 106 | if (node.body instanceof AST_Statement) { 107 | node.body._walk(visitor); 108 | } else { 109 | node.body.forEach(function(stat) { 110 | stat._walk(visitor); 111 | }); 112 | } 113 | } 114 | AST_Block = DEFNODE("Block", "body", { 115 | $documentation: "A body of statements (usually bracketed)", 116 | $propdoc: { 117 | body: "[AST_Statement*] an array of statements" 118 | }, 119 | _walk: function(visitor) { 120 | return visitor._visit(this, function() { 121 | walk_body(this, visitor); 122 | }); 123 | } 124 | }, AST_Statement); 125 | AST_BlockStatement = DEFNODE("BlockStatement", null, { 126 | $documentation: "A block statement" 127 | }, AST_Block); 128 | AST_EmptyStatement = DEFNODE("EmptyStatement", null, { 129 | $documentation: "The empty statement (empty block or simply a semicolon)", 130 | _walk: function(visitor) { 131 | return visitor._visit(this); 132 | } 133 | }, AST_Statement); 134 | AST_StatementWithBody = DEFNODE("StatementWithBody", "body", { 135 | $documentation: "Base class for all statements that contain one nested body: `For`, `ForIn`, `Do`, `While`, `With`", 136 | $propdoc: { 137 | body: "[AST_Statement] the body; this should always be present, even if it's an AST_EmptyStatement" 138 | }, 139 | _walk: function(visitor) { 140 | return visitor._visit(this, function() { 141 | this.body._walk(visitor); 142 | }); 143 | } 144 | }, AST_Statement); 145 | AST_LabeledStatement = DEFNODE("LabeledStatement", "label", { 146 | $documentation: "Statement with a label", 147 | $propdoc: { 148 | label: "[AST_Label] a label definition" 149 | }, 150 | _walk: function(visitor) { 151 | return visitor._visit(this, function() { 152 | this.label._walk(visitor); 153 | this.body._walk(visitor); 154 | }); 155 | } 156 | }, AST_StatementWithBody); 157 | AST_DWLoop = DEFNODE("DWLoop", "condition", { 158 | $documentation: "Base class for do/while statements", 159 | $propdoc: { 160 | condition: "[AST_Node] the loop condition. Should not be instanceof AST_Statement" 161 | }, 162 | _walk: function(visitor) { 163 | return visitor._visit(this, function() { 164 | this.condition._walk(visitor); 165 | this.body._walk(visitor); 166 | }); 167 | } 168 | }, AST_StatementWithBody); 169 | AST_Do = DEFNODE("Do", null, { 170 | $documentation: "A `do` statement" 171 | }, AST_DWLoop); 172 | AST_While = DEFNODE("While", null, { 173 | $documentation: "A `while` statement" 174 | }, AST_DWLoop); 175 | AST_ForIn = DEFNODE("ForIn", "init name object", { 176 | $documentation: "A `for ... in` statement", 177 | $propdoc: { 178 | init: "[AST_Node] the `for/in` initialization code", 179 | name: "[AST_SymbolRef?] the loop variable, only if `init` is AST_Var", 180 | object: "[AST_Node] the object that we're looping through" 181 | }, 182 | _walk: function(visitor) { 183 | return visitor._visit(this, function() { 184 | this.init._walk(visitor); 185 | this.object._walk(visitor); 186 | this.body._walk(visitor); 187 | }); 188 | } 189 | }, AST_StatementWithBody); 190 | AST_ForJS = DEFNODE("ForJS", "condition", { 191 | $documentation: "A `for ... in` statement", 192 | $propdoc: { 193 | condition: "[AST_Verbatim] raw JavaScript conditional" 194 | } 195 | }, AST_StatementWithBody); 196 | AST_ListComprehension = DEFNODE("ListComprehension", "condition statement", { 197 | $documentation: "A list comprehension expression", 198 | $propdoc: { 199 | condition: "[AST_Node] the `if` condition", 200 | statement: "[AST_Node] statement to perform on each element before returning it" 201 | } 202 | }, AST_ForIn); 203 | AST_With = DEFNODE("With", "expression", { 204 | $documentation: "A `with` statement", 205 | $propdoc: { 206 | expression: "[AST_Node] the `with` expression" 207 | }, 208 | _walk: function(visitor) { 209 | return visitor._visit(this, function() { 210 | this.expression._walk(visitor); 211 | this.body._walk(visitor); 212 | }); 213 | } 214 | }, AST_StatementWithBody); 215 | AST_Scope = DEFNODE("Scope", "directives variables localvars functions uses_with uses_eval parent_scope enclosed cname", { 216 | $documentation: "Base class for all statements introducing a lexical scope", 217 | $propdoc: { 218 | directives: "[string*/S] an array of directives declared in this scope", 219 | variables: "[Object/S] a map of name -> SymbolDef for all variables/functions defined in this scope", 220 | localvars: "[SymbolDef*] list of variables local to this scope", 221 | functions: "[Object/S] like `variables`, but only lists function declarations", 222 | uses_with: "[boolean/S] tells whether this scope uses the `with` statement", 223 | uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`", 224 | parent_scope: "[AST_Scope?/S] link to the parent scope", 225 | enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes", 226 | cname: "[integer/S] current index for mangling variables (used internally by the mangler)" 227 | } 228 | }, AST_Block); 229 | AST_Toplevel = DEFNODE("Toplevel", "globals baselib imports strict shebang import_order module_id exports submodules classes", { 230 | $documentation: "The toplevel scope", 231 | $propdoc: { 232 | globals: "[Object/S] a map of name -> SymbolDef for all undeclared names", 233 | baselib: "[Object/s] a collection of used parts of baselib", 234 | imports: "[Object/S] a map of module_id->AST_Toplevel for all imported modules", 235 | nonlocalvars: "[String*] a list of all non-local variable names (names that come from the global scope)", 236 | strict: "[boolean/S] true if strict directive is in scope", 237 | shebang: "[string] If #! line is present, it will be stored here", 238 | import_order: "[number] The global order in which this scope was imported", 239 | module_id: "[string] The id of this module", 240 | exports: "[SymbolDef*] list of names exported from this module", 241 | submodules: "[string*] list of names exported from this module", 242 | classes: "[Object/S] a map of class names to AST_Class for classes defined in this module" 243 | }, 244 | wrap_enclose: function(arg_parameter_pairs) { 245 | var self, args, parameters, wrapped_tl; 246 | self = this; 247 | args = []; 248 | parameters = []; 249 | arg_parameter_pairs.forEach(function(pair) { 250 | var split; 251 | split = pair.split(":"); 252 | args.push(split[0]); 253 | parameters.push(split[1]); 254 | }); 255 | wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")"; 256 | wrapped_tl = parse(wrapped_tl); 257 | wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node) { 258 | if (node instanceof AST_Directive && node.value === "$ORIG") { 259 | return MAP.splice(self.body); 260 | } 261 | })); 262 | return wrapped_tl; 263 | }, 264 | wrap_commonjs: function(name, export_all) { 265 | var self, to_export, wrapped_tl; 266 | self = this; 267 | to_export = []; 268 | if (export_all) { 269 | self.figure_out_scope(); 270 | self.walk(new TreeWalker(function(node) { 271 | if (node instanceof AST_SymbolDeclaration && node.definition().global) { 272 | if (!find_if(function(n) { 273 | return n.name === node.name; 274 | }, to_export)) { 275 | to_export.push(node); 276 | } 277 | } 278 | })); 279 | } 280 | wrapped_tl = "(function(exports, global){ global['" + name + "'] = exports; '$ORIG'; '$EXPORTS'; }({}, (function(){return this}())))"; 281 | wrapped_tl = parse(wrapped_tl); 282 | wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node) { 283 | var tmp_, body; 284 | if (node instanceof AST_SimpleStatement) { 285 | node = node.body; 286 | if (node instanceof AST_String) { 287 | tmp_ = node.getValue(); 288 | if (tmp_ === "$ORIG") { 289 | return MAP.splice(self.body); 290 | } else if (tmp_ === "$EXPORTS") { 291 | body = []; 292 | to_export.forEach(function(sym) { 293 | body.push(new AST_SimpleStatement({ 294 | body: new AST_Assign({ 295 | left: new AST_Sub({ 296 | expression: new AST_SymbolRef({ 297 | name: "exports" 298 | }), 299 | property: new AST_String({ 300 | value: sym.name 301 | }) 302 | }), 303 | operator: "=", 304 | right: new AST_SymbolRef(sym) 305 | }) 306 | })); 307 | }); 308 | return MAP.splice(body); 309 | } 310 | } 311 | } 312 | })); 313 | return wrapped_tl; 314 | } 315 | }, AST_Scope); 316 | AST_Import = DEFNODE("Import", "module key argnames body", { 317 | $documentation: "Container for imports", 318 | $propdoc: { 319 | module: "[AST_SymbolVar] name of the module we're importing", 320 | key: "[string] The key by which this module is stored in the global modules mapping", 321 | argnames: "[AST_SymbolVar*] names of objects to be imported", 322 | body: "[AST_TopLevel] parsed contents of the imported file" 323 | } 324 | }, AST_Statement); 325 | AST_Decorator = DEFNODE("Decorator", "name", { 326 | $documentation: "Class for function decorators", 327 | $propdoc: { 328 | name: "[string] decorator name" 329 | } 330 | }); 331 | AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments decorators", { 332 | $documentation: "Base class for functions", 333 | $propdoc: { 334 | name: "[AST_SymbolDeclaration?] the name of this function", 335 | argnames: "[AST_SymbolFunarg*] array of function arguments", 336 | uses_arguments: "[boolean/S] tells whether this function accesses the arguments array", 337 | decorators: "[AST_Decorator*] function decorators, if any" 338 | }, 339 | _walk: function(visitor) { 340 | return visitor._visit(this, function() { 341 | if (this.name) { 342 | this.name._walk(visitor); 343 | } 344 | this.argnames.forEach(function(arg) { 345 | arg._walk(visitor); 346 | }); 347 | walk_body(this, visitor); 348 | }); 349 | } 350 | }, AST_Scope); 351 | AST_Accessor = DEFNODE("Accessor", null, { 352 | $documentation: "A setter/getter function" 353 | }, AST_Lambda); 354 | AST_Function = DEFNODE("Function", null, { 355 | $documentation: "A function expression" 356 | }, AST_Lambda); 357 | AST_Class = DEFNODE("Class", "init name parent static external bound decorators module_id", { 358 | $documentation: "A class declaration", 359 | $propdoc: { 360 | name: "[AST_SymbolDeclaration?] the name of this class", 361 | init: "[AST_Function] constructor for the class", 362 | parent: "[AST_Class?] parent class this class inherits from", 363 | "static": "[string*] list of static methods", 364 | external: "[boolean] true if class is declared elsewhere, but will be within current scope at runtime", 365 | bound: "[string*] list of methods that need to be bound to behave correctly (function pointers)", 366 | decorators: "[AST_Decorator*] function decorators, if any", 367 | module_id: "[string] The id of the module this class is defined in" 368 | }, 369 | _walk: function(visitor) { 370 | return visitor._visit(this, function() { 371 | this.name._walk(visitor); 372 | walk_body(this, visitor); 373 | this.parent._walk(visitor); 374 | }); 375 | } 376 | }, AST_Scope); 377 | AST_Module = DEFNODE("Module", "name external decorators", { 378 | $documentation: "A module definition, meant to abstract a group of related classes and/or functions", 379 | $propdoc: { 380 | name: "[AST_SymbolDeclaration?] the name of this class", 381 | external: "[boolean] true if module is declared elsewhere, but will be within current scope at runtime", 382 | decorators: "[AST_Decorator*] module decorators, if any" 383 | } 384 | }, AST_Scope); 385 | AST_Method = DEFNODE("Defun", "static", { 386 | $documentation: "A class method definition", 387 | $propdoc: { 388 | "static": "[boolean] true if method is static" 389 | } 390 | }, AST_Lambda); 391 | AST_Jump = DEFNODE("Jump", null, { 392 | $documentation: "Base class for “jumps” (for now that's `return`, `throw`, `break` and `continue`)" 393 | }, AST_Statement); 394 | AST_Exit = DEFNODE("Exit", "value", { 395 | $documentation: "Base class for “exits” (`return` and `throw`)", 396 | $propdoc: { 397 | value: "[AST_Node?] the value returned or thrown by this statement; could be null for AST_Return" 398 | }, 399 | _walk: function(visitor) { 400 | return visitor._visit(this, this.value && function() { 401 | this.value._walk(visitor); 402 | }); 403 | } 404 | }, AST_Jump); 405 | AST_Return = DEFNODE("Return", null, { 406 | $documentation: "A `return` statement" 407 | }, AST_Exit); 408 | AST_Throw = DEFNODE("Throw", null, { 409 | $documentation: "A `throw` statement" 410 | }, AST_Exit); 411 | AST_LoopControl = DEFNODE("LoopControl", "label", { 412 | $documentation: "Base class for loop control statements (`break` and `continue`)", 413 | $propdoc: { 414 | label: "[AST_LabelRef?] the label, or null if none" 415 | }, 416 | _walk: function(visitor) { 417 | return visitor._visit(this, this.label && function() { 418 | this.label._walk(visitor); 419 | }); 420 | } 421 | }, AST_Jump); 422 | AST_Break = DEFNODE("Break", null, { 423 | $documentation: "A `break` statement" 424 | }, AST_LoopControl); 425 | AST_Continue = DEFNODE("Continue", null, { 426 | $documentation: "A `continue` statement" 427 | }, AST_LoopControl); 428 | AST_If = DEFNODE("If", "condition alternative", { 429 | $documentation: "A `if` statement", 430 | $propdoc: { 431 | condition: "[AST_Node] the `if` condition", 432 | alternative: "[AST_Statement?] the `else` part, or null if not present" 433 | }, 434 | _walk: function(visitor) { 435 | return visitor._visit(this, function() { 436 | this.condition._walk(visitor); 437 | this.body._walk(visitor); 438 | if (this.alternative) { 439 | this.alternative._walk(visitor); 440 | } 441 | }); 442 | } 443 | }, AST_StatementWithBody); 444 | AST_Switch = DEFNODE("Switch", "expression", { 445 | $documentation: "A `switch` statement", 446 | $propdoc: { 447 | expression: "[AST_Node] the `switch` “discriminant”" 448 | }, 449 | _walk: function(visitor) { 450 | return visitor._visit(this, function() { 451 | this.expression._walk(visitor); 452 | walk_body(this, visitor); 453 | }); 454 | } 455 | }, AST_Block); 456 | AST_SwitchBranch = DEFNODE("SwitchBranch", null, { 457 | $documentation: "Base class for `switch` branches" 458 | }, AST_Block); 459 | AST_Default = DEFNODE("Default", null, { 460 | $documentation: "A `default` switch branch" 461 | }, AST_SwitchBranch); 462 | AST_Case = DEFNODE("Case", "expression", { 463 | $documentation: "A `case` switch branch", 464 | $propdoc: { 465 | expression: "[AST_Node] the `case` expression" 466 | }, 467 | _walk: function(visitor) { 468 | return visitor._visit(this, function() { 469 | this.expression._walk(visitor); 470 | walk_body(this, visitor); 471 | }); 472 | } 473 | }, AST_SwitchBranch); 474 | AST_Try = DEFNODE("Try", "bcatch bfinally", { 475 | $documentation: "A `try` statement", 476 | $propdoc: { 477 | bcatch: "[AST_Catch?] the catch block, or null if not present", 478 | bfinally: "[AST_Finally?] the finally block, or null if not present" 479 | }, 480 | _walk: function(visitor) { 481 | return visitor._visit(this, function() { 482 | walk_body(this, visitor); 483 | if (this.bcatch) { 484 | this.bcatch._walk(visitor); 485 | } 486 | if (this.bfinally) { 487 | this.bfinally._walk(visitor); 488 | } 489 | }); 490 | } 491 | }, AST_Block); 492 | AST_Catch = DEFNODE("Catch", null, { 493 | $documentation: "A `catch` node; only makes sense as part of a `try` statement", 494 | $propdoc: {}, 495 | _walk: function(visitor) { 496 | return visitor._visit(this, function() { 497 | this.argname._walk(visitor); 498 | walk_body(this, visitor); 499 | }); 500 | } 501 | }, AST_Block); 502 | AST_Except = DEFNODE("Except", "argname errors", { 503 | $documentation: "An `except` node for RapydScript, which resides inside the catch block", 504 | $propdoc: { 505 | argname: "[AST_SymbolCatch] symbol for the exception", 506 | errors: "[AST_SymbolVar*] error classes to catch in this block" 507 | } 508 | }, AST_Block); 509 | AST_Finally = DEFNODE("Finally", null, { 510 | $documentation: "A `finally` node; only makes sense as part of a `try` statement" 511 | }, AST_Block); 512 | AST_Definitions = DEFNODE("Definitions", "definitions", { 513 | $documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)", 514 | $propdoc: { 515 | definitions: "[AST_VarDef*] array of variable definitions" 516 | }, 517 | _walk: function(visitor) { 518 | return visitor._visit(this, function() { 519 | this.definitions.forEach(function(def_) { 520 | def_._walk(visitor); 521 | }); 522 | }); 523 | } 524 | }, AST_Statement); 525 | AST_Var = DEFNODE("Var", null, { 526 | $documentation: "A `var` statement" 527 | }, AST_Definitions); 528 | AST_Const = DEFNODE("Const", null, { 529 | $documentation: "A `const` statement" 530 | }, AST_Definitions); 531 | AST_VarDef = DEFNODE("VarDef", "name value", { 532 | $documentation: "A variable declaration; only appears in a AST_Definitions node", 533 | $propdoc: { 534 | name: "[AST_SymbolVar|AST_SymbolConst] name of the variable", 535 | value: "[AST_Node?] initializer, or null if there's no initializer" 536 | }, 537 | _walk: function(visitor) { 538 | return visitor._visit(this, function() { 539 | this.name._walk(visitor); 540 | if (this.value) { 541 | this.value._walk(visitor); 542 | } 543 | }); 544 | } 545 | }); 546 | AST_BaseCall = DEFNODE("BaseCall", "args", { 547 | $documentation: "A base class for function calls", 548 | $propdoc: { 549 | args: "[AST_Node*] array of arguments" 550 | } 551 | }); 552 | AST_Call = DEFNODE("Call", "expression", { 553 | $documentation: "A function call expression", 554 | $propdoc: { 555 | expression: "[AST_Node] expression to invoke as function" 556 | }, 557 | _walk: function(visitor) { 558 | return visitor._visit(this, function() { 559 | this.expression._walk(visitor); 560 | this.args.forEach(function(arg) { 561 | arg._walk(visitor); 562 | }); 563 | }); 564 | } 565 | }, AST_BaseCall); 566 | AST_ClassCall = DEFNODE("ClassCall", "class method static", { 567 | $documentation: "A function call expression", 568 | $propdoc: { 569 | "class": "[string] name of the class method belongs to", 570 | method: "[string] class method being called", 571 | "static": "[boolean] defines whether the method is static" 572 | }, 573 | _walk: function(visitor) { 574 | return visitor._visit(this, function() { 575 | this.expression._walk(visitor); 576 | this.args.forEach(function(arg) { 577 | arg._walk(visitor); 578 | }); 579 | }); 580 | } 581 | }, AST_BaseCall); 582 | AST_New = DEFNODE("New", null, { 583 | $documentation: "An object instantiation. Derives from a function call since it has exactly the same properties" 584 | }, AST_Call); 585 | AST_Seq = DEFNODE("Seq", "car cdr", { 586 | $documentation: "A sequence expression (two comma-separated expressions)", 587 | $propdoc: { 588 | car: "[AST_Node] first element in sequence", 589 | cdr: "[AST_Node] second element in sequence" 590 | }, 591 | $cons: function(x, y) { 592 | var seq; 593 | seq = new AST_Seq(x); 594 | seq.car = x; 595 | seq.cdr = y; 596 | return seq; 597 | }, 598 | $from_array: function(array) { 599 | var list, i, p; 600 | if (array.length === 0) { 601 | return null; 602 | } 603 | if (array.length === 1) { 604 | return array[0].clone(); 605 | } 606 | list = null; 607 | for (i = array.length - 1; i > -1; i-=1) { 608 | list = AST_Seq.cons(array[i], list); 609 | } 610 | p = list; 611 | while (p) { 612 | if (p.cdr && !p.cdr.cdr) { 613 | p.cdr = p.cdr.car; 614 | break; 615 | } 616 | p = p.cdr; 617 | } 618 | return list; 619 | }, 620 | to_array: function() { 621 | var a, p; 622 | p = this; 623 | a = []; 624 | while (p) { 625 | a.push(p.car); 626 | if (p.cdr && !(p.cdr instanceof AST_Seq)) { 627 | a.push(p.cdr); 628 | break; 629 | } 630 | p = p.cdr; 631 | } 632 | return a; 633 | }, 634 | add: function(node) { 635 | var cell, p; 636 | p = this; 637 | while (p) { 638 | if (!(p.cdr instanceof AST_Seq)) { 639 | cell = AST_Seq.cons(p.cdr, node); 640 | return p.cdr = cell; 641 | } 642 | p = p.cdr; 643 | } 644 | }, 645 | _walk: function(visitor) { 646 | return visitor._visit(this, function() { 647 | this.car._walk(visitor); 648 | if (this.cdr) { 649 | this.cdr._walk(visitor); 650 | } 651 | }); 652 | } 653 | }); 654 | AST_PropAccess = DEFNODE("PropAccess", "expression property", { 655 | $documentation: "Base class for property access expressions, i.e. `a.foo` or `a[\"foo\"]`", 656 | $propdoc: { 657 | expression: "[AST_Node] the “container” expression", 658 | property: "[AST_Node|string] the property to access. For AST_Dot this is always a plain string, while for AST_Sub it's an arbitrary AST_Node" 659 | } 660 | }); 661 | AST_Dot = DEFNODE("Dot", null, { 662 | $documentation: "A dotted property access expression", 663 | _walk: function(visitor) { 664 | return visitor._visit(this, function() { 665 | this.expression._walk(visitor); 666 | }); 667 | } 668 | }, AST_PropAccess); 669 | AST_Sub = DEFNODE("Sub", null, { 670 | $documentation: "Index-style property access, i.e. `a[\"foo\"]`", 671 | _walk: function(visitor) { 672 | return visitor._visit(this, function() { 673 | this.expression._walk(visitor); 674 | this.property._walk(visitor); 675 | }); 676 | } 677 | }, AST_PropAccess); 678 | AST_Splice = DEFNODE("Slice", "property2 assignment", { 679 | $documentation: "Index-style property access, i.e. `a[3:5]`", 680 | $propdoc: { 681 | property2: "[AST_Node] the 2nd property to access - typically ending index for the array.", 682 | assignment: "[AST_Node] The data being spliced in." 683 | }, 684 | _walk: function(visitor) { 685 | return visitor._visit(this, function() { 686 | this.expression._walk(visitor); 687 | this.property._walk(visitor); 688 | this.property2._walk(visitor); 689 | }); 690 | } 691 | }, AST_PropAccess); 692 | AST_Unary = DEFNODE("Unary", "operator expression", { 693 | $documentation: "Base class for unary expressions", 694 | $propdoc: { 695 | operator: "[string] the operator", 696 | expression: "[AST_Node] expression that this unary operator applies to" 697 | }, 698 | _walk: function(visitor) { 699 | return visitor._visit(this, function() { 700 | this.expression._walk(visitor); 701 | }); 702 | } 703 | }); 704 | AST_UnaryPrefix = DEFNODE("UnaryPrefix", null, { 705 | $documentation: "Unary prefix expression, i.e. `typeof i` or `++i`" 706 | }, AST_Unary); 707 | AST_UnaryPostfix = DEFNODE("UnaryPostfix", null, { 708 | $documentation: "Unary postfix expression, i.e. `i++`" 709 | }, AST_Unary); 710 | AST_Binary = DEFNODE("Binary", "left operator right", { 711 | $documentation: "Binary expression, i.e. `a + b`", 712 | $propdoc: { 713 | left: "[AST_Node] left-hand side expression", 714 | operator: "[string] the operator", 715 | right: "[AST_Node] right-hand side expression" 716 | }, 717 | _walk: function(visitor) { 718 | return visitor._visit(this, function() { 719 | this.left._walk(visitor); 720 | this.right._walk(visitor); 721 | }); 722 | } 723 | }); 724 | AST_Conditional = DEFNODE("Conditional", "condition consequent alternative", { 725 | $documentation: "Conditional expression using the ternary operator, i.e. `a ? b : c`", 726 | $propdoc: { 727 | condition: "[AST_Node]", 728 | consequent: "[AST_Node]", 729 | alternative: "[AST_Node]" 730 | }, 731 | _walk: function(visitor) { 732 | return visitor._visit(this, function() { 733 | this.condition._walk(visitor); 734 | this.consequent._walk(visitor); 735 | this.alternative._walk(visitor); 736 | }); 737 | } 738 | }); 739 | AST_Assign = DEFNODE("Assign", null, { 740 | $documentation: "An assignment expression — `a = b + 5`" 741 | }, AST_Binary); 742 | AST_Array = DEFNODE("Array", "elements", { 743 | $documentation: "An array literal", 744 | $propdoc: { 745 | elements: "[AST_Node*] array of elements" 746 | }, 747 | _walk: function(visitor) { 748 | return visitor._visit(this, function() { 749 | this.elements.forEach(function(el) { 750 | el._walk(visitor); 751 | }); 752 | }); 753 | } 754 | }); 755 | AST_TupleUnpack = DEFNODE("TupleUnpack", "elements right", { 756 | $documentation: "An object used to represent tuple unpacking", 757 | $propdoc: { 758 | elements: "[AST_Node*] array of elements being assigned to", 759 | right: "[AST_Node] right-hand side expression" 760 | }, 761 | _walk: function(visitor) { 762 | return visitor._visit(this, function() { 763 | this.elements.forEach(function(el) { 764 | el._walk(visitor); 765 | }); 766 | this.right._walk(visitor); 767 | }); 768 | } 769 | }); 770 | AST_Object = DEFNODE("Object", "properties", { 771 | $documentation: "An object literal", 772 | $propdoc: { 773 | properties: "[AST_ObjectProperty*] array of properties" 774 | }, 775 | _walk: function(visitor) { 776 | return visitor._visit(this, function() { 777 | this.properties.forEach(function(prop) { 778 | prop._walk(visitor); 779 | }); 780 | }); 781 | } 782 | }); 783 | AST_ObjectProperty = DEFNODE("ObjectProperty", "key value quoted", { 784 | $documentation: "Base class for literal object properties", 785 | $propdoc: { 786 | key: "[string] the property name; it's always a plain string in our AST, no matter if it was a string, number or identifier in original code", 787 | value: "[AST_Node] property value. For setters and getters this is an AST_Function.", 788 | quoted: "[true/false] keeps track whether the property was quoted in original code." 789 | }, 790 | _walk: function(visitor) { 791 | return visitor._visit(this, function() { 792 | this.value._walk(visitor); 793 | }); 794 | } 795 | }); 796 | AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", null, { 797 | $documentation: "A key: value object property" 798 | }, AST_ObjectProperty); 799 | AST_ObjectSetter = DEFNODE("ObjectSetter", null, { 800 | $documentation: "An object setter property" 801 | }, AST_ObjectProperty); 802 | AST_ObjectGetter = DEFNODE("ObjectGetter", null, { 803 | $documentation: "An object getter property" 804 | }, AST_ObjectProperty); 805 | AST_Symbol = DEFNODE("Symbol", "scope name thedef", { 806 | $propdoc: { 807 | name: "[string] name of this symbol", 808 | scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)", 809 | thedef: "[SymbolDef/S] the definition of this symbol" 810 | }, 811 | $documentation: "Base class for all symbols" 812 | }); 813 | AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, { 814 | $documentation: "The name of a property accessor (setter/getter function)" 815 | }, AST_Symbol); 816 | AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", { 817 | $documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)", 818 | $propdoc: { 819 | init: "[AST_Node*/S] array of initializers for this declaration." 820 | } 821 | }, AST_Symbol); 822 | AST_SymbolVar = DEFNODE("SymbolVar", null, { 823 | $documentation: "Symbol defining a variable" 824 | }, AST_SymbolDeclaration); 825 | AST_SymbolConst = DEFNODE("SymbolConst", null, { 826 | $documentation: "A constant declaration" 827 | }, AST_SymbolDeclaration); 828 | AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, { 829 | $documentation: "Symbol naming a function argument" 830 | }, AST_SymbolVar); 831 | AST_SymbolDefun = DEFNODE("SymbolDefun", null, { 832 | $documentation: "Symbol defining a function" 833 | }, AST_SymbolDeclaration); 834 | AST_SymbolLambda = DEFNODE("SymbolLambda", null, { 835 | $documentation: "Symbol naming a function expression" 836 | }, AST_SymbolDeclaration); 837 | AST_SymbolCatch = DEFNODE("SymbolCatch", null, { 838 | $documentation: "Symbol naming the exception in catch" 839 | }, AST_SymbolDeclaration); 840 | AST_Label = DEFNODE("Label", "references", { 841 | $documentation: "Symbol naming a label (declaration)", 842 | $propdoc: { 843 | references: "[AST_LabelRef*] a list of nodes referring to this label" 844 | } 845 | }, AST_Symbol); 846 | AST_SymbolRef = DEFNODE("SymbolRef", "parens", { 847 | $documentation: "Reference to some symbol (not definition/declaration)", 848 | $propdoc: { 849 | parens: "[boolean/S] if true, this variable is wrapped in parentheses" 850 | } 851 | }, AST_Symbol); 852 | AST_LabelRef = DEFNODE("LabelRef", null, { 853 | $documentation: "Reference to a label symbol" 854 | }, AST_Symbol); 855 | AST_This = DEFNODE("This", null, { 856 | $documentation: "The `this` symbol" 857 | }, AST_Symbol); 858 | AST_Constant = DEFNODE("Constant", null, { 859 | $documentation: "Base class for all constants", 860 | getValue: function() { 861 | return this.value; 862 | } 863 | }); 864 | AST_String = DEFNODE("String", "value", { 865 | $documentation: "A string literal", 866 | $propdoc: { 867 | value: "[string] the contents of this string" 868 | } 869 | }, AST_Constant); 870 | AST_Verbatim = DEFNODE("Verbatim", "value", { 871 | $documentation: "Raw JavaScript code", 872 | $propdoc: { 873 | value: "[string] A string of raw JS code" 874 | } 875 | }, AST_Constant); 876 | AST_Number = DEFNODE("Number", "value", { 877 | $documentation: "A number literal", 878 | $propdoc: { 879 | value: "[number] the numeric value" 880 | } 881 | }, AST_Constant); 882 | AST_RegExp = DEFNODE("RegExp", "value", { 883 | $documentation: "A regexp literal", 884 | $propdoc: { 885 | value: "[RegExp] the actual regexp" 886 | } 887 | }, AST_Constant); 888 | AST_Atom = DEFNODE("Atom", null, { 889 | $documentation: "Base class for atoms" 890 | }, AST_Constant); 891 | AST_Null = DEFNODE("Null", null, { 892 | $documentation: "The `null` atom", 893 | value: null 894 | }, AST_Atom); 895 | AST_NaN = DEFNODE("NaN", null, { 896 | $documentation: "The impossible value", 897 | value: 0 / 0 898 | }, AST_Atom); 899 | AST_Undefined = DEFNODE("Undefined", null, { 900 | $documentation: "The `undefined` value", 901 | value: function() { 902 | }.call(this) 903 | }, AST_Atom); 904 | AST_Hole = DEFNODE("Hole", null, { 905 | $documentation: "A hole in an array", 906 | value: function() { 907 | }.call(this) 908 | }, AST_Atom); 909 | AST_Infinity = DEFNODE("Infinity", null, { 910 | $documentation: "The `Infinity` value", 911 | value: 1 / 0 912 | }, AST_Atom); 913 | AST_Boolean = DEFNODE("Boolean", null, { 914 | $documentation: "Base class for booleans" 915 | }, AST_Atom); 916 | AST_False = DEFNODE("False", null, { 917 | $documentation: "The `false` atom", 918 | value: false 919 | }, AST_Boolean); 920 | AST_True = DEFNODE("True", null, { 921 | $documentation: "The `true` atom", 922 | value: true 923 | }, AST_Boolean); 924 | function TreeWalker(callback) { 925 | this.visit = callback; 926 | this.stack = []; 927 | } 928 | TreeWalker.prototype = { 929 | _visit: function(node, descend) { 930 | var ret; 931 | this.stack.push(node); 932 | ret = this.visit(node, descend ? function() { 933 | descend.call(node); 934 | } : noop); 935 | if (!ret && descend) { 936 | descend.call(node); 937 | } 938 | this.stack.pop(); 939 | return ret; 940 | }, 941 | parent: function(n) { 942 | return this.stack[this.stack.length - 2 - (n || 0)]; 943 | }, 944 | push: function(node) { 945 | this.stack.push(node); 946 | }, 947 | pop: function() { 948 | return this.stack.pop(); 949 | }, 950 | self: function() { 951 | return this.stack[this.stack.length - 1]; 952 | }, 953 | find_parent: function(type) { 954 | var stack, x, i; 955 | stack = this.stack; 956 | for (i = stack.length - 1; i > -1; i-=1) { 957 | x = stack[i]; 958 | if (x instanceof type) { 959 | return x; 960 | } 961 | } 962 | }, 963 | in_boolean_context: function() { 964 | var stack, i, p, self; 965 | stack = this.stack; 966 | i = stack.length; 967 | self = stack[i -= 1]; 968 | while (i > 0) { 969 | p = stack[i -= 1]; 970 | if (p instanceof AST_If && p.condition === self || p instanceof AST_Conditional && p.condition === self || p instanceof AST_DWLoop && p.condition === self || p instanceof AST_UnaryPrefix && p.operator === "!" && p.expression === self) { 971 | return true; 972 | } 973 | if (!(p instanceof AST_Binary && (p.operator === "&&" || p.operator === "||"))) { 974 | return false; 975 | } 976 | self = p; 977 | } 978 | }, 979 | loopcontrol_target: function(label) { 980 | var stack, x, i; 981 | stack = this.stack; 982 | if (label) { 983 | for (i = stack.length - 1; i > -1; i-=1) { 984 | x = stack[i]; 985 | if (x instanceof AST_LabeledStatement && x.label.name === label.name) { 986 | return x.body; 987 | } 988 | } 989 | } else { 990 | for (i = stack.length - 1; i > -1; i-=1) { 991 | x = stack[i]; 992 | if (x instanceof AST_Switch || x instanceof AST_ForIn || x instanceof AST_DWLoop) { 993 | return x; 994 | } 995 | } 996 | } 997 | } 998 | }; -------------------------------------------------------------------------------- /ReactJS Example/static/rapydscript/0.3.6/lib/baselib.js: -------------------------------------------------------------------------------- 1 | function abs(n) { 2 | return Math.abs(n); 3 | } 4 | 5 | function _$rapyd$_bind(fn, thisArg) { 6 | var ret; 7 | if (fn.orig) { 8 | fn = fn.orig; 9 | } 10 | if (thisArg === false) { 11 | return fn; 12 | } 13 | ret = function() { 14 | return fn.apply(thisArg, arguments); 15 | }; 16 | ret.orig = fn; 17 | return ret; 18 | } 19 | 20 | function _$rapyd$_rebindAll(thisArg, rebind) { 21 | if (typeof rebind === "undefined") { 22 | rebind = true; 23 | } 24 | for (var p in thisArg) { 25 | if (thisArg[p] && thisArg[p].orig) { 26 | if (rebind) { 27 | thisArg[p] = _$rapyd$_bind(thisArg[p], thisArg); 28 | } else { 29 | thisArg[p] = thisArg[p].orig; 30 | } 31 | } 32 | } 33 | } 34 | 35 | function dir(item) { 36 | var arr; 37 | arr = []; 38 | for (var i in item) { 39 | arr.push(i); 40 | } 41 | return arr; 42 | } 43 | 44 | function enumerate(item) { 45 | var arr; 46 | arr = []; 47 | for (var i=0;i\n http://www.pyjeon.com\n\n Distributed under Apache 2.0 license:\n Copyright 2013 (c) Alexander Tsepkov \n\n RapydScript source code is originally based on UglifyJS2 (covered\n by BSD license). UglifyJS2 was written by Mihai Bazon\n , who is its respective copyright holder.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions\n are met:\n\n * Redistributions of source code must retain the above\n copyright notice, this list of conditions and the following\n disclaimer.\n\n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials\n provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY\n EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE\n LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\n TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\n THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n SUCH DAMAGE.\n\n **********************************************************************\n"; 3 | "use strict"; 4 | function array_to_hash(a) { 5 | var ret, i; 6 | ret = Object.create(null); 7 | for (i = 0; i < len(a); i++) { 8 | ret[a[i]] = true; 9 | } 10 | return ret; 11 | } 12 | function slice(a, start) { 13 | return Array.prototype.slice.call(a, start || 0); 14 | } 15 | function characters(str_) { 16 | return str_.split(""); 17 | } 18 | function member(name, array) { 19 | var i; 20 | for (i = array.length - 1; i > -1; i-=1) { 21 | if (array[i] === name) { 22 | return true; 23 | } 24 | } 25 | return false; 26 | } 27 | function find_if(func, array) { 28 | var i; 29 | for (i = 0; i < len(array); i++) { 30 | if (func(array[i])) { 31 | return array[i]; 32 | } 33 | } 34 | } 35 | function repeat_string(str_, i) { 36 | var d; 37 | if (i <= 0) { 38 | return ""; 39 | } 40 | if (i === 1) { 41 | return str_; 42 | } 43 | d = repeat_string(str_, i >> 1); 44 | d += d; 45 | if (i & 1) { 46 | d += str_; 47 | } 48 | return d; 49 | } 50 | function DefaultsError(msg, defs) { 51 | this.msg = msg; 52 | this.defs = defs; 53 | } 54 | function defaults(args, defs, croak) { 55 | var ret, i; 56 | if (args === true) { 57 | args = {}; 58 | } 59 | ret = args || {}; 60 | if (croak) { 61 | for (i in ret) { 62 | if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i)) { 63 | throw new DefaultsError("`" + i + "` is not a supported option", defs); 64 | } 65 | } 66 | } 67 | for (i in defs) { 68 | if (defs.hasOwnProperty(i)) { 69 | ret[i] = args && args.hasOwnProperty(i) ? args[i] : defs[i]; 70 | } 71 | } 72 | return ret; 73 | } 74 | function merge(obj, ext) { 75 | var i; 76 | for (i in ext) { 77 | if (ext.hasOwnProperty(i)) { 78 | obj[i] = ext[i]; 79 | } 80 | } 81 | return obj; 82 | } 83 | function noop() { 84 | } 85 | MAP = function() { 86 | var skip; 87 | function MAP(a, f, backwards) { 88 | var ret, top, i; 89 | ret = []; 90 | top = []; 91 | function doit() { 92 | var is_last, val; 93 | val = f(a[i], i); 94 | is_last = val instanceof Last; 95 | if (is_last) { 96 | val = val.v; 97 | } 98 | if (val instanceof AtTop) { 99 | val = val.v; 100 | if (val instanceof Splice) { 101 | top.push.apply(top, backwards ? val.v.slice().reverse() : val.v); 102 | } else { 103 | top.push(val); 104 | } 105 | } else if (val !== skip) { 106 | if (val instanceof Splice) { 107 | ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v); 108 | } else { 109 | ret.push(val); 110 | } 111 | } 112 | return is_last; 113 | } 114 | if (Array.isArray(a)) { 115 | if (backwards) { 116 | for (i = a.length - 1; i > -1; i-=1) { 117 | if (doit()) { 118 | break; 119 | } 120 | } 121 | ret.reverse(); 122 | top.reverse(); 123 | } else { 124 | for (i = 0; i < len(a); i++) { 125 | if (doit()) { 126 | break; 127 | } 128 | } 129 | } 130 | } else { 131 | for (i in a) { 132 | if (a.hasOwnProperty(i)) { 133 | if (doit()) { 134 | break; 135 | } 136 | } 137 | } 138 | } 139 | return top.concat(ret); 140 | } 141 | MAP.at_top = function(val) { 142 | return new AtTop(val); 143 | }; 144 | MAP.splice = function(val) { 145 | return new Splice(val); 146 | }; 147 | MAP.last = function(val) { 148 | return new Last(val); 149 | }; 150 | skip = MAP.skip = {}; 151 | function AtTop(val) { 152 | this.v = val; 153 | } 154 | function Splice(val) { 155 | this.v = val; 156 | } 157 | function Last(val) { 158 | this.v = val; 159 | } 160 | return MAP; 161 | }.call(this); 162 | function push_uniq(array, el) { 163 | if (array.indexOf(el) < 0) { 164 | array.push(el); 165 | } 166 | } 167 | function string_template(text, props) { 168 | return text.replace(/\{(.+?)\}/g, function(str_, p) { 169 | return props[p]; 170 | }); 171 | } 172 | function remove(array, el) { 173 | var i; 174 | for (i = array.length - 1; i > -1; i-=1) { 175 | if (array[i] === el) { 176 | array.splice(i, 1); 177 | } 178 | } 179 | } 180 | function mergeSort(array, cmp) { 181 | if (array.length < 2) { 182 | return array.slice(); 183 | } 184 | function merge(a, b) { 185 | var r, ai, bi, i; 186 | r = []; 187 | ai = 0; 188 | bi = 0; 189 | i = 0; 190 | while (ai < a.length && bi < b.length) { 191 | if (cmp(a[ai], b[bi]) <= 0) { 192 | r[i] = a[ai]; 193 | ai += 1; 194 | } else { 195 | r[i] = b[bi]; 196 | bi += 1; 197 | } 198 | i += 1; 199 | } 200 | if (ai < a.length) { 201 | r.push.apply(r, a.slice(ai)); 202 | } 203 | if (bi < b.length) { 204 | r.push.apply(r, b.slice(bi)); 205 | } 206 | return r; 207 | } 208 | function _ms(a) { 209 | var m, left, right; 210 | if (a.length <= 1) { 211 | return a; 212 | } 213 | m = Math.floor(a.length / 2); 214 | left = a.slice(0, m); 215 | right = a.slice(m); 216 | left = _ms(left); 217 | right = _ms(right); 218 | return merge(left, right); 219 | } 220 | return _ms(array); 221 | } 222 | function set_difference(a, b) { 223 | return a.filter(function(el) { 224 | return b.indexOf(el) < 0; 225 | }); 226 | } 227 | function set_intersection(a, b) { 228 | return a.filter(function(el) { 229 | return b.indexOf(el) >= 0; 230 | }); 231 | } 232 | function makePredicate(words) { 233 | var cats, skip, j, cat, i, f; 234 | if (!Array.isArray(words)) { 235 | words = words.split(" "); 236 | } 237 | f = ""; 238 | cats = []; 239 | for (i = 0; i < len(words); i++) { 240 | skip = false; 241 | for (j = 0; j < len(cats); j++) { 242 | if (cats[j][0].length === words[i].length) { 243 | cats[j].push(words[i]); 244 | skip = true; 245 | break; 246 | } 247 | } 248 | if (!skip) { 249 | cats.push([ words[i] ]); 250 | } 251 | } 252 | function compareTo(arr) { 253 | var i; 254 | if (arr.length === 1) { 255 | return f += "return str === " + JSON.stringify(arr[0]) + ";"; 256 | } 257 | f += "switch(str){"; 258 | for (i = 0; i < len(arr); i++) { 259 | f += "case " + JSON.stringify(arr[i]) + ":"; 260 | } 261 | f += "return true}return false;"; 262 | } 263 | if (cats.length > 3) { 264 | cats.sort(function(a, b) { 265 | return b.length - a.length; 266 | }); 267 | f += "switch(str.length){"; 268 | for (i = 0; i < len(cats); i++) { 269 | cat = cats[i]; 270 | f += "case " + cat[0].length + ":"; 271 | compareTo(cat); 272 | } 273 | f += "}"; 274 | } else { 275 | compareTo(words); 276 | } 277 | return new Function("str", f); 278 | } 279 | function Dictionary() { 280 | this._values = Object.create(null); 281 | this._size = 0; 282 | } 283 | Dictionary.prototype = { 284 | set: function(key, val) { 285 | if (!this.has(key)) { 286 | this._size += 1; 287 | } 288 | this._values["$" + key] = val; 289 | return this; 290 | }, 291 | add: function(key, val) { 292 | if (this.has(key)) { 293 | this.get(key).push(val); 294 | } else { 295 | this.set(key, [ val ]); 296 | } 297 | return this; 298 | }, 299 | get: function(key) { 300 | return this._values["$" + key]; 301 | }, 302 | del_: function(key) { 303 | if (this.has(key)) { 304 | this._size -= 1; 305 | delete this._values["$" + key]; 306 | } 307 | return this; 308 | }, 309 | has: function(key) { 310 | return _$rapyd$_in("$" + key, this._values); 311 | }, 312 | each: function(f) { 313 | var i; 314 | for (i in this._values) { 315 | f(this._values[i], i.substr(1)); 316 | } 317 | }, 318 | size: function() { 319 | return this._size; 320 | }, 321 | map: function(f) { 322 | var ret, i; 323 | ret = []; 324 | for (i in this._values) { 325 | ret.push(f(this._values[i], i.substr(1))); 326 | } 327 | return ret; 328 | } 329 | }; -------------------------------------------------------------------------------- /ReactJS Example/static/rapydscript/0.3.6/stdlib.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var _$rapyd$_Temp; 3 | function range(start, stop, step) { 4 | var length, idx, range; 5 | if (arguments.length <= 1) { 6 | stop = start || 0; 7 | start = 0; 8 | } 9 | step = arguments[2] || 1; 10 | length = Math.max(Math.ceil((stop - start) / step), 0); 11 | idx = 0; 12 | range = new Array(length); 13 | while (idx < length) { 14 | range[idx++] = start; 15 | start += step; 16 | } 17 | return range; 18 | } 19 | function _$rapyd$_Iterable(iterable) { 20 | if (iterable instanceof Array || iterable instanceof String || typeof iterable === "string") { 21 | return iterable; 22 | } 23 | return Object.keys(iterable); 24 | } 25 | function _$rapyd$_in(val, arr) { 26 | if (arr instanceof Array || typeof arr === "string") { 27 | return arr.indexOf(val) !== -1; 28 | } else { 29 | if (arr.hasOwnProperty(val)) { 30 | return true; 31 | } 32 | return false; 33 | } 34 | } 35 | function dir(item) { 36 | var arr; 37 | arr = []; 38 | for (var i in item) { 39 | arr.push(i); 40 | } 41 | return arr; 42 | } 43 | function _$rapyd$_extends(child, parent) { 44 | child.prototype = Object.create(parent.prototype); 45 | child.prototype.constructor = child; 46 | } 47 | var str; 48 | str = JSON.stringify; 49 | function kwargs(f) { 50 | var argNames; 51 | argNames = f.toString().match(/\(([^\)]+)/)[1]; 52 | argNames = argNames ? argNames.split(",").map(function(s) { 53 | return s.trim(); 54 | }) : []; 55 | return function() { 56 | var args, kw, i; 57 | args = [].slice.call(arguments); 58 | if (args.length) { 59 | kw = args.pop(); 60 | if (typeof kw === "object") { 61 | for (i = 0; i < argNames.length; i++) { 62 | if (_$rapyd$_in(argNames[i], dir(kw))) { 63 | args[i] = kw[argNames[i]]; 64 | } 65 | } 66 | } else { 67 | args.push(kw); 68 | } 69 | } 70 | return f.apply(this, args); 71 | }; 72 | } 73 | function IndexError() { 74 | IndexError.prototype.__init__.apply(this, arguments); 75 | } 76 | _$rapyd$_extends(IndexError, Error); 77 | IndexError.prototype.__init__ = function __init__(message){ 78 | var self = this; 79 | if (typeof message === "undefined") message = "list index out of range"; 80 | self.name = "IndexError"; 81 | self.message = message; 82 | }; 83 | 84 | function TypeError() { 85 | TypeError.prototype.__init__.apply(this, arguments); 86 | } 87 | _$rapyd$_extends(TypeError, Error); 88 | TypeError.prototype.__init__ = function __init__(message){ 89 | var self = this; 90 | self.name = "TypeError"; 91 | self.message = message; 92 | }; 93 | 94 | function ValueError() { 95 | ValueError.prototype.__init__.apply(this, arguments); 96 | } 97 | _$rapyd$_extends(ValueError, Error); 98 | ValueError.prototype.__init__ = function __init__(message){ 99 | var self = this; 100 | self.name = "ValueError"; 101 | self.message = message; 102 | }; 103 | 104 | function AssertionError() { 105 | AssertionError.prototype.__init__.apply(this, arguments); 106 | } 107 | _$rapyd$_extends(AssertionError, Error); 108 | AssertionError.prototype.__init__ = function __init__(message){ 109 | var self = this; 110 | if (typeof message === "undefined") message = ""; 111 | self.name = "AssertionError"; 112 | self.message = message; 113 | }; 114 | 115 | function map(oper, arr) { 116 | return list(arr.map(oper)); 117 | } 118 | function filter(oper, arr) { 119 | return list(arr.filter(oper)); 120 | } 121 | function sum(arr, start) { 122 | if (typeof start === "undefined") start = 0; 123 | return arr.reduce(function(prev, cur) { 124 | return prev + cur; 125 | }, start); 126 | } 127 | function deep_eq(a, b) { 128 | var i; 129 | "\n Equality comparison that works with all data types, returns true if structure and\n contents of first object equal to those of second object\n\n Arguments:\n a: first object\n b: second object\n "; 130 | if (a === b) { 131 | return true; 132 | } 133 | if (a instanceof Array && b instanceof Array || a instanceof Object && b instanceof Object) { 134 | if (a.constructor !== b.constructor || a.length !== b.length) { 135 | return false; 136 | } 137 | var _$rapyd$_Iter0 = _$rapyd$_Iterable(dict.keys(a)); 138 | for (var _$rapyd$_Index0 = 0; _$rapyd$_Index0 < _$rapyd$_Iter0.length; _$rapyd$_Index0++) { 139 | i = _$rapyd$_Iter0[_$rapyd$_Index0]; 140 | if (b.hasOwnProperty(i)) { 141 | if (!deep_eq(a[i], b[i])) { 142 | return false; 143 | } 144 | } else { 145 | return false; 146 | } 147 | } 148 | return true; 149 | } 150 | return false; 151 | } 152 | String.prototype.find = String.prototype.indexOf; 153 | String.prototype.strip = String.prototype.trim; 154 | String.prototype.lstrip = String.prototype.trimLeft; 155 | String.prototype.rstrip = String.prototype.trimRight; 156 | String.prototype.join = function(iterable) { 157 | return iterable.join(this); 158 | }; 159 | String.prototype.zfill = function(size) { 160 | var s; 161 | s = this; 162 | while (s.length < size) { 163 | s = "0" + s; 164 | } 165 | return s; 166 | }; 167 | function list(iterable) { 168 | if (typeof iterable === "undefined") iterable = []; 169 | var result, i; 170 | result = []; 171 | var _$rapyd$_Iter1 = _$rapyd$_Iterable(iterable); 172 | for (var _$rapyd$_Index1 = 0; _$rapyd$_Index1 < _$rapyd$_Iter1.length; _$rapyd$_Index1++) { 173 | i = _$rapyd$_Iter1[_$rapyd$_Index1]; 174 | result.append(i); 175 | } 176 | return result; 177 | } 178 | Array.prototype.append = Array.prototype.push; 179 | Array.prototype.find = Array.prototype.indexOf; 180 | Array.prototype.index = function(index) { 181 | var val; 182 | val = this.find(index); 183 | if (val === -1) { 184 | throw new ValueError(str(index) + " is not in list"); 185 | } 186 | return val; 187 | }; 188 | Array.prototype.insert = function(index, item) { 189 | this.splice(index, 0, item); 190 | }; 191 | Array.prototype.pop = function(index) { 192 | if (typeof index === "undefined") index = this.length - 1; 193 | return this.splice(index, 1)[0]; 194 | }; 195 | Array.prototype.extend = function(array2) { 196 | this.push.apply(this, array2); 197 | }; 198 | Array.prototype.remove = function(item) { 199 | var index; 200 | index = this.find(item); 201 | this.splice(index, 1); 202 | }; 203 | Array.prototype.copy = function() { 204 | return this.slice(0); 205 | }; 206 | function dict(iterable) { 207 | var result, key; 208 | result = {}; 209 | var _$rapyd$_Iter2 = _$rapyd$_Iterable(iterable); 210 | for (var _$rapyd$_Index2 = 0; _$rapyd$_Index2 < _$rapyd$_Iter2.length; _$rapyd$_Index2++) { 211 | key = _$rapyd$_Iter2[_$rapyd$_Index2]; 212 | result[key] = iterable[key]; 213 | } 214 | return result; 215 | } 216 | if (typeof Object.getOwnPropertyNames !== "function") { 217 | dict.keys = function(hash) { 218 | var keys; 219 | keys = []; 220 | 221 | for (var x in hash) { 222 | if (hash.hasOwnProperty(x)) { 223 | keys.push(x); 224 | } 225 | } 226 | ; 227 | return keys; 228 | }; 229 | } else { 230 | dict.keys = function(hash) { 231 | return Object.getOwnPropertyNames(hash); 232 | }; 233 | } 234 | dict.values = function(hash) { 235 | var vals, key; 236 | vals = []; 237 | var _$rapyd$_Iter3 = _$rapyd$_Iterable(dict.keys(hash)); 238 | for (var _$rapyd$_Index3 = 0; _$rapyd$_Index3 < _$rapyd$_Iter3.length; _$rapyd$_Index3++) { 239 | key = _$rapyd$_Iter3[_$rapyd$_Index3]; 240 | vals.append(hash[key]); 241 | } 242 | return vals; 243 | }; 244 | dict.items = function(hash) { 245 | var items, key; 246 | items = []; 247 | var _$rapyd$_Iter4 = _$rapyd$_Iterable(dict.keys(hash)); 248 | for (var _$rapyd$_Index4 = 0; _$rapyd$_Index4 < _$rapyd$_Iter4.length; _$rapyd$_Index4++) { 249 | key = _$rapyd$_Iter4[_$rapyd$_Index4]; 250 | items.append([key, hash[key]]); 251 | } 252 | return items; 253 | }; 254 | dict.copy = dict; 255 | dict.clear = function(hash) { 256 | var key; 257 | var _$rapyd$_Iter5 = _$rapyd$_Iterable(dict.keys(hash)); 258 | for (var _$rapyd$_Index5 = 0; _$rapyd$_Index5 < _$rapyd$_Iter5.length; _$rapyd$_Index5++) { 259 | key = _$rapyd$_Iter5[_$rapyd$_Index5]; 260 | delete hash[key]; 261 | } 262 | }; 263 | -------------------------------------------------------------------------------- /ReactJS Example/static/rapydscript/pyjTransformer.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 3 | /** 4 | * Actually transform the code. 5 | * 6 | * @param {string} code 7 | * @param {string?} url 8 | * @param {object?} options 9 | * @return {string} The transformed code. 10 | * @internal 11 | */ 12 | function transformCode(code, url, options) { 13 | //RapydScript options 14 | var rs_options = { 15 | "filename":"demo", 16 | "toplevel":null, 17 | "basedir": null, 18 | "libdir": null 19 | }; 20 | var output_opts = { 21 | "beautify":true, 22 | "private_scope":false, 23 | "omit_baselib":true, 24 | "comments" : true 25 | }; 26 | 27 | var rapydscript_string = code; 28 | output = OutputStream(output_opts) 29 | rapydscript_string += '\n'; //just to be safe 30 | 31 | try { 32 | TOPLEVEL = parse(rapydscript_string, rs_options); 33 | TOPLEVEL.print(output); 34 | //(new Function(String(output) + '\n'))(); 35 | var js_code = String(output) + '\n' 36 | js_code = js_code.replace('var __name__ = "__main__";', ''); 37 | return js_code 38 | 39 | } catch(err) { 40 | console.log("ERROR: " + err.message + ". Line " + err.line + ", column " + err.col + "."); 41 | } 42 | } 43 | 44 | /** 45 | * Appends a script element at the end of the with the content of code, 46 | * after transforming it. 47 | * 48 | * @param {string} code The original source code 49 | * @param {string?} url Where the code came from. null if inline 50 | * @param {object?} options Options to pass to jstransform 51 | * @internal 52 | */ 53 | function run(code, url, options) { 54 | var scriptEl = document.createElement('script'); 55 | scriptEl.text = transformCode(code, url, options); 56 | if (options.otype) { 57 | scriptEl.type = options.otype 58 | } 59 | headEl.appendChild(scriptEl); 60 | } 61 | 62 | /** 63 | * Load script from the provided url and pass the content to the callback. 64 | * 65 | * @param {string} script The script 66 | * @param {function} callback Function to call with the content of url 67 | * @internal 68 | */ 69 | function load(script, successCallback, errorCallback) { 70 | var xhr; 71 | xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') 72 | : new XMLHttpRequest(); 73 | 74 | // async, however scripts will be executed in the order they are in the 75 | // DOM to mirror normal script loading. 76 | xhr.open('GET', 77 | script.src, 78 | script.options.async 79 | ); 80 | if ('overrideMimeType' in xhr) { 81 | xhr.overrideMimeType('text/plain'); 82 | } 83 | xhr.onreadystatechange = function() { 84 | if (xhr.readyState === 4) { 85 | if (xhr.status === 0 || xhr.status === 200) { 86 | successCallback(xhr.responseText); 87 | } else { 88 | errorCallback(); 89 | throw new Error("Could not load " + script.src); 90 | } 91 | } 92 | }; 93 | return xhr.send(null); 94 | } 95 | 96 | /** 97 | * Loop over provided script tags and get the content, via innerHTML if an 98 | * inline script, or by using XHR. Transforms are applied if needed. The scripts 99 | * are executed in the order they are found on the page. 100 | * 101 | * @param {array} scripts The 8 | 9 | 10 | 31 | 32 | 33 | 34 |
35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /jQuery Example/static/rapydscript/0.3.6/fis-conf.js: -------------------------------------------------------------------------------- 1 | //use baidu fis3 to compress .js files 2 | // 3 | fis.set('project.ignore',[ 4 | '*.js', //bourbon 5 | 'output/**' 6 | ]); 7 | 8 | fis.match('lib/*.js', { 9 | deploy: fis.plugin('local-deliver', { 10 | to: 'output/' 11 | }), 12 | packTo: 'rapydscript.min.js', 13 | }); 14 | 15 | fis.match('lib/*.js', { 16 | optimizer: fis.plugin('uglify-js'), 17 | useHash: false, 18 | }); 19 | 20 | 21 | -------------------------------------------------------------------------------- /jQuery Example/static/rapydscript/0.3.6/lib/baselib.js: -------------------------------------------------------------------------------- 1 | function abs(n) { 2 | return Math.abs(n); 3 | } 4 | 5 | function _$rapyd$_bind(fn, thisArg) { 6 | var ret; 7 | if (fn.orig) { 8 | fn = fn.orig; 9 | } 10 | if (thisArg === false) { 11 | return fn; 12 | } 13 | ret = function() { 14 | return fn.apply(thisArg, arguments); 15 | }; 16 | ret.orig = fn; 17 | return ret; 18 | } 19 | 20 | function _$rapyd$_rebindAll(thisArg, rebind) { 21 | if (typeof rebind === "undefined") { 22 | rebind = true; 23 | } 24 | for (var p in thisArg) { 25 | if (thisArg[p] && thisArg[p].orig) { 26 | if (rebind) { 27 | thisArg[p] = _$rapyd$_bind(thisArg[p], thisArg); 28 | } else { 29 | thisArg[p] = thisArg[p].orig; 30 | } 31 | } 32 | } 33 | } 34 | 35 | function dir(item) { 36 | var arr; 37 | arr = []; 38 | for (var i in item) { 39 | arr.push(i); 40 | } 41 | return arr; 42 | } 43 | 44 | function enumerate(item) { 45 | var arr; 46 | arr = []; 47 | for (var i=0;i\n http://www.pyjeon.com\n\n Distributed under Apache 2.0 license:\n Copyright 2013 (c) Alexander Tsepkov \n\n RapydScript source code is originally based on UglifyJS2 (covered\n by BSD license). UglifyJS2 was written by Mihai Bazon\n , who is its respective copyright holder.\n\n Redistribution and use in source and binary forms, with or without\n modification, are permitted provided that the following conditions\n are met:\n\n * Redistributions of source code must retain the above\n copyright notice, this list of conditions and the following\n disclaimer.\n\n * Redistributions in binary form must reproduce the above\n copyright notice, this list of conditions and the following\n disclaimer in the documentation and/or other materials\n provided with the distribution.\n\n THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY\n EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE\n LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,\n OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\n PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\n PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR\n TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\n THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n SUCH DAMAGE.\n\n **********************************************************************\n"; 3 | "use strict"; 4 | function array_to_hash(a) { 5 | var ret, i; 6 | ret = Object.create(null); 7 | for (i = 0; i < len(a); i++) { 8 | ret[a[i]] = true; 9 | } 10 | return ret; 11 | } 12 | function slice(a, start) { 13 | return Array.prototype.slice.call(a, start || 0); 14 | } 15 | function characters(str_) { 16 | return str_.split(""); 17 | } 18 | function member(name, array) { 19 | var i; 20 | for (i = array.length - 1; i > -1; i-=1) { 21 | if (array[i] === name) { 22 | return true; 23 | } 24 | } 25 | return false; 26 | } 27 | function find_if(func, array) { 28 | var i; 29 | for (i = 0; i < len(array); i++) { 30 | if (func(array[i])) { 31 | return array[i]; 32 | } 33 | } 34 | } 35 | function repeat_string(str_, i) { 36 | var d; 37 | if (i <= 0) { 38 | return ""; 39 | } 40 | if (i === 1) { 41 | return str_; 42 | } 43 | d = repeat_string(str_, i >> 1); 44 | d += d; 45 | if (i & 1) { 46 | d += str_; 47 | } 48 | return d; 49 | } 50 | function DefaultsError(msg, defs) { 51 | this.msg = msg; 52 | this.defs = defs; 53 | } 54 | function defaults(args, defs, croak) { 55 | var ret, i; 56 | if (args === true) { 57 | args = {}; 58 | } 59 | ret = args || {}; 60 | if (croak) { 61 | for (i in ret) { 62 | if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i)) { 63 | throw new DefaultsError("`" + i + "` is not a supported option", defs); 64 | } 65 | } 66 | } 67 | for (i in defs) { 68 | if (defs.hasOwnProperty(i)) { 69 | ret[i] = args && args.hasOwnProperty(i) ? args[i] : defs[i]; 70 | } 71 | } 72 | return ret; 73 | } 74 | function merge(obj, ext) { 75 | var i; 76 | for (i in ext) { 77 | if (ext.hasOwnProperty(i)) { 78 | obj[i] = ext[i]; 79 | } 80 | } 81 | return obj; 82 | } 83 | function noop() { 84 | } 85 | MAP = function() { 86 | var skip; 87 | function MAP(a, f, backwards) { 88 | var ret, top, i; 89 | ret = []; 90 | top = []; 91 | function doit() { 92 | var is_last, val; 93 | val = f(a[i], i); 94 | is_last = val instanceof Last; 95 | if (is_last) { 96 | val = val.v; 97 | } 98 | if (val instanceof AtTop) { 99 | val = val.v; 100 | if (val instanceof Splice) { 101 | top.push.apply(top, backwards ? val.v.slice().reverse() : val.v); 102 | } else { 103 | top.push(val); 104 | } 105 | } else if (val !== skip) { 106 | if (val instanceof Splice) { 107 | ret.push.apply(ret, backwards ? val.v.slice().reverse() : val.v); 108 | } else { 109 | ret.push(val); 110 | } 111 | } 112 | return is_last; 113 | } 114 | if (Array.isArray(a)) { 115 | if (backwards) { 116 | for (i = a.length - 1; i > -1; i-=1) { 117 | if (doit()) { 118 | break; 119 | } 120 | } 121 | ret.reverse(); 122 | top.reverse(); 123 | } else { 124 | for (i = 0; i < len(a); i++) { 125 | if (doit()) { 126 | break; 127 | } 128 | } 129 | } 130 | } else { 131 | for (i in a) { 132 | if (a.hasOwnProperty(i)) { 133 | if (doit()) { 134 | break; 135 | } 136 | } 137 | } 138 | } 139 | return top.concat(ret); 140 | } 141 | MAP.at_top = function(val) { 142 | return new AtTop(val); 143 | }; 144 | MAP.splice = function(val) { 145 | return new Splice(val); 146 | }; 147 | MAP.last = function(val) { 148 | return new Last(val); 149 | }; 150 | skip = MAP.skip = {}; 151 | function AtTop(val) { 152 | this.v = val; 153 | } 154 | function Splice(val) { 155 | this.v = val; 156 | } 157 | function Last(val) { 158 | this.v = val; 159 | } 160 | return MAP; 161 | }.call(this); 162 | function push_uniq(array, el) { 163 | if (array.indexOf(el) < 0) { 164 | array.push(el); 165 | } 166 | } 167 | function string_template(text, props) { 168 | return text.replace(/\{(.+?)\}/g, function(str_, p) { 169 | return props[p]; 170 | }); 171 | } 172 | function remove(array, el) { 173 | var i; 174 | for (i = array.length - 1; i > -1; i-=1) { 175 | if (array[i] === el) { 176 | array.splice(i, 1); 177 | } 178 | } 179 | } 180 | function mergeSort(array, cmp) { 181 | if (array.length < 2) { 182 | return array.slice(); 183 | } 184 | function merge(a, b) { 185 | var r, ai, bi, i; 186 | r = []; 187 | ai = 0; 188 | bi = 0; 189 | i = 0; 190 | while (ai < a.length && bi < b.length) { 191 | if (cmp(a[ai], b[bi]) <= 0) { 192 | r[i] = a[ai]; 193 | ai += 1; 194 | } else { 195 | r[i] = b[bi]; 196 | bi += 1; 197 | } 198 | i += 1; 199 | } 200 | if (ai < a.length) { 201 | r.push.apply(r, a.slice(ai)); 202 | } 203 | if (bi < b.length) { 204 | r.push.apply(r, b.slice(bi)); 205 | } 206 | return r; 207 | } 208 | function _ms(a) { 209 | var m, left, right; 210 | if (a.length <= 1) { 211 | return a; 212 | } 213 | m = Math.floor(a.length / 2); 214 | left = a.slice(0, m); 215 | right = a.slice(m); 216 | left = _ms(left); 217 | right = _ms(right); 218 | return merge(left, right); 219 | } 220 | return _ms(array); 221 | } 222 | function set_difference(a, b) { 223 | return a.filter(function(el) { 224 | return b.indexOf(el) < 0; 225 | }); 226 | } 227 | function set_intersection(a, b) { 228 | return a.filter(function(el) { 229 | return b.indexOf(el) >= 0; 230 | }); 231 | } 232 | function makePredicate(words) { 233 | var cats, skip, j, cat, i, f; 234 | if (!Array.isArray(words)) { 235 | words = words.split(" "); 236 | } 237 | f = ""; 238 | cats = []; 239 | for (i = 0; i < len(words); i++) { 240 | skip = false; 241 | for (j = 0; j < len(cats); j++) { 242 | if (cats[j][0].length === words[i].length) { 243 | cats[j].push(words[i]); 244 | skip = true; 245 | break; 246 | } 247 | } 248 | if (!skip) { 249 | cats.push([ words[i] ]); 250 | } 251 | } 252 | function compareTo(arr) { 253 | var i; 254 | if (arr.length === 1) { 255 | return f += "return str === " + JSON.stringify(arr[0]) + ";"; 256 | } 257 | f += "switch(str){"; 258 | for (i = 0; i < len(arr); i++) { 259 | f += "case " + JSON.stringify(arr[i]) + ":"; 260 | } 261 | f += "return true}return false;"; 262 | } 263 | if (cats.length > 3) { 264 | cats.sort(function(a, b) { 265 | return b.length - a.length; 266 | }); 267 | f += "switch(str.length){"; 268 | for (i = 0; i < len(cats); i++) { 269 | cat = cats[i]; 270 | f += "case " + cat[0].length + ":"; 271 | compareTo(cat); 272 | } 273 | f += "}"; 274 | } else { 275 | compareTo(words); 276 | } 277 | return new Function("str", f); 278 | } 279 | function Dictionary() { 280 | this._values = Object.create(null); 281 | this._size = 0; 282 | } 283 | Dictionary.prototype = { 284 | set: function(key, val) { 285 | if (!this.has(key)) { 286 | this._size += 1; 287 | } 288 | this._values["$" + key] = val; 289 | return this; 290 | }, 291 | add: function(key, val) { 292 | if (this.has(key)) { 293 | this.get(key).push(val); 294 | } else { 295 | this.set(key, [ val ]); 296 | } 297 | return this; 298 | }, 299 | get: function(key) { 300 | return this._values["$" + key]; 301 | }, 302 | del_: function(key) { 303 | if (this.has(key)) { 304 | this._size -= 1; 305 | delete this._values["$" + key]; 306 | } 307 | return this; 308 | }, 309 | has: function(key) { 310 | return _$rapyd$_in("$" + key, this._values); 311 | }, 312 | each: function(f) { 313 | var i; 314 | for (i in this._values) { 315 | f(this._values[i], i.substr(1)); 316 | } 317 | }, 318 | size: function() { 319 | return this._size; 320 | }, 321 | map: function(f) { 322 | var ret, i; 323 | ret = []; 324 | for (i in this._values) { 325 | ret.push(f(this._values[i], i.substr(1))); 326 | } 327 | return ret; 328 | } 329 | }; -------------------------------------------------------------------------------- /jQuery Example/static/rapydscript/0.3.6/stdlib.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var _$rapyd$_Temp; 3 | function range(start, stop, step) { 4 | var length, idx, range; 5 | if (arguments.length <= 1) { 6 | stop = start || 0; 7 | start = 0; 8 | } 9 | step = arguments[2] || 1; 10 | length = Math.max(Math.ceil((stop - start) / step), 0); 11 | idx = 0; 12 | range = new Array(length); 13 | while (idx < length) { 14 | range[idx++] = start; 15 | start += step; 16 | } 17 | return range; 18 | } 19 | function _$rapyd$_Iterable(iterable) { 20 | if (iterable instanceof Array || iterable instanceof String || typeof iterable === "string") { 21 | return iterable; 22 | } 23 | return Object.keys(iterable); 24 | } 25 | function _$rapyd$_in(val, arr) { 26 | if (arr instanceof Array || typeof arr === "string") { 27 | return arr.indexOf(val) !== -1; 28 | } else { 29 | if (arr.hasOwnProperty(val)) { 30 | return true; 31 | } 32 | return false; 33 | } 34 | } 35 | function dir(item) { 36 | var arr; 37 | arr = []; 38 | for (var i in item) { 39 | arr.push(i); 40 | } 41 | return arr; 42 | } 43 | function _$rapyd$_extends(child, parent) { 44 | child.prototype = Object.create(parent.prototype); 45 | child.prototype.constructor = child; 46 | } 47 | var str; 48 | str = JSON.stringify; 49 | function kwargs(f) { 50 | var argNames; 51 | argNames = f.toString().match(/\(([^\)]+)/)[1]; 52 | argNames = argNames ? argNames.split(",").map(function(s) { 53 | return s.trim(); 54 | }) : []; 55 | return function() { 56 | var args, kw, i; 57 | args = [].slice.call(arguments); 58 | if (args.length) { 59 | kw = args.pop(); 60 | if (typeof kw === "object") { 61 | for (i = 0; i < argNames.length; i++) { 62 | if (_$rapyd$_in(argNames[i], dir(kw))) { 63 | args[i] = kw[argNames[i]]; 64 | } 65 | } 66 | } else { 67 | args.push(kw); 68 | } 69 | } 70 | return f.apply(this, args); 71 | }; 72 | } 73 | function IndexError() { 74 | IndexError.prototype.__init__.apply(this, arguments); 75 | } 76 | _$rapyd$_extends(IndexError, Error); 77 | IndexError.prototype.__init__ = function __init__(message){ 78 | var self = this; 79 | if (typeof message === "undefined") message = "list index out of range"; 80 | self.name = "IndexError"; 81 | self.message = message; 82 | }; 83 | 84 | function TypeError() { 85 | TypeError.prototype.__init__.apply(this, arguments); 86 | } 87 | _$rapyd$_extends(TypeError, Error); 88 | TypeError.prototype.__init__ = function __init__(message){ 89 | var self = this; 90 | self.name = "TypeError"; 91 | self.message = message; 92 | }; 93 | 94 | function ValueError() { 95 | ValueError.prototype.__init__.apply(this, arguments); 96 | } 97 | _$rapyd$_extends(ValueError, Error); 98 | ValueError.prototype.__init__ = function __init__(message){ 99 | var self = this; 100 | self.name = "ValueError"; 101 | self.message = message; 102 | }; 103 | 104 | function AssertionError() { 105 | AssertionError.prototype.__init__.apply(this, arguments); 106 | } 107 | _$rapyd$_extends(AssertionError, Error); 108 | AssertionError.prototype.__init__ = function __init__(message){ 109 | var self = this; 110 | if (typeof message === "undefined") message = ""; 111 | self.name = "AssertionError"; 112 | self.message = message; 113 | }; 114 | 115 | function map(oper, arr) { 116 | return list(arr.map(oper)); 117 | } 118 | function filter(oper, arr) { 119 | return list(arr.filter(oper)); 120 | } 121 | function sum(arr, start) { 122 | if (typeof start === "undefined") start = 0; 123 | return arr.reduce(function(prev, cur) { 124 | return prev + cur; 125 | }, start); 126 | } 127 | function deep_eq(a, b) { 128 | var i; 129 | "\n Equality comparison that works with all data types, returns true if structure and\n contents of first object equal to those of second object\n\n Arguments:\n a: first object\n b: second object\n "; 130 | if (a === b) { 131 | return true; 132 | } 133 | if (a instanceof Array && b instanceof Array || a instanceof Object && b instanceof Object) { 134 | if (a.constructor !== b.constructor || a.length !== b.length) { 135 | return false; 136 | } 137 | var _$rapyd$_Iter0 = _$rapyd$_Iterable(dict.keys(a)); 138 | for (var _$rapyd$_Index0 = 0; _$rapyd$_Index0 < _$rapyd$_Iter0.length; _$rapyd$_Index0++) { 139 | i = _$rapyd$_Iter0[_$rapyd$_Index0]; 140 | if (b.hasOwnProperty(i)) { 141 | if (!deep_eq(a[i], b[i])) { 142 | return false; 143 | } 144 | } else { 145 | return false; 146 | } 147 | } 148 | return true; 149 | } 150 | return false; 151 | } 152 | String.prototype.find = String.prototype.indexOf; 153 | String.prototype.strip = String.prototype.trim; 154 | String.prototype.lstrip = String.prototype.trimLeft; 155 | String.prototype.rstrip = String.prototype.trimRight; 156 | String.prototype.join = function(iterable) { 157 | return iterable.join(this); 158 | }; 159 | String.prototype.zfill = function(size) { 160 | var s; 161 | s = this; 162 | while (s.length < size) { 163 | s = "0" + s; 164 | } 165 | return s; 166 | }; 167 | function list(iterable) { 168 | if (typeof iterable === "undefined") iterable = []; 169 | var result, i; 170 | result = []; 171 | var _$rapyd$_Iter1 = _$rapyd$_Iterable(iterable); 172 | for (var _$rapyd$_Index1 = 0; _$rapyd$_Index1 < _$rapyd$_Iter1.length; _$rapyd$_Index1++) { 173 | i = _$rapyd$_Iter1[_$rapyd$_Index1]; 174 | result.append(i); 175 | } 176 | return result; 177 | } 178 | Array.prototype.append = Array.prototype.push; 179 | Array.prototype.find = Array.prototype.indexOf; 180 | Array.prototype.index = function(index) { 181 | var val; 182 | val = this.find(index); 183 | if (val === -1) { 184 | throw new ValueError(str(index) + " is not in list"); 185 | } 186 | return val; 187 | }; 188 | Array.prototype.insert = function(index, item) { 189 | this.splice(index, 0, item); 190 | }; 191 | Array.prototype.pop = function(index) { 192 | if (typeof index === "undefined") index = this.length - 1; 193 | return this.splice(index, 1)[0]; 194 | }; 195 | Array.prototype.extend = function(array2) { 196 | this.push.apply(this, array2); 197 | }; 198 | Array.prototype.remove = function(item) { 199 | var index; 200 | index = this.find(item); 201 | this.splice(index, 1); 202 | }; 203 | Array.prototype.copy = function() { 204 | return this.slice(0); 205 | }; 206 | function dict(iterable) { 207 | var result, key; 208 | result = {}; 209 | var _$rapyd$_Iter2 = _$rapyd$_Iterable(iterable); 210 | for (var _$rapyd$_Index2 = 0; _$rapyd$_Index2 < _$rapyd$_Iter2.length; _$rapyd$_Index2++) { 211 | key = _$rapyd$_Iter2[_$rapyd$_Index2]; 212 | result[key] = iterable[key]; 213 | } 214 | return result; 215 | } 216 | if (typeof Object.getOwnPropertyNames !== "function") { 217 | dict.keys = function(hash) { 218 | var keys; 219 | keys = []; 220 | 221 | for (var x in hash) { 222 | if (hash.hasOwnProperty(x)) { 223 | keys.push(x); 224 | } 225 | } 226 | ; 227 | return keys; 228 | }; 229 | } else { 230 | dict.keys = function(hash) { 231 | return Object.getOwnPropertyNames(hash); 232 | }; 233 | } 234 | dict.values = function(hash) { 235 | var vals, key; 236 | vals = []; 237 | var _$rapyd$_Iter3 = _$rapyd$_Iterable(dict.keys(hash)); 238 | for (var _$rapyd$_Index3 = 0; _$rapyd$_Index3 < _$rapyd$_Iter3.length; _$rapyd$_Index3++) { 239 | key = _$rapyd$_Iter3[_$rapyd$_Index3]; 240 | vals.append(hash[key]); 241 | } 242 | return vals; 243 | }; 244 | dict.items = function(hash) { 245 | var items, key; 246 | items = []; 247 | var _$rapyd$_Iter4 = _$rapyd$_Iterable(dict.keys(hash)); 248 | for (var _$rapyd$_Index4 = 0; _$rapyd$_Index4 < _$rapyd$_Iter4.length; _$rapyd$_Index4++) { 249 | key = _$rapyd$_Iter4[_$rapyd$_Index4]; 250 | items.append([key, hash[key]]); 251 | } 252 | return items; 253 | }; 254 | dict.copy = dict; 255 | dict.clear = function(hash) { 256 | var key; 257 | var _$rapyd$_Iter5 = _$rapyd$_Iterable(dict.keys(hash)); 258 | for (var _$rapyd$_Index5 = 0; _$rapyd$_Index5 < _$rapyd$_Iter5.length; _$rapyd$_Index5++) { 259 | key = _$rapyd$_Iter5[_$rapyd$_Index5]; 260 | delete hash[key]; 261 | } 262 | }; 263 | -------------------------------------------------------------------------------- /jQuery Example/static/rapydscript/pyjTransformer.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 3 | /** 4 | * Actually transform the code. 5 | * 6 | * @param {string} code 7 | * @param {string?} url 8 | * @param {object?} options 9 | * @return {string} The transformed code. 10 | * @internal 11 | */ 12 | function transformCode(code, url, options) { 13 | //RapydScript options 14 | var rs_options = { 15 | "filename":"demo", 16 | "toplevel":null, 17 | "basedir": null, 18 | "libdir": null 19 | }; 20 | var output_opts = { 21 | "beautify":true, 22 | "private_scope":false, 23 | "omit_baselib":true, 24 | "comments" : true 25 | }; 26 | 27 | var rapydscript_string = code; 28 | output = OutputStream(output_opts) 29 | rapydscript_string += '\n'; //just to be safe 30 | 31 | try { 32 | TOPLEVEL = parse(rapydscript_string, rs_options); 33 | TOPLEVEL.print(output); 34 | //(new Function(String(output) + '\n'))(); 35 | var js_code = String(output) + '\n' 36 | js_code = js_code.replace('var __name__ = "__main__";', ''); 37 | return js_code 38 | 39 | } catch(err) { 40 | console.log("ERROR: " + err.message + ". Line " + err.line + ", column " + err.col + "."); 41 | } 42 | } 43 | 44 | /** 45 | * Appends a script element at the end of the with the content of code, 46 | * after transforming it. 47 | * 48 | * @param {string} code The original source code 49 | * @param {string?} url Where the code came from. null if inline 50 | * @param {object?} options Options to pass to jstransform 51 | * @internal 52 | */ 53 | function run(code, url, options) { 54 | var scriptEl = document.createElement('script'); 55 | scriptEl.text = transformCode(code, url, options); 56 | if (options.otype) { 57 | scriptEl.type = options.otype 58 | } 59 | headEl.appendChild(scriptEl); 60 | } 61 | 62 | /** 63 | * Load script from the provided url and pass the content to the callback. 64 | * 65 | * @param {string} script The script 66 | * @param {function} callback Function to call with the content of url 67 | * @internal 68 | */ 69 | function load(script, successCallback, errorCallback) { 70 | var xhr; 71 | xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') 72 | : new XMLHttpRequest(); 73 | 74 | // async, however scripts will be executed in the order they are in the 75 | // DOM to mirror normal script loading. 76 | xhr.open('GET', 77 | script.src, 78 | script.options.async 79 | ); 80 | if ('overrideMimeType' in xhr) { 81 | xhr.overrideMimeType('text/plain'); 82 | } 83 | xhr.onreadystatechange = function() { 84 | if (xhr.readyState === 4) { 85 | if (xhr.status === 0 || xhr.status === 200) { 86 | successCallback(xhr.responseText); 87 | } else { 88 | errorCallback(); 89 | throw new Error("Could not load " + script.src); 90 | } 91 | } 92 | }; 93 | return xhr.send(null); 94 | } 95 | 96 | /** 97 | * Loop over provided script tags and get the content, via innerHTML if an 98 | * inline script, or by using XHR. Transforms are applied if needed. The scripts 99 | * are executed in the order they are found on the page. 100 | * 101 | * @param {array} scripts The