Skip to content

Commit 1ec6620

Browse files
committed
250723.1
1 parent f1d7396 commit 1ec6620

File tree

11 files changed

+581
-4
lines changed

11 files changed

+581
-4
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
*/__pycache__/*
22
*.code-workspace
3-
*.py
43
*.ecs
39.2 KB
Binary file not shown.

dist/easycoder-250723.1.tar.gz

2.65 MB
Binary file not shown.

easycoder/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
from .ec_timestamp import *
1212
from .ec_value import *
1313

14-
__version__ = "250722.5"
14+
__version__ = "250723.1"

easycoder/ec_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import numbers, base64, binascii, random, requests, paramiko
33
from psutil import Process
44
from datetime import datetime
5-
from random import randrange
65
from .ec_classes import FatalError, RuntimeWarning, RuntimeError, AssertionError, NoValueError, NoValueRuntimeError, Condition, Object
76
from .ec_handler import Handler
87
from .ec_timestamp import getTimestamp
@@ -1804,6 +1803,8 @@ def k_use(self, command):
18041803
from .ec_pyside import Graphics
18051804
self.program.graphics = Graphics
18061805
self.program.useClass(Graphics)
1806+
# from .ec_keyboard import Keyboard
1807+
# self.program.useClass(Keyboard)
18071808
return True
18081809
return False
18091810

easycoder/ec_keyboard.py

Lines changed: 392 additions & 0 deletions
Large diffs are not rendered by default.

easycoder/ec_pyside.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
2-
from easycoder import Handler, RuntimeError
2+
from .ec_handler import Handler
3+
from .ec_classes import RuntimeError
4+
from .ec_keyboard import Keyboard
35
from PySide6.QtCore import Qt, QTimer
46
from PySide6.QtGui import QPixmap
57
from PySide6.QtWidgets import (

plugins/sql.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
from easycoder import Handler, FatalError, RuntimeError, json
2+
3+
class SQL(Handler):
4+
5+
def __init__(self, compiler):
6+
Handler.__init__(self, compiler)
7+
8+
def getName(self):
9+
return 'sql'
10+
11+
#############################################################################
12+
# Keyword handlers
13+
14+
# create {table} {name} [with ...]
15+
# {name} {flag(s)} {type} [default {value}] [and ..]
16+
def k_create(self, command):
17+
if self.nextIsSymbol():
18+
record = self.getSymbolRecord()
19+
if record['keyword'] == 'table':
20+
command['target'] = record['name']
21+
command['tableName'] = self.nextValue()
22+
keys = []
23+
while self.peek() in ['key', 'include']:
24+
item = {}
25+
token = self.nextToken()
26+
if token == 'include':
27+
item['include'] = self.nextValue()
28+
else:
29+
item['name'] = self.nextValue()
30+
token = self.peek()
31+
if token == 'primary':
32+
item['primary'] = True
33+
self.nextToken()
34+
if token == 'secondary':
35+
item['secondary'] = True
36+
self.nextToken()
37+
elif token == 'required':
38+
item['required'] = True
39+
self.nextToken()
40+
elif token == 'auto':
41+
item['required'] = True
42+
self.nextToken()
43+
item['type'] = self.nextToken()
44+
if self.peek() in ['default', '=']:
45+
self.nextToken()
46+
item['default'] = self.nextValue()
47+
elif self.peek() == 'check':
48+
self.nextToken()
49+
item['check'] = self.nextValue()
50+
keys.append(item)
51+
command['keys'] = keys
52+
self.add(command)
53+
return True
54+
return False
55+
56+
def r_create(self, command):
57+
record = self.getVariable(command['target'])
58+
self.putSymbolValue(record, command)
59+
return self.nextPC()
60+
61+
def k_get(self, command):
62+
if self.nextIsSymbol():
63+
record = self.getSymbolRecord()
64+
if record['hasValue']:
65+
command['target'] = record['name']
66+
self.skip('from')
67+
if self.nextIsSymbol():
68+
record = self.getSymbolRecord()
69+
if record['keyword'] == 'table':
70+
command['entity'] = record['name']
71+
if self.peek() == 'as':
72+
self.nextToken()
73+
command['form'] = self.nextToken()
74+
else: command['form'] = 'sql'
75+
self.add(command)
76+
return True
77+
return False
78+
79+
def r_get(self, command):
80+
target = self.getVariable(command['target'])
81+
entity = self.getVariable(command['entity'])
82+
form = command['form']
83+
keyword = entity['keyword']
84+
if keyword == 'table':
85+
value = self.getSymbolValue(entity)
86+
tableName = self.getRuntimeValue(value['tableName'])
87+
output = []
88+
if form == 'sql':
89+
# -------------------------------------------------------------
90+
# Here are the rules for generating SQL
91+
output.append(f'DROP TABLE IF EXISTS {tableName} CASCADE;')
92+
output.append(f'CREATE TABLE {tableName} {{')
93+
secondary = False
94+
includes = []
95+
keys = entity['value'][entity['index']]['keys']
96+
for index, key in enumerate(keys):
97+
item = []
98+
if 'include' in key:
99+
name = self.getRuntimeValue(key['include'])
100+
includes.append(f'{name}_id')
101+
item = f'{name}_id BIGINT REFERENCES {name}'
102+
else:
103+
if 'secondary' in key:
104+
secondary = True
105+
output.append(' id BIGSERIAL PRIMARY KEY,')
106+
item.append(self.getRuntimeValue(key['name']))
107+
type = key['type']
108+
if type == 'string': type = 'text'
109+
elif type == 'datetime': type = 'timestamptz'
110+
elif type == 'u64': type = 'bigint'
111+
item.append(type.upper())
112+
if secondary:
113+
item.append('UNIQUE NOT NULL')
114+
secondary = False
115+
if 'primary' in key: item.append('PRIMARY KEY')
116+
if 'required' in key: item.append('NOT NULL')
117+
if 'default' in key:
118+
default = self.getRuntimeValue(key['default'])
119+
item.append(f'DEFAULT \'{default}\'')
120+
if 'check' in key:
121+
check = self.getRuntimeValue(key['check'])
122+
item.append(f'CHECK ({check})')
123+
item = ' '.join(item)
124+
if index < len(keys) - 1 or len(includes) > 0: item = f'{item},'
125+
output.append(f' {item}')
126+
if len(includes) > 0:
127+
includes = ', '.join(includes)
128+
item = f' PRIMARY KEY ({includes})'
129+
output.append(item)
130+
output.append('};')
131+
# -------------------------------------------------------------
132+
v = {}
133+
v['type'] = 'text'
134+
v['content'] = '\n'.join(output)
135+
self.putSymbolValue(target, v)
136+
return self.nextPC()
137+
138+
def k_table(self, command):
139+
return self.compileVariable(command, False)
140+
141+
def r_table(self, command):
142+
return self.nextPC()
143+
144+
#############################################################################
145+
# Compile a value in this domain
146+
def compileValue(self):
147+
return None
148+
149+
#############################################################################
150+
# Modify a value or leave it unchanged.
151+
def modifyValue(self, value):
152+
return value
153+
154+
#############################################################################
155+
# Value handlers
156+
157+
#############################################################################
158+
# Compile a condition
159+
def compileCondition(self):
160+
condition = {}
161+
return condition
162+
163+
#############################################################################
164+
# Condition handlers

test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/python3
2+
3+
from easycoder import Program
4+
5+
Program('test.ecs').start()

testsql.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/python3
2+
3+
import os
4+
from easycoder import Program
5+
6+
os.chdir('../..')
7+
Program('testsql.ecs').start()

0 commit comments

Comments
 (0)