Skip to content

Commit a4c8579

Browse files
committed
v241211.2
1 parent 36bbcbc commit a4c8579

File tree

6 files changed

+108
-1
lines changed

6 files changed

+108
-1
lines changed
-35 Bytes
Binary file not shown.

dist/easycoder-241211.2.tar.gz

1.13 KB
Binary file not shown.

easycoder/ec_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ def compileValue(self):
16401640
return value
16411641
return None
16421642

1643-
print(f'Unknown token {token}')
1643+
self.warning(f'Core: Unknown token {token}')
16441644
return None
16451645

16461646
#############################################################################
-3.95 KB
Binary file not shown.

plugins/example.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from easycoder import Handler, FatalError, RuntimeError, math
2+
3+
class Points(Handler):
4+
5+
def __init__(self, compiler):
6+
Handler.__init__(self, compiler)
7+
8+
def getName(self):
9+
return 'points'
10+
11+
#############################################################################
12+
# Keyword handlers
13+
14+
def k_point(self, command):
15+
return self.compileVariable(command, False)
16+
17+
def r_point(self, command):
18+
return self.nextPC()
19+
20+
# set {point} to {xvalue} {yvalue}
21+
def k_set(self, command):
22+
if self.nextIsSymbol():
23+
pointRecord = self.getSymbolRecord()
24+
if pointRecord['keyword'] == 'point':
25+
if self.nextIs('to'):
26+
xValue = self.nextValue()
27+
yValue = self.nextValue()
28+
command['x'] = xValue
29+
command['y'] = yValue
30+
command['name'] = pointRecord['name']
31+
self.add(command)
32+
return True
33+
34+
def r_set(self, command):
35+
pointRecord = self.getVariable(command['name'])
36+
x = self.getRuntimeValue(command['x'])
37+
y = self.getRuntimeValue(command['y'])
38+
pointRecord['x'] = x
39+
pointRecord['y'] = y
40+
return self.nextPC()
41+
42+
#############################################################################
43+
# Compile a value in this domain
44+
def compileValue(self):
45+
value = {}
46+
value['domain'] = 'points'
47+
if self.tokenIs('the'):
48+
self.nextToken()
49+
token = self.getToken()
50+
if token == 'distance':
51+
if self.nextIs('between'):
52+
if self.nextIsSymbol():
53+
point1Record = self.getSymbolRecord()
54+
if point1Record['keyword'] == 'point':
55+
if self.nextIs('and'):
56+
if self.nextIsSymbol():
57+
point2Record = self.getSymbolRecord()
58+
if point2Record['keyword'] == 'point':
59+
value['type'] = 'difference'
60+
value['point1'] = point1Record['name']
61+
value['point2'] = point2Record['name']
62+
return value
63+
return None
64+
65+
#############################################################################
66+
# Modify a value or leave it unchanged.
67+
def modifyValue(self, value):
68+
return value
69+
70+
#############################################################################
71+
# Value handlers
72+
73+
def v_difference(self, v):
74+
point1 = self.getVariable(v['point1'])
75+
point2 = self.getVariable(v['point2'])
76+
dx = point2['x'] - point1['x']
77+
dy = point2['y'] - point1['y']
78+
value = {}
79+
value['type'] = 'int'
80+
value['content'] = int(math.sqrt(dx*dx + dy*dy))
81+
return value
82+
83+
#############################################################################
84+
# Compile a condition
85+
def compileCondition(self):
86+
condition = {}
87+
return condition
88+
89+
#############################################################################
90+
# Condition handlers

scripts/points.ecs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
! Points example
2+
3+
script Points
4+
5+
import Points from plugins/example.py
6+
7+
point Point1
8+
point Point2
9+
variable Distance
10+
11+
print `Hello, world!`
12+
13+
set Point1 to 50 500
14+
set Point2 to 200 300
15+
16+
put the distance between Point1 and Point2 into Distance
17+
print `The distance is ` cat Distance cat ` units`

0 commit comments

Comments
 (0)