2
0
Quellcode durchsuchen

Parser now uses globals; exports itself to SmalltalkParser

Herbert Vojčík vor 11 Jahren
Ursprung
Commit
ff34eaf586
6 geänderte Dateien mit 50 neuen und 46 gelöschten Zeilen
  1. 1 1
      Gruntfile.js
  2. 1 1
      grunt/tasks/grunt-peg.js
  3. 9 5
      js/Kernel-Infrastructure.js
  4. 1 1
      st/Kernel-Infrastructure.st
  5. 20 20
      support/parser.js
  6. 18 18
      support/parser.pegjs

+ 1 - 1
Gruntfile.js

@@ -18,7 +18,7 @@ module.exports = function(grunt) {
         options: {
           trackLineAndColumn: true,
           cache: true,
-          export_var: 'smalltalk.parser'
+          export_var: 'globals.SmalltalkParser'
         },
         src: 'support/parser.pegjs',
         dest: 'support/parser.js',

+ 1 - 1
grunt/tasks/grunt-peg.js

@@ -23,7 +23,7 @@ module.exports = function(grunt) {
       export_var: 'module.exports'
     });
     var parser = PEG.buildParser(grunt.file.read(this.data.src), options);
-    var content = 'define("amber_vm/parser", ["./smalltalk", "./nil"], function(smalltalk, nil) {\n'+options.export_var + ' = ' + parser.toSource() + ';\n});';
+    var content = 'define("amber_vm/parser", ["./globals", "./nil"], function(globals, nil) {\n'+options.export_var + ' = ' + parser.toSource() + ';\n});';
     grunt.file.write(this.data.dest, content);
   });
 };

+ 9 - 5
js/Kernel-Infrastructure.js

@@ -2385,12 +2385,16 @@ selector: "basicParse:",
 protocol: 'private',
 fn: function (aString){
 var self=this;
-return smalltalk.parser.parse(aString);
-return self},
+function $SmalltalkParser(){return globals.SmalltalkParser||(typeof SmalltalkParser=="undefined"?nil:SmalltalkParser)}
+return smalltalk.withContext(function($ctx1) { 
+var $1;
+$1=_st($SmalltalkParser())._parse_(aString);
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"basicParse:",{aString:aString},globals.SmalltalkImage)})},
 args: ["aString"],
-source: "basicParse: aString\x0a\x09<return smalltalk.parser.parse(aString)>",
-messageSends: [],
-referencedClasses: []
+source: "basicParse: aString\x0a\x09^ SmalltalkParser parse: aString",
+messageSends: ["parse:"],
+referencedClasses: ["SmalltalkParser"]
 }),
 globals.SmalltalkImage);
 

+ 1 - 1
st/Kernel-Infrastructure.st

@@ -1103,7 +1103,7 @@ basicCreatePackage: packageName
 !
 
 basicParse: aString
-	<return smalltalk.parser.parse(aString)>
+	^ SmalltalkParser parse: aString
 !
 
 createPackage: packageName properties: aDict

+ 20 - 20
support/parser.js

