Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit a0a719b

Browse files
author
Héctor Hurtado
committed
Working version
1 parent 4d338c3 commit a0a719b

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

mist/lang/classes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def run(self, stack):
4040
if self.params:
4141
fields = [p for p in self.params]
4242
values = [
43-
json.dumps(await get_id(i, stack)) if i.customList or type(await get_id(i, stack)) is list else str(await get_id(i, stack))
43+
json.dumps(await get_id(i, stack)) if i.value.__class__.__name__ == 'CustomList' or type(await get_id(i, stack)) is list else str(await get_id(i, stack))
4444
for i in self.sources
4545
]
4646
await watchedInsert(self.target, stack, values, fields=fields)
@@ -231,7 +231,7 @@ async def run(self, stack):
231231
break
232232
for arg in self.namedArgs:
233233
if arg.value.source:
234-
sourceStream = arg.value.source
234+
sourceStream = arg.value.source
235235

236236
if sourceStream or self.targetStream:
237237
t = asyncio.create_task(function_runner(self.name, stack[:], sourceStream, self.targetStream, self.args, self.namedArgs))
@@ -241,7 +241,7 @@ async def run(self, stack):
241241
if self.targetStream:
242242
streams.createIfNotExists(self.targetStream)
243243
producers.append(t)
244-
else:
244+
else:
245245
result = await function_runner(self.name, stack, sourceStream, self.targetStream, self.args, self.namedArgs, self.commands)
246246
if self.key:
247247
for s in reversed(stack):
@@ -285,7 +285,7 @@ async def run(self, stack):
285285
content = f.read()
286286
# TODO: pass stack
287287
print(await mist.action_run.execute_from_text(content, environment))
288-
288+
289289

290290
exports = [DataCommand, SaveCommand, SaveListCommand, CheckCommand,
291291
PrintCommand, IterateCommand, WatchCommand, AbortCommand,

mist/lang/core.tx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,29 @@ FunctionInlineCall:
4747
name=ID ('()' | '(' (namedArgs+=NamedArg[','] | args+=IDorSTRING[',']) ')')
4848
;
4949

50+
StringData:
51+
data=/(?ms)\'{3}(.*?)\'{3}/
52+
;
53+
54+
VarReference:
55+
id=ID('.'childs+=ID['.'])?
56+
;
57+
58+
ExtParameter:
59+
'%' param=ID
60+
;
61+
62+
EnvVariable:
63+
'$' var=ID
64+
;
65+
66+
Source:
67+
':' source=ID
68+
;
69+
5070
IDorSTRING:
51-
function=FunctionInlineCall | customList=CustomList | data=/(?ms)\'{3}(.*?)\'{3}/ | (id=ID('.'childs+=ID['.'])?) | string=STRING | intVal=INT | '%'param=ID |
52-
'$'var=ID | ':'source=ID
71+
value=FunctionInlineCall | value=CustomList | value=StringData | value=VarReference |
72+
value=STRING | value=INT | value=ExtParameter | value=EnvVariable | value=Source
5373
;
5474

5575
FunctionCall:

mist/sdk/herlpers.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,46 @@ async def get_id(id, stack):
136136
else:
137137
return get_var(id.id, stack)
138138

139+
def get_id(id):
140+
141+
if id == None:
142+
return None
143+
144+
if isinstance(id.value, str):
145+
if id.value in ("True", "Success"):
146+
return True
147+
elif id.value in ("False", "Error"):
148+
return False
149+
else:
150+
s = id.value
151+
pairs = [(i[1],get_key(i[1])) for i in Formatter().parse(s) if i[1] is not None]
152+
for k,v in pairs:
153+
s = s.replace('{' + k + '}',str(v),1)
154+
return s
155+
elif isinstance(id.value, int):
156+
return id.value
157+
elif id.value.__class__.__name__ == "StringData":
158+
return id.value.data
159+
elif id.value.__class__.__name__ == "ExtParameter":
160+
return params[id.value.param]
161+
elif id.value.__class__.__name__ == "EnvVariable":
162+
return environment[id.value.var]
163+
elif id.value.__class__.__name__ == "FunctionInlineCall":
164+
return function_runner(id.value.name, id.value.args, id.value.namedArgs )
165+
elif id.value.__class__.__name__ == "CustomList":
166+
return [ get_id(c) for c in id.value.components ]
167+
elif id.value.__class__.__name__ == "VarReference":
168+
if id.value.childs:
169+
return getChildFromVar(get_var(id.value.id), id.value.childs)
170+
else:
171+
return get_var(id.value.id)
172+
elif id.value.__class__.__name__ == "Source":
173+
return environment[id.value.source]
174+
else: # type(id.value is boolean, float, ....)
175+
pass
176+
177+
178+
139179
def get_param(params, key):
140180
t = [x for x in params if x.key == key]
141181
return t[0].value if t else None

test.mist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
data myTable {
2+
key
3+
value
4+
}
5+
6+
set key_1 <= 'k1'
7+
8+
set val_1 <= tmpFile()
9+
10+
put key_1 val_1 => myTable
11+
12+
set myList <= ["one","two","three","four"]
13+
14+
iterate myList => v {
15+
put v 'value' => myTable
16+
}
17+
18+
iterate myTable => row {
19+
print row.key row.value
20+
}

0 commit comments

Comments
 (0)