|
@@ -52,8 +52,168 @@ File extension - `*.de` (because `de` is more short than `def`).
|
|
|
|
|
|
|
|
|
# 2. Syntax and Ideas
|
|
|
-todo
|
|
|
|
|
|
|
|
|
+## 2.1 toml file for config keys-values
|
|
|
+
|
|
|
+```toml
|
|
|
+[lexer]
|
|
|
+indent_type = 0
|
|
|
+indent_matter = 4
|
|
|
+indent_not_matter = 2
|
|
|
+```
|
|
|
+this means we have basic indent (Off-side rule) as 4 whitespaces,
|
|
|
+but we do not got error when next line have 5, 6 or 3, 2 whitespaces -
|
|
|
+needs to have more that 2 whitespaces for change indent (Off-side rule) for next level.
|
|
|
+
|
|
|
+
|
|
|
+## 2.2 do not use any reserved words (keywords) for function definition (like in Erlang)
|
|
|
+todo add examples
|
|
|
+
|
|
|
+
|
|
|
+## 2.3 Pattern Matching that transforms into ```if .. else if .. else ..```
|
|
|
+todo think - there are ```case``` in dlang already (maybe use ```case .. of``` ?):
|
|
|
+https://dlang.org/spec/statement.html#SwitchStatement
|
|
|
+https://dlang.org/spec/statement.html#case-range
|
|
|
+https://tour.dlang.org/tour/uk/basics/controlling-flow
|
|
|
+https://dlang.org/spec/expression.html#IsExpression
|
|
|
+todo add examples
|
|
|
+
|
|
|
+
|
|
|
+## 2.4 Pattern Matching at functions too (like in Erlang)
|
|
|
+Function overloading in dlang allows to define the same function but with different versions for different data types:
|
|
|
+```dlang
|
|
|
+int my_func(int x) {
|
|
|
+ return x;
|
|
|
+}
|
|
|
+
|
|
|
+int my_func(string x) {
|
|
|
+ return x.length; // or other operation(s) with argument
|
|
|
+}
|
|
|
+```
|
|
|
+that similar to erlang's functions clauses:
|
|
|
+```erlang
|
|
|
+my_func(X) when is_integer(X) -> X;
|
|
|
+my_func(Y) when is_binary(Y) orelse is_list(Y) -> string:length(Y). %% is_list for list string (list chars codes)
|
|
|
+```
|
|
|
+
|
|
|
+other example
|
|
|
+```erlang
|
|
|
+my_func(1) -> 1;
|
|
|
+my_func(5) -> 5 * 2;
|
|
|
+my_func(9) -> 9 * 3;
|
|
|
+my_func(X) -> X * 4.
|
|
|
+```
|
|
|
+->
|
|
|
+```dlang
|
|
|
+int my_func(int x) {
|
|
|
+ if (x == 1) return 1;
|
|
|
+ else if (x == 5) return x * 2;
|
|
|
+ else if (x == 9) return x * 3;
|
|
|
+ else return x * 4; // other cases
|
|
|
+}
|
|
|
+
|
|
|
+// or
|
|
|
+
|
|
|
+int my_func(int x) {
|
|
|
+ switch (x) {
|
|
|
+ case 1:
|
|
|
+ return 1; // if x == 1
|
|
|
+ case 5:
|
|
|
+ return x * 2; // if x == 5
|
|
|
+ case 9:
|
|
|
+ return x * 3; // if x == 9
|
|
|
+ default:
|
|
|
+ return x * 4; // other cases
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
+note that compiler can optimise few comparison conditions for ```switch``` better than that in ```if .. else```.
|
|
|
+
|
|
|
+todo add examples
|
|
|
+
|
|
|
+
|
|
|
+## 2.5 aliases for imports, externs etc
|
|
|
+```
|
|
|
+use std [ stdio array string algorithm ] as use_std // definition at the beginning of the file
|
|
|
+
|
|
|
+use use_std // allows use elsewhere in the file -- generate next code in this position in the target .d file
|
|
|
+
|
|
|
+->
|
|
|
+
|
|
|
+import std.stdio;
|
|
|
+import std.array;
|
|
|
+import std.string;
|
|
|
+import std.algorithm;
|
|
|
+```
|
|
|
+todo add more examples
|
|
|
+
|
|
|
+
|
|
|
+## 2.6 code between ```dlang``` reserved words translates into target .d file without changes
|
|
|
+```
|
|
|
+...
|
|
|
+
|
|
|
+dlang
|
|
|
+
|
|
|
+// common dlang code here
|
|
|
+
|
|
|
+dlang
|
|
|
+
|
|
|
+...
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+## 2.7 reserved words (keywords) list
|
|
|
+including https://dlang.org/spec/lex.html#keywords
|
|
|
+```
|
|
|
+abstract alias align asm assert auto
|
|
|
+bool break byte
|
|
|
+case cast catch char class const continue
|
|
|
+dchar debug default delegate deprecated do double
|
|
|
+else enum export extern
|
|
|
+false final finally float for foreach foreach_reverse function
|
|
|
+goto
|
|
|
+if immutable import in inout int interface invariant is
|
|
|
+lazy long
|
|
|
+macro mixin module
|
|
|
+new nothrow null
|
|
|
+out override
|
|
|
+package pragma private protected public pure
|
|
|
+real ref return
|
|
|
+scope shared static struct super switch synchronized
|
|
|
+template this throw true try typeid typeof
|
|
|
+ubyte uint ulong union unittest ushort
|
|
|
+version void
|
|
|
+wchar while with
|
|
|
+
|
|
|
+__FILE__
|
|
|
+__FILE_FULL_PATH__
|
|
|
+__FUNCTION__
|
|
|
+__LINE__
|
|
|
+__MODULE__
|
|
|
+__PRETTY_FUNCTION__
|
|
|
+
|
|
|
+__gshared
|
|
|
+__parameters
|
|
|
+__rvalue
|
|
|
+__traits
|
|
|
+__vector
|
|
|
+
|
|
|
+__DATE__
|
|
|
+__EOF__
|
|
|
+__TIME__
|
|
|
+__TIMESTAMP__
|
|
|
+__VENDOR__
|
|
|
+__VERSION__
|
|
|
+
|
|
|
+
|
|
|
+[deprecated keywords] body cdouble cent cfloat creal delete idouble ifloat ireal ucent
|
|
|
+
|
|
|
+
|
|
|
+dlang
|
|
|
+use
|
|
|
+as
|
|
|
+```
|
|
|
+todo
|
|
|
|
|
|
|