Skip to content

Commit 2268604

Browse files
authored
Create README-LanguageDraft-2.0.md
1 parent 96017f1 commit 2268604

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

README-LanguageDraft-2.0.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
![LOGO](https://raw.githubusercontent.com/andreasdr/minitscript/master/resources/github/minitscript-logo.png)
2+
3+
# 1 MinitScript 2.0: new language features draft
4+
5+
- inline comments with #- $x = 1 -#
6+
7+
```
8+
function: bubbleSortA(&$array)
9+
# best code quality, but less performance
10+
for ($i = 1, $i < $array->getSize()#-+ 1-#, ++$i)
11+
for ($j = 0, $j < $array->getSize() - $i, ++$j)
12+
#-
13+
if ($array[$j] > $array[$j + 1])
14+
swap($array[$j], $array[$j + 1])
15+
end
16+
-#
17+
end
18+
end
19+
end
20+
```
21+
22+
- enums
23+
24+
```
25+
enum Colors
26+
$RED = 0
27+
$GREEN = 1
28+
$BLUE = 2
29+
end
30+
31+
...
32+
$color = Colors.$RED
33+
switch($color)
34+
case(Colors.$RED)
35+
console.printLine("RED")
36+
end
37+
case(Colors.$GREEN)
38+
console.printLine("GREEN")
39+
end
40+
case(Colors.$BLUE)
41+
console.printLine("BLUE")
42+
end
43+
#-
44+
case(Colors.$YELLOW)
45+
console.printLine("YELLOW")
46+
end
47+
-#
48+
default
49+
console.printLine("No specific color selected")
50+
end
51+
end
52+
```
53+
54+
- structures, which are data only
55+
56+
```
57+
# maybe, not sure if required 100%
58+
structure CarData
59+
$tireCount: Integer
60+
$color: Integer
61+
end
62+
```
63+
64+
- structure data validations, which are type hinted interfaces alike
65+
66+
```
67+
# maybe, but looks good already
68+
data Car validated-by CarData
69+
private $tireCount = 4
70+
private $color = "red"
71+
end
72+
```
73+
74+
- interfaces for class methods
75+
76+
```
77+
interface CarInterface
78+
private $tireCount
79+
private $color
80+
81+
constructor($tireCount, $color)
82+
83+
destructor()
84+
85+
method: dump()
86+
87+
operator: +: ($a, $b)
88+
89+
operator: +=: ($b)
90+
end
91+
```
92+
93+
- classes with optional interface and data validation
94+
95+
```
96+
class Car[ implements CarInterface [validated-by CarData]
97+
private $tireCount = 4
98+
private $color = "red"
99+
100+
constructor($tireCount, $color)
101+
$this.tireCount = $tireCount
102+
$this.color = $color
103+
end
104+
105+
destructor()
106+
$this.tireCount = null
107+
$this.color = null
108+
end
109+
110+
method: dump()
111+
console.printLine(
112+
"$this.tireCount = $tireCount, " +
113+
"$this.color = $color"
114+
)
115+
end
116+
117+
operator: +: ($a, $b)
118+
return Auto(
119+
$a.tireCount + $b.tireCount,
120+
$a.color + "/" + $b.color
121+
)
122+
end
123+
124+
operator: +=: ($b)
125+
$this.tireCount+= $b.tireCount,
126+
$this.color+= "/" + $b.color
127+
end
128+
129+
end
130+
131+
#
132+
$car = Car(4, Colors.$RED)
133+
$car->dump()
134+
#
135+
$car = Car(4, Colors.$RED) + Car(4, Colors.$BLUE)
136+
```
137+
138+
- Static member variables
139+
- maybe by mapping to global variables
140+
- Class::$classProperty would map to $$.___Class_classProperty
141+
142+
```
143+
class Class
144+
static private $classProperty = 4
145+
end
146+
```
147+
148+
- Static member methods
149+
150+
```
151+
class Class
152+
static method: classMethod($a, $b)
153+
console.printLine($a + " / " + $b)
154+
end
155+
end
156+
```

0 commit comments

Comments
 (0)