瀏覽代碼

Merge pull request #972 from seandenigris/Issue971

Chunk Importer - convert character literals to strings #971
Nicolas Petton 11 年之前
父節點
當前提交
876849cc1e
共有 4 個文件被更改,包括 261 次插入198 次删除
  1. 4 2
      src/Compiler-Tests.js
  2. 1 0
      src/Compiler-Tests.st
  3. 248 194
      support/parser.js
  4. 8 2
      support/parser.pegjs

+ 4 - 2
src/Compiler-Tests.js

@@ -698,12 +698,14 @@ self._should_return_("foo ^ #{1->2. 3->4}",globals.HashedCollection._newFromPair
 $ctx1.sendIdx["should:return:"]=7;
 self._should_return_("foo ^ #hello","hello");
 $ctx1.sendIdx["should:return:"]=8;
-self._should_return_("foo ^ -123.456",(-123.456));
+self._should_return_("foo ^ $h","h");
 $ctx1.sendIdx["should:return:"]=9;
+self._should_return_("foo ^ -123.456",(-123.456));
+$ctx1.sendIdx["should:return:"]=10;
 self._should_return_("foo ^ -2.5e4",(-25000));
 return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},globals.CodeGeneratorTest)})},
 args: [],
-source: "testLiterals\x0a\x09self should: 'foo ^ 1' return: 1.\x0a\x09self should: 'foo ^ ''hello''' return: 'hello'.\x0a\x09self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ true' return: true.\x0a\x09self should: 'foo ^ false' return: false.\x0a\x09self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.\x0a\x09self should: 'foo ^ #hello' return: #hello.\x0a\x09self should: 'foo ^ -123.456' return: -123.456.\x0a\x09self should: 'foo ^ -2.5e4' return: -25000.",
+source: "testLiterals\x0a\x09self should: 'foo ^ 1' return: 1.\x0a\x09self should: 'foo ^ ''hello''' return: 'hello'.\x0a\x09self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ true' return: true.\x0a\x09self should: 'foo ^ false' return: false.\x0a\x09self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.\x0a\x09self should: 'foo ^ #hello' return: #hello.\x0a\x09self should: 'foo ^ $h' return: 'h'.\x0a\x09self should: 'foo ^ -123.456' return: -123.456.\x0a\x09self should: 'foo ^ -2.5e4' return: -25000.",
 messageSends: ["should:return:"],
 referencedClasses: []
 }),

+ 1 - 0
src/Compiler-Tests.st

@@ -287,6 +287,7 @@ testLiterals
 	self should: 'foo ^ false' return: false.
 	self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.
 	self should: 'foo ^ #hello' return: #hello.
+	self should: 'foo ^ $h' return: 'h'.
 	self should: 'foo ^ -123.456' return: -123.456.
 	self should: 'foo ^ -2.5e4' return: -25000.
 !

文件差異過大導致無法顯示
+ 248 - 194
support/parser.js


+ 8 - 2
support/parser.pegjs

@@ -13,7 +13,13 @@ string         = ['] val:(("''" {return "'";} / [^'])*) ['] {
                             ._source_(text())
                             ._value_(val.join("").replace(/\"/ig, '"'));
                  }
-
+character      = "$" char:. 
+                  {
+                      return globals.ValueNode._new()
+                             ._position_((line()).__at(column()))
+                             ._source_(text())
+                             ._value_(char);
+                  }
 symbol         = "#" rest:bareSymbol {return rest;}
 bareSymbol         = val:(selector / binarySelector / node:string {return node._value();})
                   {
@@ -62,7 +68,7 @@ pseudoVariable = val:(
                               ._source_(text())
                               ._value_(val);
                    }
-parseTimeLiteral        = pseudoVariable / number / literalArray / string / symbol
+parseTimeLiteral        = pseudoVariable / number / literalArray / string / symbol / character
 runtimeLiteral        = dynamicDictionary / dynamicArray / block
 literal        = runtimeLiteral / parseTimeLiteral
 

部分文件因文件數量過多而無法顯示