resin 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,9 +48,9 @@ if (typeof console === "undefined") {
48
48
 
49
49
  /* Smalltalk constructors definition */
50
50
 
51
- function SmalltalkObject(){};
51
+ function SmalltalkObject(){}
52
52
  function SmalltalkBehavior(){};
53
- function SmalltalkClass(){};
53
+ function SmalltalkClass(){}
54
54
  function SmalltalkPackage(){};
55
55
  function SmalltalkMetaclass(){
56
56
  this.meta = true;
@@ -133,6 +133,7 @@ function Smalltalk(){
133
133
  that.fn = spec.fn || function(){};
134
134
  that.superclass = spec.superclass;
135
135
  that.iVarNames = spec.iVarNames || [];
136
+ that.toString = function() {return 'Smalltalk ' + that.className};
136
137
  if(that.superclass) {
137
138
  that.klass.superclass = that.superclass.klass;
138
139
  }
@@ -246,7 +247,7 @@ function Smalltalk(){
246
247
  /* Create a new class wrapping a JavaScript constructor, and add it to the
247
248
  global smalltalk object. Package is lazily created if it does not exist with given name. */
248
249
 
249
- st.mapClassName = function(className, pkgName, fn, superclass) {
250
+ st.wrapClassName = function(className, pkgName, fn, superclass) {
250
251
  var pkg = st.addPackage(pkgName);
251
252
  st[className] = klass({
252
253
  className: className,
@@ -256,6 +257,11 @@ function Smalltalk(){
256
257
  });
257
258
  };
258
259
 
260
+ /* Create an alias for an existing class */
261
+ st.alias = function(klass, alias) {
262
+ st[alias] = klass;
263
+ }
264
+
259
265
  /* Add a package to the smalltalk.packages object, creating a new one if needed.
260
266
  If pkgName is null or empty we return nil, which is an allowed package for a class.
261
267
  If package already exists we still update the properties of it. */
@@ -390,6 +396,10 @@ function Smalltalk(){
390
396
  /* Call a method of a JS object, or answer a property if it exists.
391
397
  Else try wrapping a JSObjectProxy around the receiver.
392
398
 
399
+ If the object property is a function, then call it, except if it starts with
400
+ an uppercase character (we probably want to answer the function itself in this
401
+ case and send it #new from Amber).
402
+
393
403
  Converts keyword-based selectors by using the first
394
404
  keyword only, but keeping all message arguments.
395
405
 
@@ -399,14 +409,14 @@ function Smalltalk(){
399
409
  function callJavaScriptMethod(receiver, selector, args) {
400
410
  var jsSelector = selector._asJavaScriptSelector();
401
411
  var jsProperty = receiver[jsSelector];
402
- if(typeof jsProperty === "function") {
412
+ if(typeof jsProperty === "function" && !/^[A-Z]/.test(jsSelector)) {
403
413
  return jsProperty.apply(receiver, args);
404
414
  } else if(jsProperty !== undefined) {
405
415
  if(args[0]) {
406
416
  receiver[jsSelector] = args[0];
407
417
  return nil;
408
418
  } else {
409
- return jsProperty
419
+ return jsProperty;
410
420
  }
411
421
  }
412
422
 
@@ -556,32 +566,37 @@ if(this.jQuery) {
556
566
  /****************************************************************************************/
557
567
 
558
568
 
559
- /* Base classes mapping. If you edit this part, do not forget to set the superclass of the
569
+ /* Base classes wrapping. If you edit this part, do not forget to set the superclass of the
560
570
  object metaclass to Class after the definition of Object */
561
571
 
562
- smalltalk.mapClassName("Object", "Kernel", SmalltalkObject);
563
- smalltalk.mapClassName("Smalltalk", "Kernel", Smalltalk, smalltalk.Object);
564
- smalltalk.mapClassName("Package", "Kernel", SmalltalkPackage, smalltalk.Object);
565
- smalltalk.mapClassName("Behavior", "Kernel", SmalltalkBehavior, smalltalk.Object);
566
- smalltalk.mapClassName("Class", "Kernel", SmalltalkClass, smalltalk.Behavior);
567
- smalltalk.mapClassName("Metaclass", "Kernel", SmalltalkMetaclass, smalltalk.Behavior);
568
- smalltalk.mapClassName("CompiledMethod", "Kernel", SmalltalkMethod, smalltalk.Object);
572
+ smalltalk.wrapClassName("Object", "Kernel", SmalltalkObject);
573
+ smalltalk.wrapClassName("Smalltalk", "Kernel", Smalltalk, smalltalk.Object);
574
+ smalltalk.wrapClassName("Package", "Kernel", SmalltalkPackage, smalltalk.Object);
575
+ smalltalk.wrapClassName("Behavior", "Kernel", SmalltalkBehavior, smalltalk.Object);
576
+ smalltalk.wrapClassName("Class", "Kernel", SmalltalkClass, smalltalk.Behavior);
577
+ smalltalk.wrapClassName("Metaclass", "Kernel", SmalltalkMetaclass, smalltalk.Behavior);
578
+ smalltalk.wrapClassName("CompiledMethod", "Kernel", SmalltalkMethod, smalltalk.Object);
569
579
 
570
580
  smalltalk.Object.klass.superclass = smalltalk.Class;
571
581
 
572
- smalltalk.mapClassName("Number", "Kernel", Number, smalltalk.Object);
573
- smalltalk.mapClassName("BlockClosure", "Kernel", Function, smalltalk.Object);
574
- smalltalk.mapClassName("Boolean", "Kernel", Boolean, smalltalk.Object);
575
- smalltalk.mapClassName("Date", "Kernel", Date, smalltalk.Object);
576
- smalltalk.mapClassName("UndefinedObject", "Kernel", SmalltalkNil, smalltalk.Object);
577
-
578
- smalltalk.mapClassName("Collection", "Kernel", null, smalltalk.Object);
579
- smalltalk.mapClassName("SequenceableCollection", "Kernel", null, smalltalk.Collection);
580
- smalltalk.mapClassName("CharacterArray", "Kernel", null, smalltalk.SequenceableCollection);
581
- smalltalk.mapClassName("String", "Kernel", String, smalltalk.CharacterArray);
582
- smalltalk.mapClassName("Symbol", "Kernel", SmalltalkSymbol, smalltalk.CharacterArray);
583
- smalltalk.mapClassName("Array", "Kernel", Array, smalltalk.SequenceableCollection);
584
- smalltalk.mapClassName("RegularExpression", "Kernel", RegExp, smalltalk.String);
585
-
586
- smalltalk.mapClassName("Error", "Kernel", Error, smalltalk.Object);
587
- smalltalk.mapClassName("MethodContext", "Kernel", SmalltalkMethodContext, smalltalk.Object);
582
+ smalltalk.wrapClassName("Number", "Kernel", Number, smalltalk.Object);
583
+ smalltalk.wrapClassName("BlockClosure", "Kernel", Function, smalltalk.Object);
584
+ smalltalk.wrapClassName("Boolean", "Kernel", Boolean, smalltalk.Object);
585
+ smalltalk.wrapClassName("Date", "Kernel", Date, smalltalk.Object);
586
+ smalltalk.wrapClassName("UndefinedObject", "Kernel", SmalltalkNil, smalltalk.Object);
587
+
588
+ smalltalk.wrapClassName("Collection", "Kernel", null, smalltalk.Object);
589
+ smalltalk.wrapClassName("SequenceableCollection", "Kernel", null, smalltalk.Collection);
590
+ smalltalk.wrapClassName("CharacterArray", "Kernel", null, smalltalk.SequenceableCollection);
591
+ smalltalk.wrapClassName("String", "Kernel", String, smalltalk.CharacterArray);
592
+ smalltalk.wrapClassName("Symbol", "Kernel", SmalltalkSymbol, smalltalk.CharacterArray);
593
+ smalltalk.wrapClassName("Array", "Kernel", Array, smalltalk.SequenceableCollection);
594
+ smalltalk.wrapClassName("RegularExpression", "Kernel", RegExp, smalltalk.String);
595
+
596
+ smalltalk.wrapClassName("Error", "Kernel", Error, smalltalk.Object);
597
+ smalltalk.wrapClassName("MethodContext", "Kernel", SmalltalkMethodContext, smalltalk.Object);
598
+
599
+ /* Alias definitions */
600
+
601
+ smalltalk.alias(smalltalk.Array, "OrderedCollection");
602
+ smalltalk.alias(smalltalk.Date, "Time");
@@ -56,6 +56,7 @@ smalltalk.parser = (function(){
56
56
  "unaryPattern": parse_unaryPattern,
57
57
  "unarySend": parse_unarySend,
58
58
  "unaryTail": parse_unaryTail,
59
+ "varIdentifier": parse_varIdentifier,
59
60
  "variable": parse_variable,
60
61
  "ws": parse_ws
61
62
  };
@@ -368,6 +369,78 @@ smalltalk.parser = (function(){
368
369
  }
369
370
 
370
371
 
372
+ var savedPos0 = pos;
373
+ var savedPos1 = pos;
374
+ if (input.substr(pos).match(/^[a-zA-Z]/) !== null) {
375
+ var result3 = input.charAt(pos);
376
+ pos++;
377
+ } else {
378
+ var result3 = null;
379
+ if (reportMatchFailures) {
380
+ matchFailed("[a-zA-Z]");
381
+ }
382
+ }
383
+ if (result3 !== null) {
384
+ var result4 = [];
385
+ if (input.substr(pos).match(/^[a-zA-Z0-9]/) !== null) {
386
+ var result5 = input.charAt(pos);
387
+ pos++;
388
+ } else {
389
+ var result5 = null;
390
+ if (reportMatchFailures) {
391
+ matchFailed("[a-zA-Z0-9]");
392
+ }
393
+ }
394
+ while (result5 !== null) {
395
+ result4.push(result5);
396
+ if (input.substr(pos).match(/^[a-zA-Z0-9]/) !== null) {
397
+ var result5 = input.charAt(pos);
398
+ pos++;
399
+ } else {
400
+ var result5 = null;
401
+ if (reportMatchFailures) {
402
+ matchFailed("[a-zA-Z0-9]");
403
+ }
404
+ }
405
+ }
406
+ if (result4 !== null) {
407
+ var result1 = [result3, result4];
408
+ } else {
409
+ var result1 = null;
410
+ pos = savedPos1;
411
+ }
412
+ } else {
413
+ var result1 = null;
414
+ pos = savedPos1;
415
+ }
416
+ var result2 = result1 !== null
417
+ ? (function(first, others) {return first + others.join("")})(result1[0], result1[1])
418
+ : null;
419
+ if (result2 !== null) {
420
+ var result0 = result2;
421
+ } else {
422
+ var result0 = null;
423
+ pos = savedPos0;
424
+ }
425
+
426
+
427
+
428
+ cache[cacheKey] = {
429
+ nextPos: pos,
430
+ result: result0
431
+ };
432
+ return result0;
433
+ }
434
+
435
+ function parse_varIdentifier() {
436
+ var cacheKey = 'varIdentifier@' + pos;
437
+ var cachedResult = cache[cacheKey];
438
+ if (cachedResult) {
439
+ pos = cachedResult.nextPos;
440
+ return cachedResult.result;
441
+ }
442
+
443
+
371
444
  var savedPos0 = pos;
372
445
  var savedPos1 = pos;
373
446
  if (input.substr(pos).match(/^[a-z]/) !== null) {
@@ -721,25 +794,119 @@ smalltalk.parser = (function(){
721
794
  }
722
795
  if (result3 !== null) {
723
796
  var result4 = [];
724
- if (input.substr(pos).match(/^[a-zA-Z0-9]/) !== null) {
725
- var result5 = input.charAt(pos);
797
+ var savedPos3 = pos;
798
+ if (input.substr(pos).match(/^[a-zA-Z0-9:]/) !== null) {
799
+ var result12 = input.charAt(pos);
726
800
  pos++;
727
801
  } else {
728
- var result5 = null;
802
+ var result12 = null;
729
803
  if (reportMatchFailures) {
730
- matchFailed("[a-zA-Z0-9]");
804
+ matchFailed("[a-zA-Z0-9:]");
731
805
  }
732
806
  }
807
+ if (result12 !== null) {
808
+ var result10 = [];
809
+ while (result12 !== null) {
810
+ result10.push(result12);
811
+ if (input.substr(pos).match(/^[a-zA-Z0-9:]/) !== null) {
812
+ var result12 = input.charAt(pos);
813
+ pos++;
814
+ } else {
815
+ var result12 = null;
816
+ if (reportMatchFailures) {
817
+ matchFailed("[a-zA-Z0-9:]");
818
+ }
819
+ }
820
+ }
821
+ } else {
822
+ var result10 = null;
823
+ }
824
+ var result11 = result10 !== null
825
+ ? (function(digits) {return digits.join("")})(result10)
826
+ : null;
827
+ if (result11 !== null) {
828
+ var result9 = result11;
829
+ } else {
830
+ var result9 = null;
831
+ pos = savedPos3;
832
+ }
833
+ if (result9 !== null) {
834
+ var result5 = result9;
835
+ } else {
836
+ var savedPos2 = pos;
837
+ var result7 = parse_string();
838
+ var result8 = result7 !== null
839
+ ? (function(node) {return node._value()})(result7)
840
+ : null;
841
+ if (result8 !== null) {
842
+ var result6 = result8;
843
+ } else {
844
+ var result6 = null;
845
+ pos = savedPos2;
846
+ }
847
+ if (result6 !== null) {
848
+ var result5 = result6;
849
+ } else {
850
+ var result5 = null;;
851
+ };
852
+ }
733
853
  while (result5 !== null) {
734
854
  result4.push(result5);
735
- if (input.substr(pos).match(/^[a-zA-Z0-9]/) !== null) {
736
- var result5 = input.charAt(pos);
855
+ var savedPos3 = pos;
856
+ if (input.substr(pos).match(/^[a-zA-Z0-9:]/) !== null) {
857
+ var result12 = input.charAt(pos);
737
858
  pos++;
738
859
  } else {
739
- var result5 = null;
860
+ var result12 = null;
740
861
  if (reportMatchFailures) {
741
- matchFailed("[a-zA-Z0-9]");
862
+ matchFailed("[a-zA-Z0-9:]");
863
+ }
864
+ }
865
+ if (result12 !== null) {
866
+ var result10 = [];
867
+ while (result12 !== null) {
868
+ result10.push(result12);
869
+ if (input.substr(pos).match(/^[a-zA-Z0-9:]/) !== null) {
870
+ var result12 = input.charAt(pos);
871
+ pos++;
872
+ } else {
873
+ var result12 = null;
874
+ if (reportMatchFailures) {
875
+ matchFailed("[a-zA-Z0-9:]");
876
+ }
877
+ }
742
878
  }
879
+ } else {
880
+ var result10 = null;
881
+ }
882
+ var result11 = result10 !== null
883
+ ? (function(digits) {return digits.join("")})(result10)
884
+ : null;
885
+ if (result11 !== null) {
886
+ var result9 = result11;
887
+ } else {
888
+ var result9 = null;
889
+ pos = savedPos3;
890
+ }
891
+ if (result9 !== null) {
892
+ var result5 = result9;
893
+ } else {
894
+ var savedPos2 = pos;
895
+ var result7 = parse_string();
896
+ var result8 = result7 !== null
897
+ ? (function(node) {return node._value()})(result7)
898
+ : null;
899
+ if (result8 !== null) {
900
+ var result6 = result8;
901
+ } else {
902
+ var result6 = null;
903
+ pos = savedPos2;
904
+ }
905
+ if (result6 !== null) {
906
+ var result5 = result6;
907
+ } else {
908
+ var result5 = null;;
909
+ };
743
910
  }
744
911
  }
745
912
  if (result4 !== null) {
@@ -754,8 +921,8 @@ smalltalk.parser = (function(){
754
921
  }
755
922
  var result2 = result1 !== null
756
923
  ? (function(val) {
757
- return smalltalk.ValueNode._new()
758
- ._value_(smalltalk.symbolFor(val.join("").replace(/\"/ig, '"')))
924
+ return smalltalk.ValueNode._new()
925
+ ._value_(smalltalk.symbolFor(val.join("").replace(/\"/ig, '"')))
759
926
  })(result1[1])
760
927
  : null;
761
928
  if (result2 !== null) {
@@ -829,17 +996,42 @@ smalltalk.parser = (function(){
829
996
  var savedPos0 = pos;
830
997
  var savedPos1 = pos;
831
998
  if (input.substr(pos).match(/^[\-]/) !== null) {
832
- var result7 = input.charAt(pos);
999
+ var result9 = input.charAt(pos);
833
1000
  pos++;
834
1001
  } else {
835
- var result7 = null;
1002
+ var result9 = null;
836
1003
  if (reportMatchFailures) {
837
1004
  matchFailed("[\\-]");
838
1005
  }
839
1006
  }
840
- var result3 = result7 !== null ? result7 : '';
1007
+ var result3 = result9 !== null ? result9 : '';
841
1008
  if (result3 !== null) {
842
- var result4 = parse_integer();
1009
+ if (input.substr(pos).match(/^[0-9]/) !== null) {
1010
+ var result8 = input.charAt(pos);
1011
+ pos++;
1012
+ } else {
1013
+ var result8 = null;
1014
+ if (reportMatchFailures) {
1015
+ matchFailed("[0-9]");
1016
+ }
1017
+ }
1018
+ if (result8 !== null) {
1019
+ var result4 = [];
1020
+ while (result8 !== null) {
1021
+ result4.push(result8);
1022
+ if (input.substr(pos).match(/^[0-9]/) !== null) {
1023
+ var result8 = input.charAt(pos);
1024
+ pos++;
1025
+ } else {
1026
+ var result8 = null;
1027
+ if (reportMatchFailures) {
1028
+ matchFailed("[0-9]");
1029
+ }
1030
+ }
1031
+ }
1032
+ } else {
1033
+ var result4 = null;
1034
+ }
843
1035
  if (result4 !== null) {
844
1036
  if (input.substr(pos, 1) === ".") {
845
1037
  var result5 = ".";
@@ -851,7 +1043,32 @@ smalltalk.parser = (function(){
851
1043
  }
852
1044
  }
853
1045
  if (result5 !== null) {
854
- var result6 = parse_integer();
1046
+ if (input.substr(pos).match(/^[0-9]/) !== null) {
1047
+ var result7 = input.charAt(pos);
1048
+ pos++;
1049
+ } else {
1050
+ var result7 = null;
1051
+ if (reportMatchFailures) {
1052
+ matchFailed("[0-9]");
1053
+ }
1054
+ }
1055
+ if (result7 !== null) {
1056
+ var result6 = [];
1057
+ while (result7 !== null) {
1058
+ result6.push(result7);
1059
+ if (input.substr(pos).match(/^[0-9]/) !== null) {
1060
+ var result7 = input.charAt(pos);
1061
+ pos++;
1062
+ } else {
1063
+ var result7 = null;
1064
+ if (reportMatchFailures) {
1065
+ matchFailed("[0-9]");
1066
+ }
1067
+ }
1068
+ }
1069
+ } else {
1070
+ var result6 = null;
1071
+ }
855
1072
  if (result6 !== null) {
856
1073
  var result1 = [result3, result4, result5, result6];
857
1074
  } else {
@@ -871,7 +1088,7 @@ smalltalk.parser = (function(){
871
1088
  pos = savedPos1;
872
1089
  }
873
1090
  var result2 = result1 !== null
874
- ? (function(neg, int, dec) {return parseFloat((neg+int+"."+dec), 10)})(result1[0], result1[1], result1[3])
1091
+ ? (function(neg, int, dec) {return parseFloat((neg + int.join("") + "." + dec.join("")), 10)})(result1[0], result1[1], result1[3])
875
1092
  : null;
876
1093
  if (result2 !== null) {
877
1094
  var result0 = result2;
@@ -1430,7 +1647,7 @@ smalltalk.parser = (function(){
1430
1647
 
1431
1648
 
1432
1649
  var savedPos0 = pos;
1433
- var result1 = parse_identifier();
1650
+ var result1 = parse_varIdentifier();
1434
1651
  var result2 = result1 !== null
1435
1652
  ? (function(identifier) {
1436
1653
  return smalltalk.VariableNode._new()
@@ -3,7 +3,8 @@ start = method
3
3
  separator = [ \t\v\f\u00A0\uFEFF\n\r\u2028\u2029]+
4
4
  comments = (["][^"]*["])+
5
5
  ws = (separator / comments)*
6
- identifier = first:[a-z] others:[a-zA-Z0-9]* {return first + others.join("")}
6
+ identifier = first:[a-zA-Z] others:[a-zA-Z0-9]* {return first + others.join("")}
7
+ varIdentifier = first:[a-z] others:[a-zA-Z0-9]* {return first + others.join("")}
7
8
  keyword = first:identifier last:[:] {return first + last}
8
9
  className = first:[A-Z] others:[a-zA-Z0-9]* {return first + others.join("")}
9
10
  string = ['] val:(("''" {return "'"} / [^'])*) ['] {
@@ -11,15 +12,17 @@ string = ['] val:(("''" {return "'"} / [^'])*) ['] {
11
12
  ._value_(val.join("").replace(/\"/ig, '"'))
12
13
  }
13
14
 
14
- symbol = "#"val:[a-zA-Z0-9]* {
15
- return smalltalk.ValueNode._new()
16
- ._value_('smalltalk.symbolFor(val.join("").replace(/\"/ig, '"')))
15
+ symbol = "#"val:(
16
+ digits:[a-zA-Z0-9\:]+ {return digits.join("")} /
17
+ node:string {return node._value()})* {
18
+ return smalltalk.ValueNode._new()
19
+ ._value_(smalltalk.symbolFor(val.join("").replace(/\"/ig, '"')))
17
20
  }
18
21
  number = n:(float / integer) {
19
22
  return smalltalk.ValueNode._new()
20
23
  ._value_(n)
21
24
  }
22
- float = neg:[-]?int:integer "." dec:integer {return parseFloat((neg+int+"."+dec), 10)}
25
+ float = neg:[-]?int:[0-9]+ "." dec:[0-9]+ {return parseFloat((neg + int.join("") + "." + dec.join("")), 10)}
23
26
  integer = neg:[-]?digits:[0-9]+ {return (parseInt(neg+digits.join(""), 10))}
24
27
  literalArray = "#(" ws lits:(lit:literal ws {return lit._value()})* ws ")" {
25
28
  return smalltalk.ValueNode._new()
@@ -42,7 +45,7 @@ pseudoVariable = val:(
42
45
  literal = pseudoVariable / number / literalArray / dynamicDictionary / dynamicArray / string / symbol / block
43
46
 
44
47
 
45
- variable = identifier:identifier {
48
+ variable = identifier:varIdentifier {
46
49
  return smalltalk.VariableNode._new()
47
50
  ._value_(identifier)
48
51
  }