Skip to content

Commit 5233f80

Browse files
committed
jison with decencies. Done
1 parent dc1dd78 commit 5233f80

7 files changed

Lines changed: 735 additions & 1920 deletions

File tree

demo/jison-demo.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@
55
<title>Basic JISON conversion test</title>
66
</head>
77
<body>
8-
<script src="../lib/require.js"></script>
8+
<!-- Jquery minified lib -->
9+
<!--<script src="../lib/jquery-1.12.0.min.js"></script>-->
10+
11+
<!-- backward compatibility shit -->
12+
<!--
13+
<script src="../lib/webtoolkit.js"></script>
14+
<script src="../lib/es5.js"></script>
15+
<script src="../lib/json2.js"></script>
16+
-->
17+
18+
<!-- jison -->
919
<script src="../lib/jison.js"></script>
20+
21+
<!-- myscript -->
1022
<script src="../src/js-to-webclgl.js"></script>
1123
<script>
1224

lib/_anchor.txt

Whitespace-only changes.

lib/es5.js

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
if (!Object.keys) {
2+
Object.keys = function (object) {
3+
var keys = [];
4+
for (var name in object) {
5+
if (Object.prototype.hasOwnProperty.call(object, name)) {
6+
keys.push(name);
7+
}
8+
}
9+
return keys;
10+
};
11+
}
12+
13+
if (!Object.defineProperty)
14+
Object.defineProperty = function(object, property, descriptor) {
15+
var has = Object.prototype.hasOwnProperty;
16+
if (typeof descriptor == "object") {
17+
if (has.call(descriptor, "value")) {
18+
if (!object.__lookupGetter__(property) && !object.__lookupSetter__(property))
19+
// data property defined and no pre-existing accessors
20+
object[property] = descriptor.value;
21+
if ((has.call(descriptor, "get") || has.call(descriptor, "set")))
22+
// descriptor has a value property but accessor already exists
23+
throw new TypeError("Object doesn't support this action");
24+
}
25+
if ( // can't implement these features; allow false but not true
26+
!(has.call(descriptor, "writable") ? descriptor.writable : true) ||
27+
!(has.call(descriptor, "enumerable") ? descriptor.enumerable : true) ||
28+
!(has.call(descriptor, "configurable") ? descriptor.configurable : true)
29+
)
30+
throw new RangeError(
31+
"This implementation of Object.defineProperty does not " +
32+
"support configurable, enumerable, or writable."
33+
);
34+
else if (typeof descriptor.get == "function")
35+
object.__defineGetter__(property, descriptor.get);
36+
if (typeof descriptor.set == "function")
37+
object.__defineSetter__(property, descriptor.set);
38+
}
39+
return object;
40+
};
41+
42+
if (!Object.defineProperties) {
43+
Object.defineProperties = function(object, properties) {
44+
for (var property in properties) {
45+
if (Object.prototype.hasOwnProperty.call(properties, property))
46+
Object.defineProperty(object, property, properties[property]);
47+
}
48+
return object;
49+
};
50+
}
51+
52+
if (!Object.create) {
53+
Object.create = function(prototype, properties) {
54+
function Type() {};
55+
Type.prototype = prototype;
56+
var object = new Type();
57+
if (typeof properties !== "undefined")
58+
Object.defineProperties(object, properties);
59+
return object;
60+
};
61+
}
62+
63+
// ES5 15.5.4.20
64+
if (!String.prototype.trim) {
65+
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
66+
var trimBeginRegexp = /^\s\s*/;
67+
var trimEndRegexp = /\s\s*$/;
68+
String.prototype.trim = function () {
69+
return String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
70+
};
71+
}
72+
// Array additions.
73+
74+
// ES5 draft:
75+
// http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
76+
77+
// ES5 15.4.3.2
78+
if (!Array.isArray) {
79+
Array.isArray = function(obj) {
80+
return Object.prototype.toString.call(obj) == "[object Array]";
81+
};
82+
}
83+
84+
// ES5 15.4.4.18
85+
if (!Array.prototype.forEach) {
86+
Array.prototype.forEach = function(block, thisObject) {
87+
var len = this.length >>> 0;
88+
for (var i = 0; i < len; i++) {
89+
if (i in this) {
90+
block.call(thisObject, this[i], i, this);
91+
}
92+
}
93+
};
94+
}
95+
96+
// ES5 15.4.4.19
97+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
98+
if (!Array.prototype.map) {
99+
Array.prototype.map = function(fun /*, thisp*/) {
100+
var len = this.length >>> 0;
101+
if (typeof fun != "function")
102+
throw new TypeError();
103+
104+
var res = new Array(len);
105+
var thisp = arguments[1];
106+
for (var i = 0; i < len; i++) {
107+
if (i in this)
108+
res[i] = fun.call(thisp, this[i], i, this);
109+
}
110+
111+
return res;
112+
};
113+
}
114+
115+
// filter
116+
if (!Array.prototype.filter) {
117+
Array.prototype.filter = function (block /*, thisp */) {
118+
var values = [];
119+
var thisp = arguments[1];
120+
for (var i = 0; i < this.length; i++)
121+
if (block.call(thisp, this[i]))
122+
values.push(this[i]);
123+
return values;
124+
};
125+
}
126+
127+
// every
128+
if (!Array.prototype.every) {
129+
Array.prototype.every = function (block /*, thisp */) {
130+
var thisp = arguments[1];
131+
for (var i = 0; i < this.length; i++)
132+
if (!block.call(thisp, this[i]))
133+
return false;
134+
return true;
135+
};
136+
}
137+
138+
// some
139+
if (!Array.prototype.some) {
140+
Array.prototype.some = function (block /*, thisp */) {
141+
var thisp = arguments[1];
142+
for (var i = 0; i < this.length; i++)
143+
if (block.call(thisp, this[i]))
144+
return true;
145+
return false;
146+
};
147+
}
148+
149+
// reduce
150+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
151+
if (!Array.prototype.reduce) {
152+
Array.prototype.reduce = function(fun /*, initial*/) {
153+
var len = this.length >>> 0;
154+
if (typeof fun != "function")
155+
throw new TypeError();
156+
157+
// no value to return if no initial value and an empty array
158+
if (len == 0 && arguments.length == 1)
159+
throw new TypeError();
160+
161+
var i = 0;
162+
if (arguments.length >= 2) {
163+
var rv = arguments[1];
164+
} else {
165+
do {
166+
if (i in this) {
167+
rv = this[i++];
168+
break;
169+
}
170+
171+
// if array contains no values, no initial value to return
172+
if (++i >= len)
173+
throw new TypeError();
174+
} while (true);
175+
}
176+
177+
for (; i < len; i++) {
178+
if (i in this)
179+
rv = fun.call(null, rv, this[i], i, this);
180+
}
181+
182+
return rv;
183+
};
184+
}
185+
186+
// reduceRight
187+
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
188+
if (!Array.prototype.reduceRight) {
189+
Array.prototype.reduceRight = function(fun /*, initial*/) {
190+
var len = this.length >>> 0;
191+
if (typeof fun != "function")
192+
throw new TypeError();
193+
194+
// no value to return if no initial value, empty array
195+
if (len == 0 && arguments.length == 1)
196+
throw new TypeError();
197+
198+
var i = len - 1;
199+
if (arguments.length >= 2) {
200+
var rv = arguments[1];
201+
} else {
202+
do {
203+
if (i in this) {
204+
rv = this[i--];
205+
break;
206+
}
207+
208+
// if array contains no values, no initial value to return
209+
if (--i < 0)
210+
throw new TypeError();
211+
} while (true);
212+
}
213+
214+
for (; i >= 0; i--) {
215+
if (i in this)
216+
rv = fun.call(null, rv, this[i], i, this);
217+
}
218+
219+
return rv;
220+
};
221+
}
222+
223+
if(!Array.prototype.indexOf){
224+
Array.prototype.indexOf = function(obj){
225+
for(var i=0; i<this.length; i++){
226+
if(this[i]==obj){
227+
return i;
228+
}
229+
}
230+
return -1;
231+
}
232+
}

0 commit comments

Comments
 (0)