Skip to content

Commit 08ad16c

Browse files
committed
Update Python version
1 parent bcccb77 commit 08ad16c

File tree

10 files changed

+739
-897
lines changed

10 files changed

+739
-897
lines changed

dist/easycoder-min.js

Lines changed: 195 additions & 218 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/easycoder.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7220,6 +7220,16 @@ const EasyCoder_Rest = {
72207220
throw new Error(command.lino, `No URL present`);
72217221
}
72227222
let target = null;
7223+
const args = {};
7224+
while (compiler.tokenIs(`with`)) {
7225+
const argName = compiler.nextToken();
7226+
if (compiler.nextTokenIs(`as`)) {
7227+
const argValue = compiler.getNextValue();
7228+
args[argName] = argValue;
7229+
} else {
7230+
break;
7231+
}
7232+
}
72237233
if (compiler.tokenIs(`giving`)) {
72247234
if (compiler.nextIsSymbol()) {
72257235
const targetRecord = compiler.getSymbolRecord();
@@ -7239,6 +7249,7 @@ const EasyCoder_Rest = {
72397249
value,
72407250
url,
72417251
target,
7252+
args,
72427253
onError: compiler.getPc() + 2
72437254
});
72447255
onError = null;
@@ -7303,6 +7314,7 @@ const EasyCoder_Rest = {
73037314
return;
73047315
}
73057316
request.script = program.script;
7317+
request.program = program;
73067318
request.pc = program.pc;
73077319

73087320
request.onload = function () {
@@ -7336,10 +7348,10 @@ const EasyCoder_Rest = {
73367348
request.onerror = function () {
73377349
if (command.onError) {
73387350
program.errorMessage = this.responseText;
7339-
program.run(command.onError);
7351+
request.program.run(command.onError);
73407352
} else {
73417353
const error = this.responseText;
7342-
program.runtimeError(command.lino, error);
7354+
request.program.runtimeError(command.lino, error);
73437355
}
73447356
};
73457357

@@ -7353,6 +7365,10 @@ const EasyCoder_Rest = {
73537365
console.log(`POST to ${path}`);
73547366
//console.log(`value=${value}`);
73557367
request.setRequestHeader(`Content-type`, `application/json; charset=UTF-8`);
7368+
for (key of Object.keys(command.args)) {
7369+
const argval = request.program.getValue(command.args[key]);
7370+
request.setRequestHeader (key, argval);
7371+
}
73567372
request.send(value);
73577373
break;
73587374
}

js/easycoder/Rest.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ const EasyCoder_Rest = {
6161
throw new Error(command.lino, `No URL present`);
6262
}
6363
let target = null;
64+
const args = {};
65+
while (compiler.tokenIs(`with`)) {
66+
const argName = compiler.nextToken();
67+
if (compiler.nextTokenIs(`as`)) {
68+
const argValue = compiler.getNextValue();
69+
args[argName] = argValue;
70+
} else {
71+
break;
72+
}
73+
}
6474
if (compiler.tokenIs(`giving`)) {
6575
if (compiler.nextIsSymbol()) {
6676
const targetRecord = compiler.getSymbolRecord();
@@ -80,6 +90,7 @@ const EasyCoder_Rest = {
8090
value,
8191
url,
8292
target,
93+
args,
8394
onError: compiler.getPc() + 2
8495
});
8596
onError = null;
@@ -144,6 +155,7 @@ const EasyCoder_Rest = {
144155
return;
145156
}
146157
request.script = program.script;
158+
request.program = program;
147159
request.pc = program.pc;
148160

149161
request.onload = function () {
@@ -177,10 +189,10 @@ const EasyCoder_Rest = {
177189
request.onerror = function () {
178190
if (command.onError) {
179191
program.errorMessage = this.responseText;
180-
program.run(command.onError);
192+
request.program.run(command.onError);
181193
} else {
182194
const error = this.responseText;
183-
program.runtimeError(command.lino, error);
195+
request.program.runtimeError(command.lino, error);
184196
}
185197
};
186198

@@ -194,6 +206,10 @@ const EasyCoder_Rest = {
194206
console.log(`POST to ${path}`);
195207
//console.log(`value=${value}`);
196208
request.setRequestHeader(`Content-type`, `application/json; charset=UTF-8`);
209+
for (key of Object.keys(command.args)) {
210+
const argval = request.program.getValue(command.args[key]);
211+
request.setRequestHeader (key, argval);
212+
}
197213
request.send(value);
198214
break;
199215
}

py/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This class contans compiler and runtime modules for core keywords, values and co
3333

3434
Each extension package has the same structure and deals with its own vocabulary and syntax.
3535

36-
The individual compiler functions make heavy use of the Compiler class to retrieve tokens and process them. When they successfully complete the compilation of any given language structure they return an 'intermediate code' object with some standard fields such as the name of the package (the 'domain') and the script line number, and other fields that relate to the specific keyword, value or condition. This object goes into the array that becomes the program to be run.
36+
The individual compiler functions make heavy use of the Compiler class to retrieve tokens and process them. When they successfully complete the compilation of any given language structure they return an 'intermediate code' object with some standard fields such as the name of the package (the 'domain'), the script line number, and other fields that relate to the specific keyword, value or condition. This object goes into the array that becomes the program to be run.
3737

3838
At runtime the **Program** class starts at the beginning of the program array and looks in the first compiled object to find which package it belongs to and the name of the keyword. It then calls the appropriate `r_xxx()` function, which does whatever is necessary for that keyword and returns an updated program counter. This is then used to repeat the process and so on.
3939

py/easycoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __init__(self):
1010

1111
domainMap = {}
1212
domainMap['core'] = Core
13-
domainMap['autogui'] = Autogui
13+
# domainMap['autogui'] = Autogui
1414

1515
if (len(sys.argv) > 1):
1616
scriptName = sys.argv[1]

py/ec_autogui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def r_move(self, command):
8383
#############################################################################
8484
# Support functions
8585

86-
def dragMove(self,command, token):
86+
def dragMove(self, command, token):
8787
if token in [LEFT, RIGHT, UP, DOWN]:
8888
command[VALUE] = self.nextValue()
8989
multiplier = 1

py/ec_compiler.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ def getCommandAt(self, pc):
7373
return self.program.code[pc]
7474

7575
def isSymbol(self):
76+
token=self.getToken()
7677
try:
77-
self.symbols[self.getToken()]
78-
return True
78+
self.symbols[token]
7979
except:
8080
return False
81+
return True
8182

8283
def nextIsSymbol(self):
8384
self.next()
@@ -109,21 +110,19 @@ def compileVariable(self, command, valueHolder):
109110
return self.compileSymbol(command, self.nextToken(), valueHolder)
110111

111112
def compileSymbol(self, command, name, valueHolder):
112-
try:
113-
self.symbols[name]
113+
if hasattr(self.symbols, name):
114114
raise Error(f'Duplicate symbol name "{name}"')
115-
except:
116-
self.symbols[name] = self.getPC()
117-
command['isSymbol'] = True
118-
command['used'] = False
119-
command['valueHolder'] = valueHolder
120-
command['name'] = name
121-
command['elements'] = 1
122-
command['index'] = 0
123-
command['value'] = [None]
124-
command['debug'] = False
125-
self.addCommand(command)
126-
return True
115+
self.symbols[name] = self.getPC()
116+
command['isSymbol'] = True
117+
command['used'] = False
118+
command['valueHolder'] = valueHolder
119+
command['name'] = name
120+
command['elements'] = 1
121+
command['index'] = 0
122+
command['value'] = [None]
123+
command['debug'] = False
124+
self.addCommand(command)
125+
return True
127126

128127
# Compile the current token
129128
def compileToken(self):
@@ -144,9 +143,10 @@ def compileToken(self):
144143
except Exception as err:
145144
self.warning(f'No handler found for "{token}" in domain "{domain.getName()}"')
146145
self.rewind()
147-
raise Error(f'I can\'t compile "{token}"')
146+
lino = self.tokens[self.index].lino
147+
raise Error(f'Line {lino + 1}: I can\'t compile "{self.script.lines[self.tokens[self.index].lino]}"')
148148

149-
# Compile a single command
149+
# Compile a single command%
150150
def compileOne(self):
151151
keyword = self.getToken()
152152
if not keyword:

0 commit comments

Comments
 (0)