plio.js (1590B)
1 /* 29dec12abu 2 * (c) Software Lab. Alexander Burger 3 */ 4 5 function plio(lst) { 6 var NIX = 0; 7 var BEG = 1; 8 var DOT = 2; 9 var END = 3; 10 11 var NUMBER = 0; 12 var INTERN = 1; 13 var TRANSIENT = 2; 14 15 var PlioPos = 1; 16 var PlioLst = lst; 17 var PlioCnt, PlioMore; 18 19 function byte() { 20 if (PlioCnt == 0) { 21 if (!PlioMore) 22 return -1; 23 PlioMore = (PlioCnt = PlioLst[PlioPos++]) == 255; 24 } 25 --PlioCnt; 26 return PlioLst[PlioPos++]; 27 } 28 29 function expr(c) { 30 if ((c & ~3) !== 0) { // Atom 31 PlioMore = (PlioCnt = c >> 2) === 63; 32 if ((c & 3) === NUMBER) { 33 c = byte(); 34 var n = c >> 1; 35 if ((c & 1) !== 0) 36 n = -n; 37 var m = 128; 38 while ((c = byte()) >= 0) { 39 n += c * m; 40 m *= 256; 41 } 42 return n; 43 } 44 var str = ""; // TRANSIENT 45 while ((c = byte()) >= 0) { 46 if ((c & 0x80) != 0) { 47 if ((c & 0x20) == 0) 48 c &= 0x1F; 49 else 50 c = (c & 0xF) << 6 | byte() & 0x3F; 51 c = c << 6 | byte() & 0x3F; 52 } 53 str += String.fromCharCode(c); 54 } 55 return str; 56 } 57 if (c !== BEG) // NIX, DOT or END 58 return null; 59 var i = 0; 60 var lst = new Array(); 61 lst[0] = expr(PlioLst[PlioPos++]); 62 while ((c = PlioLst[PlioPos++]) !== END && c !== DOT) 63 lst[++i] = expr(c); 64 return lst; 65 } 66 67 return expr(PlioLst[0]); 68 }