Vladislav Folts 9 роки тому
батько
коміт
7bece8683c

+ 26 - 0
doc/wiki/eberon-array-initializers.md

@@ -0,0 +1,26 @@
+Array initializers create array with specified elements as a shortcut instead of declaring array variable and initialize each element separately.
+
+### Syntax
+
+	"[" expression {, expression} "]"
+
+### Example
+
+	
+	MODULE test;
+	CONST a = [1, 2, 3];
+
+	PROCEDURE passArray(a: ARRAY OF INTEGER);
+	END;
+
+	BEGIN
+		passArray(a);
+		passArray([123, 456]);
+	END test.
+
+### Semantics
+
+* all expressions used in initializers list must have the same type
+* if string literal is used as expression then element's type is [[STRING|eberon-strings]]
+* array initializers can be used to define a constant in CONST section
+* array initializers can be used wherever constant expression of corresponded array's type can be used 

+ 1 - 2
doc/wiki/eberon-in-place-variables.md

@@ -9,8 +9,7 @@ Example:
 
     i <- 123;
 
-*In place* variable is declared and assigned in the same time. The type of variable is not specified but deduced from the expression on the right. In the example above 
-variable will have type INTEGER. In the following example the variable will have the same type as a result of PROCEDURE f:
+*In place* variable is declared and assigned in the same time. The type of variable is not specified but deduced from the expression on the right. In the example above variable will have type INTEGER. If expression is a string literal then deduced type is [[STRING|eberon-strings]]. In the following example the variable will have the same type as a result of PROCEDURE f:
 
     x <- f();
 

+ 1 - 0
doc/wiki/eberon.md

@@ -11,6 +11,7 @@ Eberon basically extends original Oberon (excluding additional [restrictions](#r
 * [[Dynamic Arrays|eberon-dynamic-arrays]]
 * [[Associative Arrays|eberon-associative-arrays]]
 * [[FOR..IN loop|eberon-FOR..IN]]
+* [[Array initializers|eberon-array-initializers]]
 * [[Array indexOf() method|eberon-array-methods]]
 * [[Record fields read-only export|eberon-record-fields-read-only-export]]
 * [[Procedure call result can be denoted|eberon-procedure-call-result]]

+ 2 - 1
test/test_unit_eberon.js

@@ -1576,7 +1576,8 @@ exports.suite = {
     fail(["[]", "not parsed"],
          ["[1, TRUE]", "array's elements should have the same type: expected 'INTEGER', got 'BOOLEAN'"],
          ["[NIL]", "cannot use NIL to initialize array's element"],
-         ["[1, NIL]", "cannot use NIL to initialize array's element"]
+         ["[1, NIL]", "cannot use NIL to initialize array's element"],
+         ["[[1, 2], [3, 4]]", "array's elements should have the same type: expected 'ARRAY 2 OF INTEGER', got 'ARRAY 2 OF INTEGER'"] // not supported
         )
     ),
 "CONST array": testWithGrammar(