@@ -1,5 +1,5 @@
-define("amber_vm/parser", ["./smalltalk", "./nil"], function(smalltalk, nil) {
-smalltalk.parser = (function(){
+define("amber_vm/parser", ["./globals", "./nil"], function(globals, nil) {
+globals.SmalltalkParser = (function(){
   /*
    * Generated by PEG.js 0.7.0.
    *
@@ -756,7 +756,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, val) {
-                             return smalltalk.ValueNode._new()
+                             return globals.ValueNode._new()
                                     ._position_((line).__at(column))
                                     ._value_(val.join("").replace(/\"/ig, '"'));
                          })(pos0.offset, pos0.line, pos0.column, result0[1]);
@@ -848,7 +848,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, val) {
-                              return smalltalk.ValueNode._new()
+                              return globals.ValueNode._new()
                                      ._position_((line).__at(column))
                                      ._value_(val);
                           })(pos0.offset, pos0.line, pos0.column, result0);
@@ -888,7 +888,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, n) {
-                             return smalltalk.ValueNode._new()
+                             return globals.ValueNode._new()
                                     ._position_((line).__at(column))
                                     ._value_(n);
                          })(pos0.offset, pos0.line, pos0.column, result0);
@@ -1443,7 +1443,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, lits) {
-                             return smalltalk.ValueNode._new()
+                             return globals.ValueNode._new()
                                     ._position_((line).__at(column))
                                     ._value_(lits);
                          })(pos0.offset, pos0.line, pos0.column, result0[1]);
@@ -1537,7 +1537,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, expressions) {
-                             return smalltalk.DynamicArrayNode._new()
+                             return globals.DynamicArrayNode._new()
                                     ._position_((line).__at(column))
                                     ._nodes_(expressions);
                          })(pos0.offset, pos0.line, pos0.column, result0[2]);
@@ -1616,7 +1616,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, expressions) {
-                                return smalltalk.DynamicDictionaryNode._new()
+                                return globals.DynamicDictionaryNode._new()
                                        ._position_((line).__at(column))
                                        ._nodes_(expressions);
                             })(pos0.offset, pos0.line, pos0.column, result0[2]);
@@ -1698,7 +1698,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, val) {
-                               return smalltalk.ValueNode._new()
+                               return globals.ValueNode._new()
                                       ._position_((line).__at(column))
                                       ._value_(val);
                            })(pos0.offset, pos0.line, pos0.column, result0);
@@ -1807,7 +1807,7 @@ smalltalk.parser = (function(){
         result0 = parse_identifier();
         if (result0 !== null) {
           result0 = (function(offset, line, column, identifier) {
-                             return smalltalk.VariableNode._new()
+                             return globals.VariableNode._new()
                                     ._position_((line).__at(column))
                                     ._value_(identifier);
                          })(pos0.offset, pos0.line, pos0.column, result0);
@@ -2323,7 +2323,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, variable, expression) {
-                             return smalltalk.AssignmentNode._new()
+                             return globals.AssignmentNode._new()
                                     ._position_((line).__at(column))
                                     ._left_(variable)
                                     ._right_(expression);
@@ -2403,7 +2403,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, expression) {
-                             return smalltalk.ReturnNode._new()
+                             return globals.ReturnNode._new()
                                     ._position_((line).__at(column))
                                     ._nodes_([expression]);
                          })(pos0.offset, pos0.line, pos0.column, result0[2]);
@@ -3024,7 +3024,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, temps, statements) {
-                             return smalltalk.SequenceNode._new()
+                             return globals.SequenceNode._new()
                                     ._position_((line).__at(column))
                                     ._temps_(temps || [])
                                     ._nodes_(statements || []);
@@ -3117,7 +3117,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, params, sequence) {
-                             return smalltalk.BlockNode._new()
+                             return globals.BlockNode._new()
                                     ._position_((line).__at(column))
                                     ._parameters_(params || [])
                                     ._nodes_([sequence._asBlockSequenceNode()]);
@@ -3210,7 +3210,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, selector) {
-                             return smalltalk.SendNode._new()
+                             return globals.SendNode._new()
                                     ._position_((line).__at(column))
                                     ._selector_(selector);
                          })(pos0.offset, pos0.line, pos0.column, result0[1]);
@@ -3383,7 +3383,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, selector, arg) {
-                             return smalltalk.SendNode._new()
+                             return globals.SendNode._new()
                                     ._position_((line).__at(column))
                                     ._selector_(selector)
                                     ._arguments_([arg]);
@@ -3579,7 +3579,7 @@ smalltalk.parser = (function(){
                                   selector.push(pairs[i].key);
                                   args.push(pairs[i].arg);
                               }
-                              return smalltalk.SendNode._new()
+                              return globals.SendNode._new()
                                      ._position_((line).__at(column))
                                      ._selector_(selector.join(""))
                                      ._arguments_(args);
@@ -3806,7 +3806,7 @@ smalltalk.parser = (function(){
                              for(var i = 0; i < messages.length; i++) {
                                  cascade.push(messages[i]);
                              }
-                             return smalltalk.CascadeNode._new()
+                             return globals.CascadeNode._new()
                                     ._position_((line).__at(column))
                                     ._receiver_(send._receiver())
                                     ._nodes_(cascade);
@@ -3930,7 +3930,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, val) {
-                             return smalltalk.JSStatementNode._new()
+                             return globals.JSStatementNode._new()
                                     ._position_((line).__at(column))
                                     ._source_(val.join(""));
                          })(pos0.offset, pos0.line, pos0.column, result0[1]);
@@ -3999,7 +3999,7 @@ smalltalk.parser = (function(){
         }
         if (result0 !== null) {
           result0 = (function(offset, line, column, pattern, sequence) {
-                              return smalltalk.MethodNode._new()
+                              return globals.MethodNode._new()
                                      ._position_((line).__at(column))
                                      ._selector_(pattern[0])
                                      ._arguments_(pattern[1])

+ 18 - 18
support/parser.pegjs

@@ -8,7 +8,7 @@ keyword        = first:identifier last:[:] {return first + last;}
 selector      = first:[a-zA-Z] others:[a-zA-Z0-9\:]* {return first + others.join("");}
 className      = first:[A-Z] others:[a-zA-Z0-9]* {return first + others.join("");}
 string         = ['] val:(("''" {return "'";} / [^'])*) ['] {
-                     return smalltalk.ValueNode._new()
+                     return globals.ValueNode._new()
                             ._position_((line).__at(column))
                             ._value_(val.join("").replace(/\"/ig, '"'));
                  }
@@ -16,12 +16,12 @@ string         = ['] val:(("''" {return "'";} / [^'])*) ['] {
 symbol         = "#" rest:bareSymbol {return rest;}
 bareSymbol         = val:(selector / binarySelector / node:string {return node._value();})
                   {
-                      return smalltalk.ValueNode._new()
+                      return globals.ValueNode._new()
                              ._position_((line).__at(column))
                              ._value_(val);
                   }
 number         = n:(numberExp / hex / float / integer) {
-                     return smalltalk.ValueNode._new()
+                     return globals.ValueNode._new()
                             ._position_((line).__at(column))
                             ._value_(n);
                  }
@@ -33,17 +33,17 @@ integer        = neg:[-]?digits:[0-9]+ {return (parseInt(neg+digits.join(""), 10
 literalArray   = "#(" rest:literalArrayRest {return rest;}
 bareLiteralArray   = "(" rest:literalArrayRest {return rest;}
 literalArrayRest   = ws lits:(lit:(parseTimeLiteral / bareLiteralArray / bareSymbol) ws {return lit._value();})* ws ")" {
-                     return smalltalk.ValueNode._new()
+                     return globals.ValueNode._new()
                             ._position_((line).__at(column))
                             ._value_(lits);
                  }
 dynamicArray   = "{" ws expressions:expressions? ws "."? "}" {
-                     return smalltalk.DynamicArrayNode._new()
+                     return globals.DynamicArrayNode._new()
                             ._position_((line).__at(column))
                             ._nodes_(expressions);
                  }
 dynamicDictionary = "#{" ws expressions: expressions? ws "}" {
-                        return smalltalk.DynamicDictionaryNode._new()
+                        return globals.DynamicDictionaryNode._new()
                                ._position_((line).__at(column))
                                ._nodes_(expressions);
                     }
@@ -51,7 +51,7 @@ pseudoVariable = val:(
                    'true' {return true;}
                  / 'false' {return false;}
                  / 'nil' {return nil;}) {
-                       return smalltalk.ValueNode._new()
+                       return globals.ValueNode._new()
                               ._position_((line).__at(column))
                               ._value_(val);
                    }
@@ -61,7 +61,7 @@ literal        = runtimeLiteral / parseTimeLiteral
 
 
 variable       = identifier:identifier {
-                     return smalltalk.VariableNode._new()
+                     return globals.VariableNode._new()
                             ._position_((line).__at(column))
                             ._value_(identifier);
                  }
@@ -100,14 +100,14 @@ expressions    = first:expression others:expressionList* {
                  }
 
 assignment     = variable:variable ws ':=' ws expression:expression {
-                     return smalltalk.AssignmentNode._new()
+                     return globals.AssignmentNode._new()
                             ._position_((line).__at(column))
                             ._left_(variable)
                             ._right_(expression);
                  }
 
 ret            = '^' ws expression:expression ws '.'? {
-                     return smalltalk.ReturnNode._new()
+                     return globals.ReturnNode._new()
                             ._position_((line).__at(column))
                             ._nodes_([expression]);
                  }
@@ -131,7 +131,7 @@ statements     = ret:ret [.]* {return [ret];}
 sequence       = jsSequence / stSequence
 
 stSequence     = temps:temps? ws statements:statements? ws {
-                     return smalltalk.SequenceNode._new()
+                     return globals.SequenceNode._new()
                             ._position_((line).__at(column))
                             ._temps_(temps || [])
                             ._nodes_(statements || []);
@@ -140,7 +140,7 @@ stSequence     = temps:temps? ws statements:statements? ws {
 jsSequence     = jsStatement
 
 block          = '[' ws params:blockParamList? ws sequence:sequence? ws ']' {
-                     return smalltalk.BlockNode._new()
+                     return globals.BlockNode._new()
                             ._position_((line).__at(column))
                             ._parameters_(params || [])
                             ._nodes_([sequence._asBlockSequenceNode()]);
@@ -151,7 +151,7 @@ operand        = literal / reference / subexpression
 
 
 unaryMessage   = ws selector:unarySelector ![:] {
-                     return smalltalk.SendNode._new()
+                     return globals.SendNode._new()
                             ._position_((line).__at(column))
                             ._selector_(selector);
                  }
@@ -175,7 +175,7 @@ unarySend      = receiver:operand ws tail:unaryTail? {
                  }
 
 binaryMessage  = ws selector:binarySelector ws arg:(unarySend / operand) {
-                     return smalltalk.SendNode._new()
+                     return globals.SendNode._new()
                             ._position_((line).__at(column))
                             ._selector_(selector)
                             ._arguments_([arg]);
@@ -207,7 +207,7 @@ keywordMessage = ws pairs:(pair:keywordPair ws {return pair;})+ {
                           selector.push(pairs[i].key);
                           args.push(pairs[i].arg);
                       }
-                      return smalltalk.SendNode._new()
+                      return globals.SendNode._new()
                              ._position_((line).__at(column))
                              ._selector_(selector.join(""))
                              ._arguments_(args);
@@ -225,21 +225,21 @@ cascade        = ws send:(keywordSend / binarySend) messages:(ws ";" ws mess:mes
                      for(var i = 0; i < messages.length; i++) {
                          cascade.push(messages[i]);
                      }
-                     return smalltalk.CascadeNode._new()
+                     return globals.CascadeNode._new()
                             ._position_((line).__at(column))
                             ._receiver_(send._receiver())
                             ._nodes_(cascade);
                  }
 
 jsStatement    = "<" val:((">>" {return ">";} / [^>])*) ">" {
-                     return smalltalk.JSStatementNode._new()
+                     return globals.JSStatementNode._new()
                             ._position_((line).__at(column))
                             ._source_(val.join(""));
                  }
 
 
 method         = ws pattern:(keywordPattern / binaryPattern / unaryPattern) ws sequence:sequence? ws {
-                      return smalltalk.MethodNode._new()
+                      return globals.MethodNode._new()
                              ._position_((line).__at(column))
                              ._selector_(pattern[0])
                              ._arguments_(pattern[1])