Pārlūkot izejas kodu

js -> eberon transition

Vladislav Folts 9 gadi atpakaļ
vecāks
revīzija
69bba9f51d

BIN
bin/compiled.zip


+ 2 - 2
build.py

@@ -130,9 +130,9 @@ def recompile(bin):
     sources = ['ContextAssignment.ob', 'ContextCase.ob', 
                'ContextIdentdef.ob', 'ContextModule.ob', 
                'EberonSymbols.ob', 'EberonCast.ob', 
-               'EberonContextExpression.ob', 'EberonContextIdentdef.ob', 'EberonContextIf.ob', 
+               'EberonContextCase.ob', 'EberonContextExpression.ob', 'EberonContextIdentdef.ob', 'EberonContextIf.ob', 
                'EberonContextInPlace.ob', 'EberonContextLoop.ob', 'EberonContextType.ob', 
-               'EberonContextVar.ob', 'EberonOperatorScopes.ob',
+               'EberonContextVar.ob',
                'OberonContext.ob', 'OberonContextType.ob', 'OberonContextVar.ob',
                'OberonSymbols.ob', 'Lexer.ob', 'Module.ob']
     

+ 21 - 0
src/eberon/EberonContextCase.ob

@@ -0,0 +1,21 @@
+MODULE EberonContextCase;
+IMPORT
+    ContextCase, EberonScope;
+TYPE
+    Label* = RECORD(ContextCase.Label)
+    END;
+
+PROCEDURE Label.handleLiteral(s: STRING);
+BEGIN
+    IF s = ":" THEN (* statement sequence is expected now *)
+        EberonScope.startOperatorScope(SELF);
+    END;
+END;
+
+PROCEDURE Label.endParse(): BOOLEAN;
+BEGIN
+    EberonScope.endOperatorScope(SELF);
+    RETURN SUPER();
+END;
+
+END EberonContextCase.

+ 4 - 18
src/eberon/EberonContextLoop.ob

@@ -65,36 +65,22 @@ BEGIN
     RETURN SUPER();
 END;
 
-PROCEDURE startLoopScope(cx: ContextHierarchy.Node);
-BEGIN
-    root <- cx.root();
-    scope <- EberonScope.makeOperator(
-        root.currentScope(),
-        root.language().stdSymbols);
-    root.pushScope(scope);
-END;
-
-PROCEDURE endLoopScope(cx: ContextHierarchy.Node);
-BEGIN
-    cx.root().popScope();
-END;
-
 PROCEDURE Repeat.Repeat(parent: ContextHierarchy.PNode)
     | SUPER(parent);
 BEGIN
-    startLoopScope(SELF);
+    EberonScope.startOperatorScope(SELF);
 END;
 
 PROCEDURE Repeat.endParse(): BOOLEAN;
 BEGIN
-    endLoopScope(SELF);
+    EberonScope.endOperatorScope(SELF);
     RETURN TRUE;
 END;
 
 PROCEDURE For.For(parent: ContextHierarchy.PNode)
     | SUPER(parent);
 BEGIN
-    startLoopScope(SELF);
+    EberonScope.startOperatorScope(SELF);
 END;
 
 PROCEDURE For.handleInPlaceInit(symbol: Symbols.PSymbol; code: STRING);
@@ -105,7 +91,7 @@ END;
 
 PROCEDURE For.endParse(): BOOLEAN;
 BEGIN
-    endLoopScope(SELF);
+    EberonScope.endOperatorScope(SELF);
     RETURN SUPER();
 END;
 

+ 16 - 1
src/eberon/EberonScope.ob

@@ -1,5 +1,6 @@
 MODULE EberonScope;
-IMPORT Errors, Scope, Symbols;
+IMPORT 
+    ContextHierarchy, Errors, Scope, Symbols;
 TYPE
     Operator = RECORD(Scope.Type)
         parent: Scope.PType
@@ -41,4 +42,18 @@ BEGIN
     RETURN result
 END;
 
+PROCEDURE startOperatorScope*(cx: ContextHierarchy.Node);
+BEGIN
+    root <- cx.root();
+    scope <- makeOperator(
+        root.currentScope(),
+        root.language().stdSymbols);
+    root.pushScope(scope);
+END;
+
+PROCEDURE endOperatorScope*(cx: ContextHierarchy.Node);
+BEGIN
+    cx.root().popScope();
+END;
+
 END EberonScope.

+ 0 - 20
src/eberon/eberon_context.js

@@ -52,25 +52,6 @@ var ChainedContext = ContextHierarchy.Node;
 ChainedContext.extend = Class.extend;
 ChainedContext.prototype.init = ContextHierarchy.Node;
 
-var CaseLabel = Class.extend.call(ContextCase.Label, {
-    init: function EberonContext$CaseLabel(context){
-        ContextCase.Label.call(this, context);
-    },
-    handleLiteral: function(s){
-        if (s == ':'){ // statement sequence is expected now
-            var root = this.root();
-            var scope = EberonScope.makeOperator(
-                root.currentScope(),
-                root.language().stdSymbols);
-            root.pushScope(scope);
-        }
-    },
-    endParse: function(){
-        this.root().popScope();
-        ContextCase.Label.prototype.endParse.call(this);
-    }
-});
-
 var MapDecl = ChainedContext.extend({
     init: function EberonContext$MapDecl(context){
         ChainedContext.prototype.init.call(this, context);
@@ -174,7 +155,6 @@ var ModuleDeclaration = Class.extend.call(ContextModule.Declaration, {
     }
 });
 
-exports.CaseLabel = CaseLabel;
 exports.FormalParameters = FormalParameters;
 exports.FormalParametersProcDecl = FormalParametersProcDecl;
 exports.FormalType = FormalType;

+ 2 - 1
src/eberon/eberon_grammar.js

@@ -6,6 +6,7 @@ var CodeGenerator = require("js/CodeGenerator.js");
 var ContextType = require("js/ContextType.js");
 var EbContext = require("eberon/eberon_context.js");
 var EberonContext = require("js/EberonContext.js");
+var EberonContextCase = require("js/EberonContextCase.js");
 var EberonContextDesignator = require("js/EberonContextDesignator.js");
 var EberonContextExpression = require("js/EberonContextExpression.js");
 var EberonContextIdentdef = require("js/EberonContextIdentdef.js");
@@ -164,7 +165,7 @@ exports.language = {
             For:                EberonContextLoop.For,
             While:              EberonContextLoop.While,
             If:                 EberonContextIf.Type,
-            CaseLabel:          EbContext.CaseLabel,
+            CaseLabel:          EberonContextCase.Label,
             Repeat:             EberonContextLoop.Repeat,
             ModuleDeclaration:  EbContext.ModuleDeclaration
         },