Browse Source

Parse stx.

Herbert Vojčík 7 years ago
parent
commit
689cc2ee69
6 changed files with 585 additions and 109 deletions
  1. 1 1
      Gruntfile.js
  2. 178 0
      src/Compiler-STX.js
  3. 46 0
      src/Compiler-STX.st
  4. 1 0
      support/lang.js
  5. 333 107
      support/parser.js
  6. 26 1
      support/parser.pegjs

+ 1 - 1
Gruntfile.js

@@ -48,7 +48,7 @@ module.exports = function (grunt) {
                     'src/Kernel-Infrastructure.st', 'src/Kernel-Promises.st', 'src/Kernel-Exceptions.st', 'src/Kernel-Announcements.st',
                     'src/Platform-Services.st', 'src/Platform-ImportExport.st', 'src/Platform-Browser.st', 'src/Platform-Node.st',
                     'src/Platform-DOM.st',
-                    'src/Kernel-Dag.st', 'src/Compiler-Core.st', 'src/Compiler-AST.st',
+                    'src/Kernel-Dag.st', 'src/Compiler-Core.st', 'src/Compiler-AST.st', 'src/Compiler-STX.st',
                     'src/Compiler-IR.st', 'src/Compiler-Inlining.st', 'src/Compiler-Semantic.st', 'src/Compiler-Interpreter.st',
                     'src/SUnit.st',
                     'src/Kernel-Tests.st', 'src/Compiler-Tests.st', 'src/Platform-DOM-Tests.st', 'src/SUnit-Tests.st'

+ 178 - 0
src/Compiler-STX.js

@@ -0,0 +1,178 @@
+define(["amber/boot", "amber_core/Compiler-AST"], function($boot){"use strict";
+if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
+var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
+if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
+$core.addPackage("Compiler-STX");
+$core.packages["Compiler-STX"].innerEval = function (expr) { return eval(expr); };
+$core.packages["Compiler-STX"].transport = {"type":"amd","amdNamespace":"amber_core"};
+
+$core.addClass("StxNode", $globals.ASTNode, ["tag", "attributes", "children"], "Compiler-STX");
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.StxNode.comment="I represent an assignment node.";
+//>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "acceptDagVisitor:",
+protocol: "visiting",
+fn: function (aVisitor){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv(aVisitor)._visitDagNode_(self);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"acceptDagVisitor:",{aVisitor:aVisitor},$globals.StxNode)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aVisitor"],
+source: "acceptDagVisitor: aVisitor\x0a\x09^ aVisitor visitDagNode: self",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["visitDagNode:"]
+}),
+$globals.StxNode);
+
+$core.addMethod(
+$core.method({
+selector: "attributes",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+return $self["@attributes"];
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "attributes\x0a\x09^ attributes",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.StxNode);
+
+$core.addMethod(
+$core.method({
+selector: "attributes:",
+protocol: "accessing",
+fn: function (anObject){
+var self=this,$self=this;
+$self["@attributes"]=anObject;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "attributes: anObject\x0a\x09attributes := anObject",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.StxNode);
+
+$core.addMethod(
+$core.method({
+selector: "children",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+return $self["@children"];
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "children\x0a\x09^ children",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.StxNode);
+
+$core.addMethod(
+$core.method({
+selector: "children:",
+protocol: "accessing",
+fn: function (anObject){
+var self=this,$self=this;
+$self["@children"]=anObject;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "children: anObject\x0a\x09children := anObject",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.StxNode);
+
+$core.addMethod(
+$core.method({
+selector: "dagChildren",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+$1=[$self._tag()];
+$recv($1)._addAll_($self._attributes());
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["addAll:"]=1;
+//>>excludeEnd("ctx");
+$recv($1)._addAll_($self._children());
+return $recv($1)._yourself();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.StxNode)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "dagChildren\x0a\x09^ { self tag }\x0a\x09\x09addAll: self attributes;\x0a\x09\x09addAll: self children;\x0a\x09\x09yourself",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["addAll:", "tag", "attributes", "children", "yourself"]
+}),
+$globals.StxNode);
+
+$core.addMethod(
+$core.method({
+selector: "tag",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+return $self["@tag"];
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "tag\x0a\x09^ tag",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.StxNode);
+
+$core.addMethod(
+$core.method({
+selector: "tag:",
+protocol: "accessing",
+fn: function (anObject){
+var self=this,$self=this;
+$self["@tag"]=anObject;
+return self;
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anObject"],
+source: "tag: anObject\x0a\x09tag := anObject",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: []
+}),
+$globals.StxNode);
+
+
+});

+ 46 - 0
src/Compiler-STX.st

@@ -0,0 +1,46 @@
+Smalltalk createPackage: 'Compiler-STX'!
+ASTNode subclass: #StxNode
+	instanceVariableNames: 'tag attributes children'
+	package: 'Compiler-STX'!
+!StxNode commentStamp!
+I represent an assignment node.!
+
+!StxNode methodsFor: 'accessing'!
+
+attributes
+	^ attributes
+!
+
+attributes: anObject
+	attributes := anObject
+!
+
+children
+	^ children
+!
+
+children: anObject
+	children := anObject
+!
+
+dagChildren
+	^ { self tag }
+		addAll: self attributes;
+		addAll: self children;
+		yourself
+!
+
+tag
+	^ tag
+!
+
+tag: anObject
+	tag := anObject
+! !
+
+!StxNode methodsFor: 'visiting'!
+
+acceptDagVisitor: aVisitor
+	^ aVisitor visitDagNode: self
+! !
+

+ 1 - 0
support/lang.js

@@ -8,6 +8,7 @@ define([
     'amber_core/Platform-ImportExport',
     'amber_core/Compiler-Core',
     'amber_core/Compiler-AST',
+    'amber_core/Compiler-STX',
     'amber_core/Compiler-Semantic',
     'amber_core/Compiler-IR',
     'amber_core/Compiler-Inlining',

File diff suppressed because it is too large
+ 333 - 107
support/parser.js


+ 26 - 1
support/parser.pegjs

@@ -107,7 +107,7 @@ pseudoVariable = val:(
 parseTimeLiteral =
 	pseudoVariable / number / literalArray / string / symbol / character
 
-runtimeLiteral = dynamicDictionary / dynamicArray / block
+runtimeLiteral = dynamicDictionary / dynamicArray / block / stx
 
 literal = runtimeLiteral / parseTimeLiteral
 
@@ -264,6 +264,31 @@ cascade =
 			._dagChildren_(messages);
 	}
 
+wsOperand = ws operand:operand {return operand;}
+
+wsKeyValueMessage = ws key:keyword value:wsOperand {
+	return $globals.SendNode._new()
+		._location_(location())
+		._source_(text())
+		._selector_(key)
+		._arguments_([value]);
+}
+
+wsRestrictedMessage = wsUnaryMessage / wsKeyValueMessage
+
+stx =
+	'<'
+	tag:wsOperand messages:wsRestrictedMessage*
+	operands:(ws '|' operands:wsOperand* {return operands;})?
+	ws '>' {
+		return $globals.StxNode._new()
+			._location_(location())
+			._source_(text())
+			._tag_(tag)
+			._attributes_(messages)
+			._children_(operands || []);
+	}
+
 jsStatement = pragmaJsStatement / legacyJsStatement
 
 legacyJsStatement =

Some files were not shown because too many files changed in this diff