├── LICENSE ├── README.md ├── bin └── pear ├── examples ├── array.pear ├── rev.pear ├── test.pear └── vars.pear ├── lib ├── parser.js ├── scope.js └── transpiler.js └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Ondřej Kocián 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [![npm package][npm-badge]][npm] 4 | [![david-dm][david-badge]][david-dm] 5 | 6 | **PearScript** - Little language that compiles into Javascript 7 | 8 | # Usage 9 | Install pearscript **globally** 10 | ``` 11 | npm install -g pearscript 12 | ``` 13 | ###### U can install it locally too of course 14 | 15 | Then use it with **pear** command - File must have **pear** extension 16 | 17 | ``` 18 | pear your-file.pear 19 | ``` 20 | 21 | It will produce your-file.js 22 | 23 | Or use Gulp plugin 24 | 25 | ## Documentation 26 | ###### Documentation being reworked 27 | ##### Use ./examples/ 28 | 29 | [npm-badge]: https://img.shields.io/npm/v/pearscript.svg 30 | [npm]: https://www.npmjs.com/package/pearscript 31 | 32 | [david-badge]: https://david-dm.org/kocisov/pearscript.svg 33 | [david-dm]: https://david-dm.org/kocisov/pearscript 34 | -------------------------------------------------------------------------------- /bin/pear: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const fs = require('fs'); 3 | const transpiler = require('../lib/transpiler'); 4 | const chalk = require('chalk'); 5 | 6 | if(process.argv[2]) { 7 | const fileName = process.argv[2]; 8 | const ext = fileName.split('.'); 9 | 10 | if(ext.length > 0 && ext[ext.length -1] === 'pear') { 11 | 12 | const output = transpiler.transpile(fs.readFileSync(fileName, 'utf-8')); 13 | 14 | } else { 15 | console.log(chalk.red('File must have pear extension.')); 16 | } 17 | } else { 18 | console.log(chalk.red('You must specify a file.')); 19 | } 20 | 21 | if(process.argv[3]) { 22 | const of = process.argv[3]; 23 | fs.writeFileSync(of, output); 24 | console.log(chalk.green('Compiled into: ' + of)); 25 | } else { 26 | const outputFile = ext[0] + '.js'; 27 | fs.writeFileSync(outputFile, output); 28 | console.log(chalk.green('Compiled into: ' + outputFile)); 29 | } -------------------------------------------------------------------------------- /examples/array.pear: -------------------------------------------------------------------------------- 1 | // set variables 2 | ip = 'localhost' 3 | 4 | arr = [ip ':' 1337] 5 | log.{arr.1 _con arr.2 _con arr.3} 6 | -------------------------------------------------------------------------------- /examples/rev.pear: -------------------------------------------------------------------------------- 1 | func test(value) { 2 | ___ = {" value.slice(1, -1) "} 3 | return ___ 4 | } 5 | 6 | log.{ 7 | {" test('.Lorem ipsum dolor.') "} 8 | } -------------------------------------------------------------------------------- /examples/test.pear: -------------------------------------------------------------------------------- 1 | name = null 2 | value = null 3 | arr = [1 2 3 name value 'John' 'hero'] 4 | n = 2 5 | 6 | if n > 3 { 7 | log."i is greater than 3" 8 | } else { 9 | log.'i is not greater than 3' 10 | } 11 | 12 | variable = $.'main' 13 | el = $g.'#main' 14 | 15 | log.{ 16 | not_object -> { 17 | message: 'hello' 18 | } 19 | } 20 | 21 | switch(num) { 22 | -> 1337 log.'num is 1337' 23 | -> 420 log.'num is 420' 24 | -> 12 log.'num is 12' 25 | -> 360 log.'num is 360' 26 | } 27 | 28 | al.'hello' 29 | 30 | while (i) i < 3 { 31 | al.'i is smaller than 3' 32 | if port = 1337 { 33 | num = 420 34 | } 35 | i++ 36 | } 37 | 38 | for i 0 i > k.len i++ { 39 | log.i 40 | } 41 | 42 | func doubleThis(x) { 43 | num = x * x 44 | return num 45 | } 46 | 47 | object -> { 48 | hero: 'Superman' 49 | power: 'Brilliant' 50 | } 51 | 52 | j.parse num. 53 | log.{ j.parse num } 54 | 55 | lol = $.main 56 | lol.html('lol') -------------------------------------------------------------------------------- /examples/vars.pear: -------------------------------------------------------------------------------- 1 | k = 0 2 | 3 | if k < 3 { 4 | log.'hello' 5 | } 6 | 7 | while (i) i < 3 { 8 | al.'i is smaller than 3' 9 | if port = 1337 { 10 | num = 420 11 | } 12 | i++ 13 | } 14 | 15 | for i 0 i > k.len i++ { 16 | log.i 17 | } -------------------------------------------------------------------------------- /lib/parser.js: -------------------------------------------------------------------------------- 1 | /* parser generated by jison 0.4.16 */ 2 | /* 3 | Returns a Parser object of the following structure: 4 | 5 | Parser: { 6 | yy: {} 7 | } 8 | 9 | Parser.prototype: { 10 | yy: {}, 11 | trace: function(), 12 | symbols_: {associative list: name ==> number}, 13 | terminals_: {associative list: number ==> name}, 14 | productions_: [...], 15 | performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, $$, _$), 16 | table: [...], 17 | defaultActions: {...}, 18 | parseError: function(str, hash), 19 | parse: function(input), 20 | 21 | lexer: { 22 | EOF: 1, 23 | parseError: function(str, hash), 24 | setInput: function(input), 25 | input: function(), 26 | unput: function(str), 27 | more: function(), 28 | less: function(n), 29 | pastInput: function(), 30 | upcomingInput: function(), 31 | showPosition: function(), 32 | test_match: function(regex_match_array, rule_index), 33 | next: function(), 34 | lex: function(), 35 | begin: function(condition), 36 | popState: function(), 37 | _currentRules: function(), 38 | topState: function(), 39 | pushState: function(condition), 40 | 41 | options: { 42 | ranges: boolean (optional: true ==> token location info will include a .range[] member) 43 | flex: boolean (optional: true ==> flex-like lexing behaviour where the rules are tested exhaustively to find the longest match) 44 | backtrack_lexer: boolean (optional: true ==> lexer regexes are tested in order and for each matching regex the action code is invoked; the lexer terminates the scan when a token is returned by the action code) 45 | }, 46 | 47 | performAction: function(yy, yy_, $avoiding_name_collisions, YY_START), 48 | rules: [...], 49 | conditions: {associative list: name ==> set}, 50 | } 51 | } 52 | 53 | 54 | token location info (@$, _$, etc.): { 55 | first_line: n, 56 | last_line: n, 57 | first_column: n, 58 | last_column: n, 59 | range: [start_number, end_number] (where the numbers are indexes into the input string, regular zero-based) 60 | } 61 | 62 | 63 | the parseError function receives a 'hash' object with these members for lexer and parser errors: { 64 | text: (matched text) 65 | token: (the produced terminal token, if any) 66 | line: (yylineno) 67 | } 68 | while parser (grammar) errors will also provide these members, i.e. parser errors deliver a superset of attributes: { 69 | loc: (yylloc) 70 | expected: (string describing the set of expected tokens) 71 | recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error) 72 | } 73 | */ 74 | var parser = (function(){ 75 | var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[1,4],$V1=[1,16],$V2=[1,5],$V3=[1,6],$V4=[1,7],$V5=[1,17],$V6=[1,9],$V7=[1,10],$V8=[1,11],$V9=[1,19],$Va=[1,12],$Vb=[1,13],$Vc=[1,14],$Vd=[1,18],$Ve=[1,20],$Vf=[1,21],$Vg=[5,7,10,11,12,15,19,22,26,27,29,30,31,32,34,35,40,41,46],$Vh=[1,32],$Vi=[1,33],$Vj=[2,26],$Vk=[5,7,8,10,11,12,15,16,17,19,20,22,25,26,27,29,30,31,32,34,35,40,41,43,44,45,46,47,48,49,50,51],$Vl=[2,31],$Vm=[10,22,30,40,41,46],$Vn=[22,25,30,40,41],$Vo=[11,22,30,40,41],$Vp=[11,32]; 76 | var parser = {trace: function trace() { }, 77 | yy: {}, 78 | symbols_: {"error":2,"program":3,"statements":4,"EOF":5,"statement":6,"CLOG":7,".":8,"i":9,"{":10,"}":11,"IF":12,"p":13,"ELSE":14,"SWITCH":15,"(":16,")":17,"cases":18,"FUNCTION":19,"=":20,"sm":21,"STRING":22,"[":23,"arr":24,"]":25,"ALERT":26,"WHILE":27,"ap":28,"FOR":29,"NUMBER":30,"RETURN":31,"->":32,"objects":33,"j.parse":34,"j.strin":35,"$":36,"g":37,"HTML":38,"m":39,"VAR":40,"NULL":41,"objExpr":42,":":43,"+":44,"-":45,"CONCAT":46,"*":47,"/":48,"!=":49,">":50,"<":51,"LEN":52,"arrExpr":53,"$accept":0,"$end":1}, 79 | terminals_: {2:"error",5:"EOF",7:"CLOG",8:".",10:"{",11:"}",12:"IF",14:"ELSE",15:"SWITCH",16:"(",17:")",19:"FUNCTION",20:"=",22:"STRING",23:"[",25:"]",26:"ALERT",27:"WHILE",29:"FOR",30:"NUMBER",31:"RETURN",32:"->",34:"j.parse",35:"j.strin",36:"$",37:"g",38:"HTML",40:"VAR",41:"NULL",43:":",44:"+",45:"-",46:"CONCAT",47:"*",48:"/",49:"!=",50:">",51:"<",52:"LEN"}, 80 | productions_: [0,[3,2],[4,1],[4,2],[6,3],[6,5],[6,5],[6,9],[6,7],[6,8],[6,3],[6,5],[6,5],[6,5],[6,3],[6,9],[6,8],[6,2],[6,5],[6,2],[6,2],[6,3],[6,3],[6,5],[6,6],[6,3],[6,1],[6,3],[6,6],[21,1],[21,1],[9,1],[9,1],[9,1],[9,1],[33,1],[42,3],[42,4],[28,3],[28,3],[28,1],[39,3],[39,3],[39,3],[39,3],[18,3],[18,4],[13,1],[13,3],[13,3],[13,3],[13,3],[13,5],[13,5],[24,1],[53,1],[53,2]], 81 | performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) { 82 | /* this == yyval */ 83 | 84 | var $0 = $$.length - 1; 85 | switch (yystate) { 86 | case 1: 87 | return yy.mainExp(yy.createVars(), $$[$0-1]); 88 | break; 89 | case 2: case 31: case 32: case 33: case 34: case 47: 90 | this.$ = $$[$0]; 91 | break; 92 | case 3: 93 | this.$ = $$[$0-1].concat($$[$0]); 94 | break; 95 | case 4: 96 | this.$ = yy.printStatement($$[$0]); 97 | break; 98 | case 5: 99 | this.$ = yy.printStatement($$[$0-1]); 100 | break; 101 | case 6: 102 | this.$ = yy.ifStatement($$[$0-3], $$[$0-1]); 103 | break; 104 | case 7: 105 | this.$ = yy.ifElseStatement($$[$0-7], $$[$0-5], $$[$0-1]); 106 | break; 107 | case 8: 108 | this.$ = yy.switchStatement($$[$0-4], $$[$0-1]); 109 | break; 110 | case 9: 111 | this.$ = yy.createFuncWith($$[$0-6], $$[$0-4], $$[$0-1]); 112 | break; 113 | case 10: 114 | this.$ = yy.setVar($$[$0-2], $$[$0]); 115 | break; 116 | case 11: 117 | this.$ = yy.setVar($$[$0-4], $$[$0-1]); 118 | break; 119 | case 12: 120 | this.$ = yy.setVarSlice($$[$0-4], $$[$0-1]); 121 | break; 122 | case 13: 123 | this.$ = yy.arrayStatement($$[$0-4], $$[$0-1]); 124 | break; 125 | case 14: 126 | this.$ = yy.alertStatement($$[$0]); 127 | break; 128 | case 15: 129 | this.$ = yy.whileLoopStatement($$[$0-6], $$[$0-4], $$[$0-2], $$[$0-1]); 130 | break; 131 | case 16: 132 | this.$ = yy.forLoopStatement($$[$0-6], $$[$0-5], $$[$0-4], $$[$0-3], $$[$0-1]); 133 | break; 134 | case 17: 135 | this.$ = yy.returnStatement($$[$0]); 136 | break; 137 | case 18: 138 | this.$ = yy.createObjectStatement($$[$0-4], $$[$0-1]); 139 | break; 140 | case 19: 141 | this.$ = yy.jsonParseStatement($$[$0], 0); 142 | break; 143 | case 20: 144 | this.$ = yy.jsonStringifyStatement($$[$0], 0); 145 | break; 146 | case 21: 147 | this.$ = yy.jsonParseStatement($$[$0-1], 1); 148 | break; 149 | case 22: 150 | this.$ = yy.jsonStringifyStatement($$[$0-1], 1); 151 | break; 152 | case 23: 153 | this.$ = yy.querySelector($$[$0-4], $$[$0]); 154 | break; 155 | case 24: 156 | this.$ = yy.getElById($$[$0-5], $$[$0]); 157 | break; 158 | case 25: 159 | this.$ = $$[$0-2] + '[' + $$[$0] + ']'; 160 | break; 161 | case 27: 162 | this.$ = yy.allText($$[$0-1]); 163 | break; 164 | case 28: 165 | this.$ = yy.innerHTMLobj($$[$0-5], $$[$0-1]); 166 | break; 167 | case 36: 168 | this.$ = $$[$0-2] + ': ' + $$[$0] + ','; 169 | break; 170 | case 37: 171 | this.$ = $$[$0-3] + $$[$0-2] + ': ' + $$[$0] + ','; 172 | break; 173 | case 38: 174 | this.$ = $$[$0-2] + '++'; 175 | break; 176 | case 39: 177 | this.$ = $$[$0-2] + '--'; 178 | break; 179 | case 40: 180 | this.$ = ' + '; 181 | break; 182 | case 41: 183 | this.$ = $$[$0-2] + ' + ' + $$[$0]; 184 | break; 185 | case 42: 186 | this.$ = $$[$0-2] + ' - ' + $$[$0]; 187 | break; 188 | case 43: 189 | this.$ = $$[$0-2] + ' * ' + $$[$0]; 190 | break; 191 | case 44: 192 | this.$ = $$[$0-2] + ' / ' + $$[$0]; 193 | break; 194 | case 45: 195 | this.$ = 'case ' + $$[$0-1] + ': ' + $$[$0] + '\nbreak;'; 196 | break; 197 | case 46: 198 | this.$ = $$[$0-3] + ' case ' + $$[$0-1] + ': ' + $$[$0] + '\nbreak;'; 199 | break; 200 | case 48: 201 | this.$ = $$[$0-2] + ' != ' + $$[$0]; 202 | break; 203 | case 49: 204 | this.$ = $$[$0-2] + ' === ' + $$[$0]; 205 | break; 206 | case 50: 207 | this.$ = $$[$0-2] + ' > ' + $$[$0]; 208 | break; 209 | case 51: 210 | this.$ = $$[$0-2] + ' < ' + $$[$0]; 211 | break; 212 | case 52: 213 | this.$ = $$[$0-4] + ' > ' + $$[$0-2] + '.length'; 214 | break; 215 | case 53: 216 | this.$ = $$[$0-4] + ' < ' + $$[$0-2] + '.length'; 217 | break; 218 | case 56: 219 | this.$ = $$[$0-1] + ', ' + $$[$0]; 220 | break; 221 | } 222 | }, 223 | table: [{3:1,4:2,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{1:[3]},{5:[1,22],6:23,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},o($Vg,[2,2]),{8:[1,24]},{9:26,13:25,22:$V5,30:$V9,40:$Vd,41:$Ve},{16:[1,27]},{9:28,22:$V5,30:$V9,40:$Vd,41:$Ve},{8:[1,31],20:[1,29],32:[1,30],44:$Vh,45:$Vi},{8:[1,34]},{16:[1,35]},{9:36,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:38,21:37,22:$V5,30:$V9,39:39,40:$Vd,41:$Ve},{9:40,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:41,22:$V5,30:$V9,40:$Vd,41:$Ve},o($Vg,$Vj),{22:[1,42]},o($Vk,$Vl),o($Vk,[2,32]),o($Vk,[2,33]),o($Vk,[2,34]),o($Vg,[2,40]),{1:[2,1]},o($Vg,[2,3]),{9:43,10:[1,44],22:$V5,30:$V9,40:$Vd,41:$Ve},{10:[1,45]},o($Vm,[2,47],{20:[1,47],49:[1,46],50:[1,48],51:[1,49]}),{9:50,22:$V5,30:$V9,40:$Vd,41:$Ve},{16:[1,51]},{9:38,10:[1,53],21:52,22:$V5,23:[1,54],30:$V9,36:[1,55],39:39,40:$Vd,41:$Ve},{10:[1,56]},{9:57,22:$V5,30:$V9,38:[1,58],40:$Vd,41:$Ve},{44:[1,59]},{45:[1,60]},{9:61,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:62,22:$V5,30:$V9,40:$Vd,41:$Ve},{30:[1,63]},o($Vg,[2,17]),o($Vg,[2,29],{44:[1,64],45:[1,65],47:[1,66],48:[1,67]}),o($Vg,[2,30]),o($Vg,[2,19],{8:[1,68]}),o($Vg,[2,20],{8:[1,69]}),{11:[1,70]},o($Vg,[2,4]),{4:71,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{4:72,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{9:73,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:74,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:75,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:76,22:$V5,30:$V9,40:$Vd,41:$Ve},{17:[1,77]},{9:78,22:$V5,30:$V9,40:$Vd,41:$Ve},o($Vg,[2,10]),{4:79,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:[1,80],26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{9:83,22:$V5,24:81,30:$V9,40:$Vd,41:$Ve,53:82},{8:[1,84],37:[1,85]},{9:88,22:$V5,30:$V9,33:86,40:$Vd,41:$Ve,42:87},o($Vg,[2,25]),{16:[1,89]},o($Vg,[2,38]),o($Vg,[2,39]),o($Vg,[2,14]),{17:[1,90]},{9:26,13:91,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:92,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:93,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:94,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:95,22:$V5,30:$V9,40:$Vd,41:$Ve},o($Vg,[2,21]),o($Vg,[2,22]),o($Vg,[2,27]),{6:23,7:$V0,9:8,10:$V1,11:[1,96],12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{6:23,7:$V0,9:8,10:$V1,11:[1,97],12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},o($Vm,[2,48]),o($Vm,[2,49]),o($Vm,[2,50],{8:[1,98]}),o($Vm,[2,51],{8:[1,99]}),{10:[1,100]},{17:[1,101]},{6:23,7:$V0,9:8,10:$V1,11:[1,102],12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},o([8,20,32,44,45],$Vl,{11:[1,103]}),{25:[1,104]},{9:105,22:$V5,25:[2,54],30:$V9,40:$Vd,41:$Ve},o($Vn,[2,55]),{9:106,22:$V5,30:$V9,40:$Vd,41:$Ve},{8:[1,107]},{11:[1,108]},{9:109,11:[2,35],22:$V5,30:$V9,40:$Vd,41:$Ve},{43:[1,110]},{9:111,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:26,13:112,22:$V5,30:$V9,40:$Vd,41:$Ve},{9:114,22:$V5,28:113,30:$V9,40:$Vd,41:$Ve,46:$Vf},o($Vg,[2,41]),o($Vg,[2,42]),o($Vg,[2,43]),o($Vg,[2,44]),o($Vg,[2,5]),o($Vg,[2,6],{14:[1,115]}),{52:[1,116]},{52:[1,117]},{18:118,32:[1,119]},{10:[1,120]},o($Vg,[2,11]),o($Vg,[2,12]),o($Vg,[2,13]),o($Vn,[2,56]),o($Vg,[2,23]),{9:121,22:$V5,30:$V9,40:$Vd,41:$Ve},o($Vg,[2,18]),{43:[1,122]},{9:123,22:$V5,30:$V9,40:$Vd,41:$Ve},{17:[1,124]},{10:[1,125]},{10:[1,126]},{44:$Vh,45:$Vi},{10:[1,127]},o($Vm,[2,52]),o($Vm,[2,53]),{11:[1,128],32:[1,129]},{9:130,22:$V5,30:$V9,40:$Vd,41:$Ve},{4:131,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},o($Vg,[2,24]),{9:132,22:$V5,30:$V9,40:$Vd,41:$Ve},o($Vo,[2,36]),o($Vg,[2,28]),{4:133,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{4:134,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{4:135,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},o($Vg,[2,8]),{9:136,22:$V5,30:$V9,40:$Vd,41:$Ve},{4:137,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{6:23,7:$V0,9:8,10:$V1,11:[1,138],12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},o($Vo,[2,37]),{6:23,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:139,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{6:23,7:$V0,9:8,10:$V1,11:[1,140],12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{6:23,7:$V0,9:8,10:$V1,11:[1,141],12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},{4:142,6:3,7:$V0,9:8,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,28:15,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf},o($Vp,[2,45],{9:8,28:15,6:23,7:$V0,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf}),o($Vg,[2,9]),o([7,10,12,15,19,22,26,27,29,30,31,34,35,40,41,46],$Vj,{11:[1,143]}),o($Vg,[2,16]),o($Vg,[2,7]),o($Vp,[2,46],{9:8,28:15,6:23,7:$V0,10:$V1,12:$V2,15:$V3,19:$V4,22:$V5,26:$V6,27:$V7,29:$V8,30:$V9,31:$Va,34:$Vb,35:$Vc,40:$Vd,41:$Ve,46:$Vf}),o($Vg,[2,15])], 224 | defaultActions: {22:[2,1]}, 225 | parseError: function parseError(str, hash) { 226 | if (hash.recoverable) { 227 | this.trace(str); 228 | } else { 229 | function _parseError (msg, hash) { 230 | this.message = msg; 231 | this.hash = hash; 232 | } 233 | _parseError.prototype = new Error(); 234 | 235 | throw new _parseError(str, hash); 236 | } 237 | }, 238 | parse: function parse(input) { 239 | var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; 240 | var args = lstack.slice.call(arguments, 1); 241 | var lexer = Object.create(this.lexer); 242 | var sharedState = { yy: {} }; 243 | for (var k in this.yy) { 244 | if (Object.prototype.hasOwnProperty.call(this.yy, k)) { 245 | sharedState.yy[k] = this.yy[k]; 246 | } 247 | } 248 | lexer.setInput(input, sharedState.yy); 249 | sharedState.yy.lexer = lexer; 250 | sharedState.yy.parser = this; 251 | if (typeof lexer.yylloc == 'undefined') { 252 | lexer.yylloc = {}; 253 | } 254 | var yyloc = lexer.yylloc; 255 | lstack.push(yyloc); 256 | var ranges = lexer.options && lexer.options.ranges; 257 | if (typeof sharedState.yy.parseError === 'function') { 258 | this.parseError = sharedState.yy.parseError; 259 | } else { 260 | this.parseError = Object.getPrototypeOf(this).parseError; 261 | } 262 | function popStack(n) { 263 | stack.length = stack.length - 2 * n; 264 | vstack.length = vstack.length - n; 265 | lstack.length = lstack.length - n; 266 | } 267 | _token_stack: 268 | var lex = function () { 269 | var token; 270 | token = lexer.lex() || EOF; 271 | if (typeof token !== 'number') { 272 | token = self.symbols_[token] || token; 273 | } 274 | return token; 275 | }; 276 | var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; 277 | while (true) { 278 | state = stack[stack.length - 1]; 279 | if (this.defaultActions[state]) { 280 | action = this.defaultActions[state]; 281 | } else { 282 | if (symbol === null || typeof symbol == 'undefined') { 283 | symbol = lex(); 284 | } 285 | action = table[state] && table[state][symbol]; 286 | } 287 | if (typeof action === 'undefined' || !action.length || !action[0]) { 288 | var errStr = ''; 289 | expected = []; 290 | for (p in table[state]) { 291 | if (this.terminals_[p] && p > TERROR) { 292 | expected.push('\'' + this.terminals_[p] + '\''); 293 | } 294 | } 295 | if (lexer.showPosition) { 296 | errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\''; 297 | } else { 298 | errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\''); 299 | } 300 | this.parseError(errStr, { 301 | text: lexer.match, 302 | token: this.terminals_[symbol] || symbol, 303 | line: lexer.yylineno, 304 | loc: yyloc, 305 | expected: expected 306 | }); 307 | } 308 | if (action[0] instanceof Array && action.length > 1) { 309 | throw new Error('Parse Error: multiple actions possible at state: ' + state + ', token: ' + symbol); 310 | } 311 | switch (action[0]) { 312 | case 1: 313 | stack.push(symbol); 314 | vstack.push(lexer.yytext); 315 | lstack.push(lexer.yylloc); 316 | stack.push(action[1]); 317 | symbol = null; 318 | if (!preErrorSymbol) { 319 | yyleng = lexer.yyleng; 320 | yytext = lexer.yytext; 321 | yylineno = lexer.yylineno; 322 | yyloc = lexer.yylloc; 323 | if (recovering > 0) { 324 | recovering--; 325 | } 326 | } else { 327 | symbol = preErrorSymbol; 328 | preErrorSymbol = null; 329 | } 330 | break; 331 | case 2: 332 | len = this.productions_[action[1]][1]; 333 | yyval.$ = vstack[vstack.length - len]; 334 | yyval._$ = { 335 | first_line: lstack[lstack.length - (len || 1)].first_line, 336 | last_line: lstack[lstack.length - 1].last_line, 337 | first_column: lstack[lstack.length - (len || 1)].first_column, 338 | last_column: lstack[lstack.length - 1].last_column 339 | }; 340 | if (ranges) { 341 | yyval._$.range = [ 342 | lstack[lstack.length - (len || 1)].range[0], 343 | lstack[lstack.length - 1].range[1] 344 | ]; 345 | } 346 | r = this.performAction.apply(yyval, [ 347 | yytext, 348 | yyleng, 349 | yylineno, 350 | sharedState.yy, 351 | action[1], 352 | vstack, 353 | lstack 354 | ].concat(args)); 355 | if (typeof r !== 'undefined') { 356 | return r; 357 | } 358 | if (len) { 359 | stack = stack.slice(0, -1 * len * 2); 360 | vstack = vstack.slice(0, -1 * len); 361 | lstack = lstack.slice(0, -1 * len); 362 | } 363 | stack.push(this.productions_[action[1]][0]); 364 | vstack.push(yyval.$); 365 | lstack.push(yyval._$); 366 | newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; 367 | stack.push(newState); 368 | break; 369 | case 3: 370 | return true; 371 | } 372 | } 373 | return true; 374 | }}; 375 | /* generated by jison-lex 0.3.4 */ 376 | var lexer = (function(){ 377 | var lexer = ({ 378 | 379 | EOF:1, 380 | 381 | parseError:function parseError(str, hash) { 382 | if (this.yy.parser) { 383 | this.yy.parser.parseError(str, hash); 384 | } else { 385 | throw new Error(str); 386 | } 387 | }, 388 | 389 | // resets the lexer, sets new input 390 | setInput:function (input, yy) { 391 | this.yy = yy || this.yy || {}; 392 | this._input = input; 393 | this._more = this._backtrack = this.done = false; 394 | this.yylineno = this.yyleng = 0; 395 | this.yytext = this.matched = this.match = ''; 396 | this.conditionStack = ['INITIAL']; 397 | this.yylloc = { 398 | first_line: 1, 399 | first_column: 0, 400 | last_line: 1, 401 | last_column: 0 402 | }; 403 | if (this.options.ranges) { 404 | this.yylloc.range = [0,0]; 405 | } 406 | this.offset = 0; 407 | return this; 408 | }, 409 | 410 | // consumes and returns one char from the input 411 | input:function () { 412 | var ch = this._input[0]; 413 | this.yytext += ch; 414 | this.yyleng++; 415 | this.offset++; 416 | this.match += ch; 417 | this.matched += ch; 418 | var lines = ch.match(/(?:\r\n?|\n).*/g); 419 | if (lines) { 420 | this.yylineno++; 421 | this.yylloc.last_line++; 422 | } else { 423 | this.yylloc.last_column++; 424 | } 425 | if (this.options.ranges) { 426 | this.yylloc.range[1]++; 427 | } 428 | 429 | this._input = this._input.slice(1); 430 | return ch; 431 | }, 432 | 433 | // unshifts one char (or a string) into the input 434 | unput:function (ch) { 435 | var len = ch.length; 436 | var lines = ch.split(/(?:\r\n?|\n)/g); 437 | 438 | this._input = ch + this._input; 439 | this.yytext = this.yytext.substr(0, this.yytext.length - len); 440 | //this.yyleng -= len; 441 | this.offset -= len; 442 | var oldLines = this.match.split(/(?:\r\n?|\n)/g); 443 | this.match = this.match.substr(0, this.match.length - 1); 444 | this.matched = this.matched.substr(0, this.matched.length - 1); 445 | 446 | if (lines.length - 1) { 447 | this.yylineno -= lines.length - 1; 448 | } 449 | var r = this.yylloc.range; 450 | 451 | this.yylloc = { 452 | first_line: this.yylloc.first_line, 453 | last_line: this.yylineno + 1, 454 | first_column: this.yylloc.first_column, 455 | last_column: lines ? 456 | (lines.length === oldLines.length ? this.yylloc.first_column : 0) 457 | + oldLines[oldLines.length - lines.length].length - lines[0].length : 458 | this.yylloc.first_column - len 459 | }; 460 | 461 | if (this.options.ranges) { 462 | this.yylloc.range = [r[0], r[0] + this.yyleng - len]; 463 | } 464 | this.yyleng = this.yytext.length; 465 | return this; 466 | }, 467 | 468 | // When called from action, caches matched text and appends it on next action 469 | more:function () { 470 | this._more = true; 471 | return this; 472 | }, 473 | 474 | // When called from action, signals the lexer that this rule fails to match the input, so the next matching rule (regex) should be tested instead. 475 | reject:function () { 476 | if (this.options.backtrack_lexer) { 477 | this._backtrack = true; 478 | } else { 479 | return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).\n' + this.showPosition(), { 480 | text: "", 481 | token: null, 482 | line: this.yylineno 483 | }); 484 | 485 | } 486 | return this; 487 | }, 488 | 489 | // retain first n characters of the match 490 | less:function (n) { 491 | this.unput(this.match.slice(n)); 492 | }, 493 | 494 | // displays already matched input, i.e. for error messages 495 | pastInput:function () { 496 | var past = this.matched.substr(0, this.matched.length - this.match.length); 497 | return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); 498 | }, 499 | 500 | // displays upcoming input, i.e. for error messages 501 | upcomingInput:function () { 502 | var next = this.match; 503 | if (next.length < 20) { 504 | next += this._input.substr(0, 20-next.length); 505 | } 506 | return (next.substr(0,20) + (next.length > 20 ? '...' : '')).replace(/\n/g, ""); 507 | }, 508 | 509 | // displays the character position where the lexing error occurred, i.e. for error messages 510 | showPosition:function () { 511 | var pre = this.pastInput(); 512 | var c = new Array(pre.length + 1).join("-"); 513 | return pre + this.upcomingInput() + "\n" + c + "^"; 514 | }, 515 | 516 | // test the lexed token: return FALSE when not a match, otherwise return token 517 | test_match:function (match, indexed_rule) { 518 | var token, 519 | lines, 520 | backup; 521 | 522 | if (this.options.backtrack_lexer) { 523 | // save context 524 | backup = { 525 | yylineno: this.yylineno, 526 | yylloc: { 527 | first_line: this.yylloc.first_line, 528 | last_line: this.last_line, 529 | first_column: this.yylloc.first_column, 530 | last_column: this.yylloc.last_column 531 | }, 532 | yytext: this.yytext, 533 | match: this.match, 534 | matches: this.matches, 535 | matched: this.matched, 536 | yyleng: this.yyleng, 537 | offset: this.offset, 538 | _more: this._more, 539 | _input: this._input, 540 | yy: this.yy, 541 | conditionStack: this.conditionStack.slice(0), 542 | done: this.done 543 | }; 544 | if (this.options.ranges) { 545 | backup.yylloc.range = this.yylloc.range.slice(0); 546 | } 547 | } 548 | 549 | lines = match[0].match(/(?:\r\n?|\n).*/g); 550 | if (lines) { 551 | this.yylineno += lines.length; 552 | } 553 | this.yylloc = { 554 | first_line: this.yylloc.last_line, 555 | last_line: this.yylineno + 1, 556 | first_column: this.yylloc.last_column, 557 | last_column: lines ? 558 | lines[lines.length - 1].length - lines[lines.length - 1].match(/\r?\n?/)[0].length : 559 | this.yylloc.last_column + match[0].length 560 | }; 561 | this.yytext += match[0]; 562 | this.match += match[0]; 563 | this.matches = match; 564 | this.yyleng = this.yytext.length; 565 | if (this.options.ranges) { 566 | this.yylloc.range = [this.offset, this.offset += this.yyleng]; 567 | } 568 | this._more = false; 569 | this._backtrack = false; 570 | this._input = this._input.slice(match[0].length); 571 | this.matched += match[0]; 572 | token = this.performAction.call(this, this.yy, this, indexed_rule, this.conditionStack[this.conditionStack.length - 1]); 573 | if (this.done && this._input) { 574 | this.done = false; 575 | } 576 | if (token) { 577 | return token; 578 | } else if (this._backtrack) { 579 | // recover context 580 | for (var k in backup) { 581 | this[k] = backup[k]; 582 | } 583 | return false; // rule action called reject() implying the next rule should be tested instead. 584 | } 585 | return false; 586 | }, 587 | 588 | // return next match in input 589 | next:function () { 590 | if (this.done) { 591 | return this.EOF; 592 | } 593 | if (!this._input) { 594 | this.done = true; 595 | } 596 | 597 | var token, 598 | match, 599 | tempMatch, 600 | index; 601 | if (!this._more) { 602 | this.yytext = ''; 603 | this.match = ''; 604 | } 605 | var rules = this._currentRules(); 606 | for (var i = 0; i < rules.length; i++) { 607 | tempMatch = this._input.match(this.rules[rules[i]]); 608 | if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { 609 | match = tempMatch; 610 | index = i; 611 | if (this.options.backtrack_lexer) { 612 | token = this.test_match(tempMatch, rules[i]); 613 | if (token !== false) { 614 | return token; 615 | } else if (this._backtrack) { 616 | match = false; 617 | continue; // rule action called reject() implying a rule MISmatch. 618 | } else { 619 | // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) 620 | return false; 621 | } 622 | } else if (!this.options.flex) { 623 | break; 624 | } 625 | } 626 | } 627 | if (match) { 628 | token = this.test_match(match, rules[index]); 629 | if (token !== false) { 630 | return token; 631 | } 632 | // else: this is a lexer rule which consumes input without producing a token (e.g. whitespace) 633 | return false; 634 | } 635 | if (this._input === "") { 636 | return this.EOF; 637 | } else { 638 | return this.parseError('Lexical error on line ' + (this.yylineno + 1) + '. Unrecognized text.\n' + this.showPosition(), { 639 | text: "", 640 | token: null, 641 | line: this.yylineno 642 | }); 643 | } 644 | }, 645 | 646 | // return next match that has a token 647 | lex:function lex() { 648 | var r = this.next(); 649 | if (r) { 650 | return r; 651 | } else { 652 | return this.lex(); 653 | } 654 | }, 655 | 656 | // activates a new lexer condition state (pushes the new lexer condition state onto the condition stack) 657 | begin:function begin(condition) { 658 | this.conditionStack.push(condition); 659 | }, 660 | 661 | // pop the previously active lexer condition state off the condition stack 662 | popState:function popState() { 663 | var n = this.conditionStack.length - 1; 664 | if (n > 0) { 665 | return this.conditionStack.pop(); 666 | } else { 667 | return this.conditionStack[0]; 668 | } 669 | }, 670 | 671 | // produce the lexer rule set which is active for the currently active lexer condition state 672 | _currentRules:function _currentRules() { 673 | if (this.conditionStack.length && this.conditionStack[this.conditionStack.length - 1]) { 674 | return this.conditions[this.conditionStack[this.conditionStack.length - 1]].rules; 675 | } else { 676 | return this.conditions["INITIAL"].rules; 677 | } 678 | }, 679 | 680 | // return the currently active lexer condition state; when an index argument is provided it produces the N-th previous condition state, if available 681 | topState:function topState(n) { 682 | n = this.conditionStack.length - 1 - Math.abs(n || 0); 683 | if (n >= 0) { 684 | return this.conditionStack[n]; 685 | } else { 686 | return "INITIAL"; 687 | } 688 | }, 689 | 690 | // alias for begin(condition) 691 | pushState:function pushState(condition) { 692 | this.begin(condition); 693 | }, 694 | 695 | // return the number of states currently on the stack 696 | stateStackSize:function stateStackSize() { 697 | return this.conditionStack.length; 698 | }, 699 | options: {}, 700 | performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { 701 | var YYSTATE=YY_START; 702 | switch($avoiding_name_collisions) { 703 | case 0:/* skip whitespace */ 704 | break; 705 | case 1:/* Ignore */ 706 | break; 707 | case 2:/* Ignore */ 708 | break; 709 | case 3:return 12 710 | break; 711 | case 4:return 14 712 | break; 713 | case 5:return 29 714 | break; 715 | case 6:return 27 716 | break; 717 | case 7:return 15 718 | break; 719 | case 8:return 7 720 | break; 721 | case 9:return 26 722 | break; 723 | case 10:return 52 724 | break; 725 | case 11:return 31 726 | break; 727 | case 12:return 19 728 | break; 729 | case 13:return 34 730 | break; 731 | case 14:return 35 732 | break; 733 | case 15:return 36 734 | break; 735 | case 16:return 37 736 | break; 737 | case 17:return 38 738 | break; 739 | case 18:return 'BOOL' 740 | break; 741 | case 19:return 'UNDEFINED' 742 | break; 743 | case 20:return 41 744 | break; 745 | case 21:return 46 746 | break; 747 | case 22:return 10 748 | break; 749 | case 23:return 11 750 | break; 751 | case 24:return 16 752 | break; 753 | case 25:return 17 754 | break; 755 | case 26:return 23 756 | break; 757 | case 27:return 25 758 | break; 759 | case 28:return '=[' 760 | break; 761 | case 29:return '=>' 762 | break; 763 | case 30:return 20 764 | break; 765 | case 31:return 49 766 | break; 767 | case 32:return 32 768 | break; 769 | case 33:return '!' 770 | break; 771 | case 34:return '?' 772 | break; 773 | case 35:return 44 774 | break; 775 | case 36:return 45 776 | break; 777 | case 37:return 47 778 | break; 779 | case 38:return 48 780 | break; 781 | case 39:return 51 782 | break; 783 | case 40:return 50 784 | break; 785 | case 41:return ',' 786 | break; 787 | case 42:return 8 788 | break; 789 | case 43:return 43 790 | break; 791 | case 44:return ';' 792 | break; 793 | case 45:return 22 794 | break; 795 | case 46:return 22 796 | break; 797 | case 47:return 30 798 | break; 799 | case 48:return 40 800 | break; 801 | case 49:return 5 802 | break; 803 | } 804 | }, 805 | rules: [/^(?:\s+)/,/^(?:\/\/.*)/,/^(?:[\/][*][^*]*[*]+([^\/*][^*]*[*]+)*[\/])/,/^(?:if\b)/,/^(?:else\b)/,/^(?:for\b)/,/^(?:while\b)/,/^(?:switch\b)/,/^(?:log\b)/,/^(?:al\b)/,/^(?:len\b)/,/^(?:return\b)/,/^(?:func\b)/,/^(?:j\.parse\b)/,/^(?:j\.strin\b)/,/^(?:\$)/,/^(?:g\b)/,/^(?:html\b)/,/^(?:bool\b)/,/^(?:undefined\b)/,/^(?:null\b)/,/^(?:_con\b)/,/^(?:\{)/,/^(?:\})/,/^(?:\()/,/^(?:\))/,/^(?:\[)/,/^(?:\])/,/^(?:=\[)/,/^(?:=>)/,/^(?:=)/,/^(?:!=)/,/^(?:->)/,/^(?:!)/,/^(?:\?)/,/^(?:\+)/,/^(?:-)/,/^(?:\*)/,/^(?:\/)/,/^(?:<)/,/^(?:>)/,/^(?:,)/,/^(?:\.)/,/^(?::)/,/^(?:;)/,/^(?:(['](\\.|[^']|\\')*?['])+)/,/^(?:(["](\\.|[^"]|\\")*?["])+)/,/^(?:[0-9]+(\.[0-9]+)?\b)/,/^(?:[_a-zA-Z]+[_a-zA-Z0-9]*\b)/,/^(?:$)/], 806 | conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49],"inclusive":true}} 807 | }); 808 | return lexer; 809 | })(); 810 | parser.lexer = lexer; 811 | function Parser () { 812 | this.yy = {}; 813 | } 814 | Parser.prototype = parser;parser.Parser = Parser; 815 | return new Parser; 816 | })(); 817 | 818 | 819 | if (typeof require !== 'undefined' && typeof exports !== 'undefined') { 820 | exports.parser = parser; 821 | exports.Parser = parser.Parser; 822 | exports.parse = function () { return parser.parse.apply(parser, arguments); }; 823 | exports.main = function commonjsMain(args) { 824 | if (!args[1]) { 825 | console.log('Usage: '+args[0]+' FILE'); 826 | process.exit(1); 827 | } 828 | var source = require('fs').readFileSync(require('path').normalize(args[1]), "utf8"); 829 | return exports.parser.parse(source); 830 | }; 831 | if (typeof module !== 'undefined' && require.main === module) { 832 | exports.main(process.argv.slice(1)); 833 | } 834 | } -------------------------------------------------------------------------------- /lib/scope.js: -------------------------------------------------------------------------------- 1 | const ___ = []; 2 | 3 | module.exports = { 4 | 5 | createVars: function() { 6 | 7 | if(___ == undefined || ___.length == 0) { 8 | // why add const; FeelsBadMan 9 | return ' '; 10 | } else { 11 | const uniq = [ ...new Set(___) ]; 12 | return 'const ' + uniq + ';'; 13 | } 14 | }, 15 | 16 | mainExp: function(vars, val) { 17 | return "(function() {\n 'use strict';\n" + vars + val + "\n})();"; 18 | }, 19 | 20 | ifStatement: function(nav, val) { 21 | return 'if(' + nav + ')' + '{' + val + '}'; 22 | }, 23 | 24 | innerHTMLobj: function(name, val) { 25 | ___.push(name); 26 | return name + '.innerHTML = ' + val + ';'; 27 | }, 28 | 29 | ifElseStatement: function(nav, val, elseval) { 30 | return 'if(' + nav + ')' + '{' + val + '} else {' + elseval + '}'; 31 | }, 32 | 33 | printStatement: function(val) { 34 | return 'console.log(' + val + ');'; 35 | }, 36 | 37 | switchStatement: function(nav, val) { 38 | ___.push(nav); 39 | return 'switch(' + nav + ') {' + val + '}'; 40 | }, 41 | 42 | setVar: function(name, val) { 43 | ___.push(name); 44 | return name + ' = ' + val + ';'; 45 | }, 46 | 47 | setVarSlice: function(name, val) { 48 | ___.push(name); 49 | const h = val.slice(1, -1); 50 | return name + ' = ' + h + ';'; 51 | }, 52 | 53 | arrayStatement: function(name, val) { 54 | ___.push(name); 55 | return name + ' = [' + val + '];'; 56 | }, 57 | 58 | querySelector: function(name, val) { 59 | ___.push(name); 60 | return name + ' = document.querySelector(' + val + ');'; 61 | }, 62 | 63 | getElById: function(name, val) { 64 | ___.push(name); 65 | return name + ' = document.getElementById(' + val + ');'; 66 | }, 67 | 68 | createFunc: function(name, dothis) { 69 | ___.push(name); 70 | return name + ' = function() {' + dothis + '}'; 71 | }, 72 | 73 | createFuncWith: function(name, op, dothis) { 74 | ___.push(name); 75 | return name + ' = function(' + op + ') {' + dothis + '}'; 76 | }, 77 | 78 | createObjectStatement: function(name, val) { 79 | ___.push(name); 80 | return name + ' = {' + val + '};'; 81 | }, 82 | 83 | testAST: function(a, b, c, d) { 84 | console.log(a + b + c + d); 85 | }, 86 | 87 | alertStatement: function(val) { 88 | return 'alert(' + val + ');'; 89 | }, 90 | 91 | jsonParseStatement: function(val, opt) { 92 | switch(opt) { 93 | case 1: 94 | return 'JSON.parse(' + val + ');'; 95 | break; 96 | case 0: 97 | return 'JSON.parse(' + val + ')'; 98 | break; 99 | } 100 | }, 101 | 102 | jsonStringifyStatement: function(val, opt) { 103 | switch(opt) { 104 | case 1: 105 | return 'JSON.stringify(' + val + ');'; 106 | break; 107 | case 0: 108 | return 'JSON.stringify(' + val + ')'; 109 | break; 110 | } 111 | }, 112 | 113 | returnStatement: function(val) { 114 | return 'return ' + val + ';'; 115 | }, 116 | 117 | forLoopStatement: function(o, val, exp, ft, stat) { 118 | ___.push(o); 119 | return 'for(' + o + ' = ' + val + '; ' + exp + '; ' + ft + ') {' + stat + '}'; 120 | }, 121 | 122 | whileLoopStatement: function(o, op, stat, ap) { 123 | ___.push(o); 124 | return 'while(' + op + ') {' + stat + ap + ';}'; 125 | }, 126 | 127 | allText: function(val) { 128 | var res = val.slice(1, -1); 129 | return res; 130 | } 131 | }; -------------------------------------------------------------------------------- /lib/transpiler.js: -------------------------------------------------------------------------------- 1 | var beautify = require('js-beautify').js_beautify; 2 | 3 | var transpile = function(source) { 4 | var parser = require('./parser').parser; 5 | parser.yy = require('./scope'); 6 | 7 | var transpiled = parser.parse(source); 8 | var output = beautify(transpiled, { indent_size: 2, max_preserve_newlines: -1, end_with_newline: true, space_before_conditional: 0 }); 9 | 10 | return output; 11 | }; 12 | 13 | module.exports.transpile = transpile; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pearscript", 3 | "description": "Simple language that compiles into Javascript", 4 | "version": "0.2.3-1", 5 | "keywords": [ 6 | "compiler", 7 | "language", 8 | "javascript", 9 | "pearscript" 10 | ], 11 | "main": "./bin/pear", 12 | "bin": { 13 | "pear": "./bin/pear" 14 | }, 15 | "preferGlobal": true, 16 | "scripts": { 17 | "test": "./bin/pear ./examples/test.pear" 18 | }, 19 | "author": "Ondřej Kocián ", 20 | "license": "MIT", 21 | "homepage": "https://github.com/kocisov/pearscript#readme", 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/kocisov/pearscript.git" 25 | }, 26 | "bugs": { 27 | "url": "https://github.com/kocisov/pearscript/issues" 28 | }, 29 | "devDependencies": {}, 30 | "directories": { 31 | "example": "examples" 32 | }, 33 | "dependencies": { 34 | "chalk": "^1.1.1", 35 | "jison": "^0.4.15", 36 | "js-beautify": "^1.5.10" 37 | } 38 | } 39 | --------------------------------------------------------------------------------