1
0
فهرست منبع

Fixed dynamic array and friends allowed in literal array.

Recompile went without error, with no changes.
Herbert Vojčík 12 سال پیش
والد
کامیت
8e772483eb
2فایلهای تغییر یافته به همراه59 افزوده شده و 17 حذف شده
  1. 55 15
      js/parser.js
  2. 4 2
      js/parser.pegjs

+ 55 - 15
js/parser.js

@@ -54,6 +54,8 @@ smalltalk.parser = (function(){
         "dynamicArray": parse_dynamicArray,
         "dynamicDictionary": parse_dynamicDictionary,
         "pseudoVariable": parse_pseudoVariable,
+        "parseTimeLiteral": parse_parseTimeLiteral,
+        "runtimeLiteral": parse_runtimeLiteral,
         "literal": parse_literal,
         "variable": parse_variable,
         "classReference": parse_classReference,
@@ -1251,7 +1253,7 @@ smalltalk.parser = (function(){
             result2 = [];
             pos2 = clone(pos);
             pos3 = clone(pos);
-            result3 = parse_literal();
+            result3 = parse_parseTimeLiteral();
             if (result3 !== null) {
               result4 = parse_ws();
               if (result4 !== null) {
@@ -1274,7 +1276,7 @@ smalltalk.parser = (function(){
               result2.push(result3);
               pos2 = clone(pos);
               pos3 = clone(pos);
-              result3 = parse_literal();
+              result3 = parse_parseTimeLiteral();
               if (result3 !== null) {
                 result4 = parse_ws();
                 if (result4 !== null) {
@@ -1597,8 +1599,8 @@ smalltalk.parser = (function(){
         return result0;
       }
       
-      function parse_literal() {
-        var cacheKey = "literal@" + pos.offset;
+      function parse_parseTimeLiteral() {
+        var cacheKey = "parseTimeLiteral@" + pos.offset;
         var cachedResult = cache[cacheKey];
         if (cachedResult) {
           pos = clone(cachedResult.nextPos);
@@ -1613,18 +1615,9 @@ smalltalk.parser = (function(){
           if (result0 === null) {
             result0 = parse_literalArray();
             if (result0 === null) {
-              result0 = parse_dynamicDictionary();
+              result0 = parse_string();
               if (result0 === null) {
-                result0 = parse_dynamicArray();
-                if (result0 === null) {
-                  result0 = parse_string();
-                  if (result0 === null) {
-                    result0 = parse_symbol();
-                    if (result0 === null) {
-                      result0 = parse_block();
-                    }
-                  }
-                }
+                result0 = parse_symbol();
               }
             }
           }
@@ -1637,6 +1630,53 @@ smalltalk.parser = (function(){
         return result0;
       }
       
+      function parse_runtimeLiteral() {
+        var cacheKey = "runtimeLiteral@" + pos.offset;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = clone(cachedResult.nextPos);
+          return cachedResult.result;
+        }
+        
+        var result0;
+        
+        result0 = parse_dynamicDictionary();
+        if (result0 === null) {
+          result0 = parse_dynamicArray();
+          if (result0 === null) {
+            result0 = parse_block();
+          }
+        }
+        
+        cache[cacheKey] = {
+          nextPos: clone(pos),
+          result:  result0
+        };
+        return result0;
+      }
+      
+      function parse_literal() {
+        var cacheKey = "literal@" + pos.offset;
+        var cachedResult = cache[cacheKey];
+        if (cachedResult) {
+          pos = clone(cachedResult.nextPos);
+          return cachedResult.result;
+        }
+        
+        var result0;
+        
+        result0 = parse_runtimeLiteral();
+        if (result0 === null) {
+          result0 = parse_parseTimeLiteral();
+        }
+        
+        cache[cacheKey] = {
+          nextPos: clone(pos),
+          result:  result0
+        };
+        return result0;
+      }
+      
       function parse_variable() {
         var cacheKey = "variable@" + pos.offset;
         var cachedResult = cache[cacheKey];

+ 4 - 2
js/parser.pegjs

@@ -26,7 +26,7 @@ number         = n:(hex / float / integer) {
 hex            = neg:[-]? "16r" num:[0-9a-fA-F]+ {return parseInt((neg + num.join("")), 16)}
 float          = neg:[-]?int:[0-9]+ "." dec:[0-9]+ {return parseFloat((neg + int.join("") + "." + dec.join("")), 10)}
 integer        = neg:[-]?digits:[0-9]+ {return (parseInt(neg+digits.join(""), 10))}
-literalArray   = "#(" ws lits:(lit:literal ws {return lit._value()})* ws ")" {
+literalArray   = "#(" ws lits:(lit:parseTimeLiteral ws {return lit._value()})* ws ")" {
                      return smalltalk.ValueNode._new()
                             ._value_(lits)
                  }
@@ -45,7 +45,9 @@ pseudoVariable = val:(
                        return smalltalk.ValueNode._new()
                               ._value_(val)
                    }
-literal        = pseudoVariable / number / literalArray / dynamicDictionary / dynamicArray / string / symbol / block
+parseTimeLiteral        = pseudoVariable / number / literalArray / string / symbol
+runtimeLiteral        = dynamicDictionary / dynamicArray / block
+literal        = runtimeLiteral / parseTimeLiteral
 
 
 variable       = identifier:varIdentifier {