Procházet zdrojové kódy

Get rid of JS in Lexer.

Vladislav Folts před 10 roky
rodič
revize
ab8dd0cfeb
5 změnil soubory, kde provedl 32 přidání a 22 odebrání
  1. binární
      bin/compiled.zip
  2. 22 7
      src/context.js
  3. 1 1
      src/grammar.js
  4. 1 1
      src/ob/Context.ob
  5. 8 13
      src/ob/Lexer.ob

binární
bin/compiled.zip


+ 22 - 7
src/context.js

@@ -239,6 +239,25 @@ exports.BaseType = ChainedContext.extend({
     }
 });
 
+exports.QualifiedIdentificatorModule = ChainedContext.extend({
+    init: function QualifiedIdentificatorModule(context){
+        ChainedContext.prototype.init.call(this, context);
+        this.__id = undefined;
+    },
+    handleIdent: function(id){
+        this.__id = id;
+    },
+    endParse: function(){
+        var found = this.findSymbol(this.__id);
+        if (!found)
+            return false;
+        var s = found.symbol();
+        if (!s || !s.isModule())
+            return false;
+        this.parent().handleModule(this.__id, s.info());
+    }
+});
+
 exports.QualifiedIdentificator = ChainedContext.extend({
     init: function QualifiedIdentificator(context){
         ChainedContext.prototype.init.call(this, context);
@@ -249,13 +268,9 @@ exports.QualifiedIdentificator = ChainedContext.extend({
     handleIdent: function(id){
         this.__id = id;
     },
-    handleLiteral: function(){
-        var s = getSymbol(this, this.__id);
-        if (!s.isModule())
-            return false; // stop parsing
-        this.__module = s.info();
-        this.__code = this.__id + ".";
-        return undefined;
+    handleModule: function(id, module){
+        this.__module = module;
+        this.__code = id + ".";
     },
     endParse: function(){
         var code = this.__code ? this.__code + Type.mangleJSProperty(this.__id) : this.__id;

+ 1 - 1
src/grammar.js

@@ -44,7 +44,7 @@ var ident = function(stream, context){
     return Lexer.ident(stream, context, reservedWords);
 };
 
-var qualident = context(and(optional(and(ident, ".")), ident),
+var qualident = context(and(optional(context(and(ident, "."), Context.QualifiedIdentificatorModule)), ident),
                         Context.QualifiedIdentificator);
 var identdef = makeIdentdef(ident);
 

+ 1 - 1
src/ob/Context.ob

@@ -3,7 +3,7 @@ IMPORT OberonRtl, Object, ScopeBase;
 TYPE
     Type* = RECORD
         handleChar*:    PROCEDURE(c: CHAR);
-        handleLiteral*: PROCEDURE(s: STRING): BOOLEAN;
+        handleLiteral*: PROCEDURE(s: STRING);
         handleString*:  PROCEDURE(s: STRING);
         handleIdent*:   PROCEDURE(s: STRING);
         isLexem*:       PROCEDURE(): BOOLEAN;

+ 8 - 13
src/ob/Lexer.ob

@@ -1,5 +1,5 @@
 MODULE Lexer;
-IMPORT Context, JS, Errors, Stream, String;
+IMPORT Context, Errors, Stream, String;
 
 CONST
     quote = 22X; (* " *)
@@ -59,13 +59,6 @@ BEGIN
     RETURN result
 END hexDigit;
 
-PROCEDURE handleLiteral(context: Context.Type; s: STRING): BOOLEAN;
-VAR result: BOOLEAN;
-BEGIN
-    JS.do("var r = context.handleLiteral(s); result = (r === undefined || r)");
-    RETURN result
-END handleLiteral;
-
 PROCEDURE point*(VAR stream: Stream.Type; context: Context.Type): BOOLEAN;
 VAR result: BOOLEAN;
 BEGIN
@@ -73,10 +66,11 @@ BEGIN
         & (Stream.getChar(stream) = ".")
         & (    Stream.eof(stream) 
             OR (Stream.peekChar(stream) # ".")) THEN (*not a diapason ".."*)        
-        result := handleLiteral(context, ".");
+        context.handleLiteral(".");
+        result := TRUE;
     END
-    RETURN result
-END point;
+    RETURN result;
+END;
 
 PROCEDURE string*(VAR stream: Stream.Type; context: Context.Type): BOOLEAN;
 VAR
@@ -212,10 +206,11 @@ BEGIN
             OR Stream.eof(stream)
             OR (~isLetter(Stream.peekChar(stream)) & ~isDigit(Stream.peekChar(stream)))
                 THEN
-            result := handleLiteral(context, l.s);
+            context.handleLiteral(l.s);
+            result := TRUE;
         END;
     END;
     RETURN result
-END literal;
+END;
 
 END Lexer.