chemql-python 1.6.6__tar.gz → 1.6.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chemql_python-1.6.7/PKG-INFO +888 -0
- chemql_python-1.6.7/README.md +874 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/pyproject.toml +2 -1
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/__init__.py +171 -25
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/codecql.py +126 -23
- chemql_python-1.6.7/src/chemql/highlighting.json +950 -0
- chemql_python-1.6.7/src/chemql_python.egg-info/PKG-INFO +888 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql_python.egg-info/SOURCES.txt +1 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/tests/test_structured_types.py +82 -0
- chemql_python-1.6.6/PKG-INFO +0 -677
- chemql_python-1.6.6/README.md +0 -663
- chemql_python-1.6.6/src/chemql_python.egg-info/PKG-INFO +0 -677
- {chemql_python-1.6.6 → chemql_python-1.6.7}/LICENSE +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/setup.cfg +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/__main__.py +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/build.py +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/colors.json +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/data/BondEnergies.json +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/data/MoleculeBonds.json +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/data/Molecules.json +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/data/PeriodicTableJSON.json +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/data/Reactions.json +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/data/THIRD_PARTY_LICENSES/PeriodicTableJSON.txt +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/data/THIRD_PARTY_LICENSES/RHEA.txt +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/highlighting.py +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/html/periodic_table.html +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/README.md +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/collections.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/datetime.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/decimal.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/fractions.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/json.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/math/statistics.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/math.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/pathlib.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/random.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql/stdlib/text.cql +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql_python.egg-info/dependency_links.txt +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql_python.egg-info/entry_points.txt +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql_python.egg-info/requires.txt +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/src/chemql_python.egg-info/top_level.txt +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/tests/test_codecql.py +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/tests/test_external_molecule_lookup.py +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/tests/test_public_api.py +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/tests/test_reactions.py +0 -0
- {chemql_python-1.6.6 → chemql_python-1.6.7}/tests/test_stdlib.py +0 -0
|
@@ -0,0 +1,888 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chemql-python
|
|
3
|
+
Version: 1.6.7
|
|
4
|
+
Summary: A chemistry-focused query language and REPL
|
|
5
|
+
Author-email: Mohammad Rakibul Islam <rakibulofficial1017@gmail.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: prompt_toolkit>=3.0
|
|
10
|
+
Requires-Dist: rich>=13.7
|
|
11
|
+
Provides-Extra: test
|
|
12
|
+
Requires-Dist: pytest>=8.0; extra == "test"
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# ChemQL & CodecQL
|
|
16
|
+
|
|
17
|
+
> A Python-embedded query language and terminal toolchain for chemistry data — with a purpose-built editor, package manager, and standard library.
|
|
18
|
+
|
|
19
|
+
ChemQL is a small language for querying, computing with, and simulating chemistry data (elements, molecules, reactions), layered on a Python runtime. It ships with an interactive REPL, a terminal editor (CodecQL), a type system (structs, records, enums), namespaces, modules, a macro/preprocessor system, a package manager, and a standard library.
|
|
20
|
+
|
|
21
|
+
- **Distribution name:** `chemql-python`
|
|
22
|
+
- **Import / CLI name:** `chemql`
|
|
23
|
+
- **Language version:** `1.6.7` (per `chemql.__version__`)
|
|
24
|
+
- **Editor version:** `codecql 0.1.1`
|
|
25
|
+
- **Python import / CLI name:** `chemql`
|
|
26
|
+
- **Author:** Mohammad Rakibul Islam
|
|
27
|
+
- **Minimum Python:** **3.12+** (verified with `vermin`)
|
|
28
|
+
- **Registry:** `https://chemqlreg.pythonanywhere.com/`
|
|
29
|
+
|
|
30
|
+
> ⚠️ **Safety:** ChemQL executes embedded Python (`[ ... ]`, `[[[ ... ]]]`) and real shell commands (`` ` ... ` ``, ` ``` ` blocks) with the permissions of the running process. Only run code and packages you trust.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install chemql-python
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Verify:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
chemql --version
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Python **3.12+** is required. The project's minimum version is checked with [`vermin`](https://github.com/netromdk/vermin).
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Quick start
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
$ chemql
|
|
54
|
+
Type help or ? for help
|
|
55
|
+
>>> search elements name like "Hydrogen"
|
|
56
|
+
H (Hydrogen)
|
|
57
|
+
>>> search molecules molecular_weight < 20 sort molecular_weight
|
|
58
|
+
H₂ (Hydrogen)
|
|
59
|
+
>>> balance H2 + O2 -> H2O
|
|
60
|
+
2 H₂ + O₂ → 2 H₂O
|
|
61
|
+
>>> let water = {{ findmol "Water" }}
|
|
62
|
+
>>> water.smiles
|
|
63
|
+
O
|
|
64
|
+
>>> findmol "caffeine" return name formula molecular_weight
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Non-interactive:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
chemql -c 'search elements symbol = "Fe" return name symbol number'
|
|
71
|
+
chemql -f script.cql
|
|
72
|
+
chemql -f script.cql -o out.txt # ANSI-stripped output to a file
|
|
73
|
+
chemql --no-ansi
|
|
74
|
+
chemql --suppress-warnings
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Open a file in the bundled editor:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
chemql edit script.cql
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Core commands
|
|
86
|
+
|
|
87
|
+
| Command | Purpose |
|
|
88
|
+
|---|---|
|
|
89
|
+
| `search [first\|last\|all] <source> <conditions> [ops] [return fields]` | Query a data source |
|
|
90
|
+
| `source <elements\|molecules\|reactions>` | Set the default source |
|
|
91
|
+
| `findel <name-or-symbol> [return …]` | Element lookup |
|
|
92
|
+
| `findmol <name-or-formula> [return …]` | Molecule lookup (local → PubChem → ChemSpider → NIST) |
|
|
93
|
+
| `findre <name-or-id> [return …]` | Reaction lookup (local → Rhea → Chempirical) |
|
|
94
|
+
| `balance <reactants> ->\|<-> <products>` | Balance a chemical equation |
|
|
95
|
+
| `react <coefficients><molecules…>` | Match a stored reaction under current conditions |
|
|
96
|
+
| `set temperature\|pressure\|catalysts <value>` | Set reaction conditions |
|
|
97
|
+
| `add\|remove catalyst "<name>"` | Modify the catalyst list |
|
|
98
|
+
| `conditions` | Show current T / P / catalysts |
|
|
99
|
+
| `let <name> = <expr>` / `unset <name>` / `variables` | Bind, remove, list variables |
|
|
100
|
+
| `define NAME <value>` / `@NAME` | Object-like macro |
|
|
101
|
+
| `define NAME{} … enddefine` / `@NAME{…}` | Function-like macro |
|
|
102
|
+
| `definitions` / `macros` / `remove definition\|macro NAME` | Inspect / remove |
|
|
103
|
+
| `func NAME … endfunc` | Define a function |
|
|
104
|
+
| `static func Type.method … endfunc` | Static method |
|
|
105
|
+
| `struct` / `record` / `enum` … `end*` | Define types |
|
|
106
|
+
| `namespace NAME … endnamespace` | Group declarations with visibility |
|
|
107
|
+
| `load <pkg> [as <alias>]` / `load <member> from <pkg> [as <alias>]` | Load packages |
|
|
108
|
+
| `help [topic]` / `?` | Help |
|
|
109
|
+
| `dump [all\|good\|bad] [queries\|results] FILE` | Export execution history |
|
|
110
|
+
| `view` | Open the periodic-table viewer in a browser |
|
|
111
|
+
| `clear` / `version` / `exit` | Misc |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Query syntax
|
|
116
|
+
|
|
117
|
+
**Sources:** `elements`, `molecules`, `reactions`.
|
|
118
|
+
|
|
119
|
+
**Operators:**
|
|
120
|
+
|
|
121
|
+
| Operator | Meaning |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `=` `!=` `>` `<` `>=` `<=` | Comparison (type-converted against the field) |
|
|
124
|
+
| `like` | Case-insensitive wildcard match |
|
|
125
|
+
| `like!` | Case-sensitive wildcard match |
|
|
126
|
+
| `likep` | Regex match |
|
|
127
|
+
| `has` | Nested containment (exact for `molecule` fields) |
|
|
128
|
+
| `and` `or` `not` `( )` | Boolean logic |
|
|
129
|
+
|
|
130
|
+
**`like` wildcard language** (not SQL):
|
|
131
|
+
|
|
132
|
+
| Token | Matches |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `*` | Any characters |
|
|
135
|
+
| `%` | Digits only |
|
|
136
|
+
| `&` | Letters only |
|
|
137
|
+
| `_` | Any single character |
|
|
138
|
+
| `#` | A single digit |
|
|
139
|
+
| `?` | A single letter |
|
|
140
|
+
| `\` | Escape |
|
|
141
|
+
|
|
142
|
+
**Result operations:** `sort FIELD [asc|desc]`, `limit N`, `count`, `return FIELD …`, and set ops `union` / `intersection`.
|
|
143
|
+
|
|
144
|
+
Examples:
|
|
145
|
+
|
|
146
|
+
```chemql
|
|
147
|
+
search elements number > 10 and number < 20 return name symbol
|
|
148
|
+
search molecules molecular_weight < 50 sort molecular_weight limit 10
|
|
149
|
+
search reactions reversible = true return name equation source
|
|
150
|
+
search elements name like "H*"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Chemistry features
|
|
156
|
+
|
|
157
|
+
### Data
|
|
158
|
+
|
|
159
|
+
Bundled JSON under `chemql/data/`:
|
|
160
|
+
|
|
161
|
+
| File | Purpose |
|
|
162
|
+
|---|---|
|
|
163
|
+
| `PeriodicTableJSON.json` | Element metadata (number, symbol, mass, category, phase, …) |
|
|
164
|
+
| `Molecules.json` | Molecule records: formula, IUPAC name, SMILES, CID, mp/bp/density/state |
|
|
165
|
+
| `Reactions.json` | Curated reactions, plus Rhea imports (see provenance) |
|
|
166
|
+
| `MoleculeBonds.json` | Bond connectivity per molecule |
|
|
167
|
+
| `BondEnergies.json` | Bond energy table used for ΔH estimates |
|
|
168
|
+
|
|
169
|
+
Reference conditions are °C at 1 atm (mp/bp), g/cm³ at 25 °C (density), and `state` at 25 °C / 1 atm.
|
|
170
|
+
|
|
171
|
+
### External lookups
|
|
172
|
+
|
|
173
|
+
`findmol` and `findre` fall back to public APIs when local data misses:
|
|
174
|
+
|
|
175
|
+
- **Molecules:** PubChem → ChemSpider (needs `CHEMSPIDER_API_KEY`) → NIST WebBook
|
|
176
|
+
- **Reactions:** Rhea → Chempirical
|
|
177
|
+
|
|
178
|
+
`search` itself stays **local** (offline-safe).
|
|
179
|
+
|
|
180
|
+
### Balancing
|
|
181
|
+
|
|
182
|
+
`balance` builds an element × species matrix and solves it with exact `Fraction` Gaussian elimination, returning smallest-integer coefficients. It fails clearly when the balance is not unique.
|
|
183
|
+
|
|
184
|
+
### Reaction simulation
|
|
185
|
+
|
|
186
|
+
`react` matches the supplied reactants (forward, or reverse for reversible reactions) against `REACTIONS`, gated by current conditions:
|
|
187
|
+
|
|
188
|
+
- Temperature tolerance: **±5 K**
|
|
189
|
+
- Pressure tolerance: **±5 %**
|
|
190
|
+
- Catalysts: required set must be a **subset** of available
|
|
191
|
+
|
|
192
|
+
### Chemistry built-ins
|
|
193
|
+
|
|
194
|
+
| Built-in | Description |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `element{symbol, field?}` | Periodic-table lookup |
|
|
197
|
+
| `count_atoms{formula, symbol}` | Atoms of one element in a formula (handles nested parentheses) |
|
|
198
|
+
| `molar_mass{formula}` | Molar mass |
|
|
199
|
+
| `empirical_formula{formula}` | Reduced formula |
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## Type system
|
|
204
|
+
|
|
205
|
+
### Structs — mutable, methods, inheritance
|
|
206
|
+
|
|
207
|
+
```chemql
|
|
208
|
+
struct Fruit
|
|
209
|
+
name!
|
|
210
|
+
weight = 1.0
|
|
211
|
+
endstruct
|
|
212
|
+
|
|
213
|
+
struct Apple from Fruit
|
|
214
|
+
appletype
|
|
215
|
+
endstruct
|
|
216
|
+
|
|
217
|
+
func Fruit.talk
|
|
218
|
+
if this.weight is not None
|
|
219
|
+
return "I am a " + this.name
|
|
220
|
+
endif
|
|
221
|
+
return "I am a " + this.name
|
|
222
|
+
endfunc
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
- `name!` or `required name` — required field
|
|
226
|
+
- `name = value` — optional with default (`None` if omitted)
|
|
227
|
+
- `required` / `!` **cannot** be combined with `=` (rejected at `endstruct`)
|
|
228
|
+
- Field ordering is normalized automatically
|
|
229
|
+
- Subclass field redeclaration overrides or strips the default
|
|
230
|
+
- `func Type.method` — instance method (`this`); `static func` — static
|
|
231
|
+
- Structs can inherit from **structs, records, or Python classes**
|
|
232
|
+
|
|
233
|
+
### Records — immutable, positional, trailing defaults
|
|
234
|
+
|
|
235
|
+
```chemql
|
|
236
|
+
record Point
|
|
237
|
+
x
|
|
238
|
+
y
|
|
239
|
+
z = 0
|
|
240
|
+
endrecord
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
- Every field is required unless it has a default
|
|
244
|
+
- Defaulted fields must be **trailing** (rejected otherwise)
|
|
245
|
+
- Instances are **immutable** (`can't set attribute`)
|
|
246
|
+
- Elementwise operator overloading (`+ - * / // % **`, unary `-`, `abs`)
|
|
247
|
+
- Records inherit **only** from records
|
|
248
|
+
- No in-language methods (hybrid-Python only)
|
|
249
|
+
|
|
250
|
+
### Enums — named singletons with payloads
|
|
251
|
+
|
|
252
|
+
```chemql
|
|
253
|
+
enum Level
|
|
254
|
+
low = 25
|
|
255
|
+
mid = 50
|
|
256
|
+
high = 75
|
|
257
|
+
endenum
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
- Auto-numbering starts at `1` when `=` is omitted
|
|
261
|
+
- `Level::low::value` → `25`; `Level::low::name` → `"low"`
|
|
262
|
+
- Equality is **identity-based** (`Level::low == 25` is `False`)
|
|
263
|
+
- Members cannot be reassigned
|
|
264
|
+
- Enums inherit from enums; **no methods**
|
|
265
|
+
|
|
266
|
+
### Summary
|
|
267
|
+
|
|
268
|
+
| | mutable | defaults | methods | inheritance |
|
|
269
|
+
|---|---|---|---|---|
|
|
270
|
+
| **struct** | yes | required / optional / defaulted | yes (incl. static) | structs, records, Python classes |
|
|
271
|
+
| **record** | no | trailing only | no (hybrid only) | records only |
|
|
272
|
+
| **enum** | no | auto-increment | no | enums only |
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Namespaces & visibility
|
|
277
|
+
|
|
278
|
+
```chemql
|
|
279
|
+
namespace foo
|
|
280
|
+
public let x = 10
|
|
281
|
+
private let y = 20
|
|
282
|
+
let z = 30 // private by default
|
|
283
|
+
endnamespace
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
- **Default visibility is private** for namespace members
|
|
287
|
+
- `public` / `private` applies to `let`, `func`, `struct`, `record`, `enum`, `namespace`
|
|
288
|
+
- Reading a private member raises an error mentioning it is set to private
|
|
289
|
+
- Code inside the namespace can access its own private members
|
|
290
|
+
- Missing members produce a distinct "no attribute" error
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Modules
|
|
295
|
+
|
|
296
|
+
`.cql` files can be loaded as packages:
|
|
297
|
+
|
|
298
|
+
```chemql
|
|
299
|
+
// foo.cql
|
|
300
|
+
public func isEven
|
|
301
|
+
return \1 % 2 == 0
|
|
302
|
+
endfunc
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
```chemql
|
|
306
|
+
// bar.cql
|
|
307
|
+
load foo
|
|
308
|
+
foo::isEven{3}
|
|
309
|
+
|
|
310
|
+
load isEven from foo
|
|
311
|
+
isEven{4}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
- `load pkg` → `pkg::name` access; only `public` members
|
|
315
|
+
- `load member from pkg [as alias]` → import one member
|
|
316
|
+
- Cross-module private access raises `PermissionError`
|
|
317
|
+
- Packages live in `./`, `~/.chemql/packages/<name>/<version>/`, or `chemql/stdlib/`
|
|
318
|
+
- Override root with `CHEMQL_PACKAGE_DIR`
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Functions, arguments, macros
|
|
323
|
+
|
|
324
|
+
```chemql
|
|
325
|
+
func square
|
|
326
|
+
return \1 * \1
|
|
327
|
+
endfunc
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
**Two access forms:**
|
|
331
|
+
|
|
332
|
+
- `\1`, `\2`, … — 1-indexed positional placeholders, **substituted textually** (works inside strings; `\10` = tenth argument, greedy `\d+`)
|
|
333
|
+
- `arguments` — a per-call `list` of positional arguments, `arguments[0]` indexed from 0, **function scope only**
|
|
334
|
+
|
|
335
|
+
> ⚠️ `arguments` is not available in macro bodies — macros get `\N` only.
|
|
336
|
+
|
|
337
|
+
### Definitions (object-like)
|
|
338
|
+
|
|
339
|
+
```chemql
|
|
340
|
+
define MAX 9
|
|
341
|
+
@MAX * 9 // 81
|
|
342
|
+
print("2@MAX") // "29"
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
- `@NAME` expands textually, including inside strings
|
|
346
|
+
- One name slot shared with macros; **definitions win** on collision
|
|
347
|
+
- `remove definition NAME` (or `remove definition @NAME`)
|
|
348
|
+
|
|
349
|
+
### Macros (function-like)
|
|
350
|
+
|
|
351
|
+
```chemql
|
|
352
|
+
define MAX{}
|
|
353
|
+
\1 if \1 > \2 else \2
|
|
354
|
+
enddefine
|
|
355
|
+
|
|
356
|
+
@MAX{1, 3} // 3
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
- Body uses `\N`; `arguments` is **not** available
|
|
360
|
+
- Macros may expand other macros (multi-pass)
|
|
361
|
+
- `remove macro NAME`
|
|
362
|
+
|
|
363
|
+
> **Gotcha:** defining `NAME{}` while `NAME = value` exists makes the macro unreachable until `remove definition NAME`.
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## Control flow
|
|
368
|
+
|
|
369
|
+
```chemql
|
|
370
|
+
if x > 10
|
|
371
|
+
let y = "big"
|
|
372
|
+
elif x > 5
|
|
373
|
+
let y = "medium"
|
|
374
|
+
else
|
|
375
|
+
let y = "small"
|
|
376
|
+
endif
|
|
377
|
+
|
|
378
|
+
for i in range(3)
|
|
379
|
+
print(i)
|
|
380
|
+
endfor
|
|
381
|
+
|
|
382
|
+
while i < 5
|
|
383
|
+
let i = i + 1
|
|
384
|
+
endwhile
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
- `break` / `continue` / `skip` (alias for continue)
|
|
388
|
+
- Bracketed Python-style blocks also accepted: `[for …] … [endblock]`
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## Error handling
|
|
393
|
+
|
|
394
|
+
```chemql
|
|
395
|
+
risk
|
|
396
|
+
signal "Something went wrong"
|
|
397
|
+
fix
|
|
398
|
+
let handled = error
|
|
399
|
+
cleanup
|
|
400
|
+
let finished = true
|
|
401
|
+
endrisk
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
- `signal "msg"` raises a recoverable ChemQL signal
|
|
405
|
+
- `warn "msg"` sets `warnings` and prints (suppress with `--suppress-warnings`)
|
|
406
|
+
- `error` holds the last error type (or `None` after success)
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
## Python integration
|
|
411
|
+
|
|
412
|
+
Inline expression:
|
|
413
|
+
|
|
414
|
+
```chemql
|
|
415
|
+
[1 + 2 * 3] // 7
|
|
416
|
+
[x * 2]
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
Multiline Python block:
|
|
420
|
+
|
|
421
|
+
```chemql
|
|
422
|
+
[[[
|
|
423
|
+
for x in range(3):
|
|
424
|
+
print(x)
|
|
425
|
+
]]]
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
Embedded queries inside Python:
|
|
429
|
+
|
|
430
|
+
```chemql
|
|
431
|
+
let m = [len({{ search molecules molecular_weight < 20 }})]
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Attribute access, `{{ }}` queries, and `::` namespace paths are rewritten before evaluation.
|
|
435
|
+
|
|
436
|
+
> **Safety reminder:** all of the above runs with your user's permissions.
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## Shell integration
|
|
441
|
+
|
|
442
|
+
Inline:
|
|
443
|
+
|
|
444
|
+
```chemql
|
|
445
|
+
`ls -la`
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Multiline:
|
|
449
|
+
|
|
450
|
+
````
|
|
451
|
+
```bash
|
|
452
|
+
cd /tmp
|
|
453
|
+
ls
|
|
454
|
+
```
|
|
455
|
+
````
|
|
456
|
+
|
|
457
|
+
- **POSIX:** persistent Bash via a PTY with a unique prompt handshake
|
|
458
|
+
- **Windows:** persistent PowerShell request/marker loop
|
|
459
|
+
- `clear` / `cls` bypass the shell
|
|
460
|
+
|
|
461
|
+
---
|
|
462
|
+
|
|
463
|
+
## CodecQL — the terminal editor
|
|
464
|
+
|
|
465
|
+
**A small terminal editor built for ChemQL.** Syntax highlighting, inline suggestions, a built-in terminal pane, and one-key execution — nothing to configure to get started.
|
|
466
|
+
|
|
467
|
+
| | |
|
|
468
|
+
|---|---|
|
|
469
|
+
| Version | 0.1.1 |
|
|
470
|
+
| Ships with | `chemql-python` |
|
|
471
|
+
| Files | `.cql` (ChemQL), `.py`, `cqlpackage.json` / `cqlpackage.toml`, and any plain-text file |
|
|
472
|
+
|
|
473
|
+
### Starting CodecQL
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
chemql edit FILE # open (or create) a file
|
|
477
|
+
python -m chemql.codecql FILE # equivalent
|
|
478
|
+
chemql edit --main-highlighting # edit the highlighting.json shipped with the package
|
|
479
|
+
chemql edit --local-highlighting # edit ./highlighting.json (created as {} if missing)
|
|
480
|
+
chemql edit --version
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
If your installation also registers a `codecql` console script, `codecql FILE` accepts the same options.
|
|
484
|
+
|
|
485
|
+
Opening a path that does not exist starts an empty buffer; it is created on the first save.
|
|
486
|
+
|
|
487
|
+
**Requirements:** the same as ChemQL (Python 3.12+), plus a terminal that understands ANSI escape sequences and 256 colours. On Windows, `colorama` is used when installed; otherwise virtual-terminal mode is enabled directly. Copying to the system clipboard needs one of `clip` (Windows), `clip.exe` (WSL), `pbcopy` (macOS), or `wl-copy` / `xclip` / `xsel` (Linux).
|
|
488
|
+
|
|
489
|
+
### Key bindings
|
|
490
|
+
|
|
491
|
+
| Key | Action |
|
|
492
|
+
|---|---|
|
|
493
|
+
| `Ctrl+S` | Save |
|
|
494
|
+
| `Ctrl+Q` | Quit. With unsaved changes, press it a second time to quit without saving |
|
|
495
|
+
| `Ctrl+Z` / `Ctrl+Y` | Undo / redo (last 200 edits) |
|
|
496
|
+
| `Ctrl+F` | Search |
|
|
497
|
+
| `Ctrl+R` | Save, then run the file |
|
|
498
|
+
| `Ctrl+T` | Open a terminal pane |
|
|
499
|
+
| `Tab` | Accept the inline suggestion; with none showing, insert a tab |
|
|
500
|
+
| `Enter` | New line, keeping the current indentation |
|
|
501
|
+
| Arrow keys, `Home`, `End` | Move |
|
|
502
|
+
| `Shift` + movement | Select |
|
|
503
|
+
| `Ctrl`/`Alt` + `←` `→` | Move by word |
|
|
504
|
+
| `Ctrl` + `↑` `↓` | Scroll the view without moving the text |
|
|
505
|
+
| `Backspace`, `Delete` | Delete a character, or the selection |
|
|
506
|
+
| `Ctrl+Backspace` / `Alt+Backspace` | Delete the word to the left |
|
|
507
|
+
| `Ctrl+Delete` / `Alt+Delete` | Delete the word to the right |
|
|
508
|
+
| `Ctrl+C` / `Ctrl+Insert` | Copy the selection (editor + system clipboard when available). It does **not** quit |
|
|
509
|
+
| `Ctrl+X` | Cut the selection |
|
|
510
|
+
| `Ctrl+V` / `Shift+Insert` | Paste the editor's clipboard |
|
|
511
|
+
|
|
512
|
+
Pasting from your terminal or OS clipboard also works: CodecQL enables bracketed paste, so multi-line pastes arrive as a single insertion.
|
|
513
|
+
|
|
514
|
+
**Auto-indent.** After a line that opens a block (`func`, `define NAME{}`, `struct`, `record`, `enum`, `namespace`, `if`, `elif`, `else`, `for`, `while`) or ends in a `\` continuation, the next line is indented with a tab. Pressing Enter after `endnamespace` removes one level of indentation. Other `end...` keywords do not dedent automatically.
|
|
515
|
+
|
|
516
|
+
**Status bar and footer.** The bar shows the file name, `Ln`/`Col`, the line count, `Unsaved` when the buffer is dirty, and search status. The footer shows messages and a reminder of the main shortcuts.
|
|
517
|
+
|
|
518
|
+
### Search
|
|
519
|
+
|
|
520
|
+
Press `Ctrl+F` and type; matches are highlighted as you type.
|
|
521
|
+
|
|
522
|
+
| Key | Action |
|
|
523
|
+
|---|---|
|
|
524
|
+
| `Enter`, `↓`, `→` | Next match |
|
|
525
|
+
| `↑`, `←` | Previous match |
|
|
526
|
+
| `Esc`, `Ctrl+C` | Close search |
|
|
527
|
+
|
|
528
|
+
A plain query is a **literal, case-insensitive** search. Add a flag prefix followed by `:` to change that:
|
|
529
|
+
|
|
530
|
+
| Flag | Meaning |
|
|
531
|
+
|---|---|
|
|
532
|
+
| `r` | Treat the query as a regular expression |
|
|
533
|
+
| `l` | Treat the query as literal text (the default; cannot be combined with `r`) |
|
|
534
|
+
| `w` | Match whole words only |
|
|
535
|
+
| `i` | Ignore case |
|
|
536
|
+
|
|
537
|
+
Once any flag is given, matching becomes case-sensitive unless `i` is included.
|
|
538
|
+
|
|
539
|
+
```text
|
|
540
|
+
water literal, case-insensitive
|
|
541
|
+
l:Water literal, case-sensitive
|
|
542
|
+
r:^search\s regular expression, case-sensitive
|
|
543
|
+
ri:^search\s regular expression, case-insensitive
|
|
544
|
+
wi:set whole word "set", case-insensitive
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
An invalid regular expression is reported in the status bar.
|
|
548
|
+
|
|
549
|
+
### Running code and the terminal pane
|
|
550
|
+
|
|
551
|
+
**`Ctrl+R`** saves the file (if it has unsaved changes) and runs the command configured for its extension. The default for `.cql` is:
|
|
552
|
+
|
|
553
|
+
```text
|
|
554
|
+
chemql -f $absoluteName
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
`$absoluteName` is replaced by the shell-quoted absolute path. Set your own with `run-command` in `highlighting.json`; the bundled configuration also runs `.py` files with `python -u` and `.rs` files with `cargo run`. The file must have a name before it can be run.
|
|
558
|
+
|
|
559
|
+
**`Ctrl+T`** opens a plain terminal without running anything.
|
|
560
|
+
|
|
561
|
+
| Platform | Behaviour |
|
|
562
|
+
|---|---|
|
|
563
|
+
| Linux, macOS, WSL | A pane opens in the bottom third of the screen running your `$SHELL` (`-i`). `Ctrl+↑` / `Ctrl+↓` resize it. `Ctrl+T`, `Ctrl+Q` or `Esc` closes it and returns to the editor. |
|
|
564
|
+
| Windows Terminal | The command runs in a new split pane beside the editor. Close it by exiting the shell. |
|
|
565
|
+
| Other Windows consoles | The command runs in a separate console window. |
|
|
566
|
+
|
|
567
|
+
### Syntax highlighting
|
|
568
|
+
|
|
569
|
+
What is coloured depends on the file:
|
|
570
|
+
|
|
571
|
+
| File | Highlighting |
|
|
572
|
+
|---|---|
|
|
573
|
+
| `.cql` | Comments (`//`, `#`), strings, numbers (including units such as `25C`, `1atm`), chemical formulas (`H2O`, `NaCl`), operators, delimiters (`{{ }}`, `[[[ ]]]`, brackets), commands, control keywords, word operators (`and`, `like`, `sort`, ...), sources, reaction conditions, field names, Python built-ins, `True`/`False`/`None`, and the name after `enum`/`struct`/`record`/`namespace` |
|
|
574
|
+
| `.py` | Python keywords, built-ins and constants, plus comments, strings, numbers and operators |
|
|
575
|
+
| `cqlpackage.json`, `cqlpackage.toml` | Keys, strings, numbers, booleans, TOML tables and comments |
|
|
576
|
+
| anything else | Comments, strings, numbers, operators and delimiters only |
|
|
577
|
+
|
|
578
|
+
Highlighting is purely lexical and line-based: it never changes the file. Extensions are matched case-insensitively.
|
|
579
|
+
|
|
580
|
+
### Inline suggestions
|
|
581
|
+
|
|
582
|
+
While you type at the **end of a line**, CodecQL shows a grey "ghost" completion. Press `Tab` to accept it. Suggestions are context-aware: they depend on what comes before the cursor on the line (and, for queries, on the most recent `source` command above it).
|
|
583
|
+
|
|
584
|
+
```text
|
|
585
|
+
se| -> search
|
|
586
|
+
search | -> search elements
|
|
587
|
+
search elements na| -> search elements name
|
|
588
|
+
search elements atomic_mass | -> search elements atomic_mass >
|
|
589
|
+
search elements phase = | -> search elements phase = "Gas"
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
Suggestions are driven entirely by the `suggestions` rules in `highlighting.json`, so you can change or extend them without touching Python. They are only offered when the cursor is at the end of the line and nothing is selected.
|
|
593
|
+
|
|
594
|
+
### Configuration: `highlighting.json`
|
|
595
|
+
|
|
596
|
+
CodecQL loads configuration from two places, in this order:
|
|
597
|
+
|
|
598
|
+
1. `highlighting.json` in the package directory (`chemql edit --main-highlighting` opens it)
|
|
599
|
+
2. `highlighting.json` in the current working directory (`chemql edit --local-highlighting` opens it)
|
|
600
|
+
|
|
601
|
+
> **Each extension's profile is replaced as a whole.** If the local file defines `".cql"`, it completely replaces the main file's `.cql` profile, including its `run-command` and `suggestions`. Copy what you want to keep.
|
|
602
|
+
|
|
603
|
+
#### Profile format
|
|
604
|
+
|
|
605
|
+
The top level maps file extensions to profiles. A leading dot is added if you omit it, and extensions are lower-cased.
|
|
606
|
+
|
|
607
|
+
```json
|
|
608
|
+
{
|
|
609
|
+
".cql": {
|
|
610
|
+
"run-command": "chemql -f $absoluteName",
|
|
611
|
+
"rules": [],
|
|
612
|
+
"suggestions": []
|
|
613
|
+
},
|
|
614
|
+
".py": {
|
|
615
|
+
"run-command": "python -u $absoluteName",
|
|
616
|
+
"rules": []
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
| Field | Description |
|
|
622
|
+
|---|---|
|
|
623
|
+
| `run-command` | Command run by `Ctrl+R`. `$absoluteName` is replaced by the quoted path. |
|
|
624
|
+
| `rules` | Highlighting rules (below). |
|
|
625
|
+
| `suggestions` | Suggestion rules (below). |
|
|
626
|
+
|
|
627
|
+
An older format, where an extension maps directly to a list of rules, is still accepted. Unknown profile fields and duplicate extensions are rejected, and a configuration error is reported when the file is loaded.
|
|
628
|
+
|
|
629
|
+
#### Highlighting rules
|
|
630
|
+
|
|
631
|
+
```json
|
|
632
|
+
{
|
|
633
|
+
"name": "my-keywords",
|
|
634
|
+
"type": "keywords",
|
|
635
|
+
"values": ["alpha", "beta"],
|
|
636
|
+
"style": "keyword"
|
|
637
|
+
}
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
| Field | Description |
|
|
641
|
+
|---|---|
|
|
642
|
+
| `name` | Non-empty label |
|
|
643
|
+
| `type` | `keywords` or `regex` |
|
|
644
|
+
| `values` | For `keywords`: a non-empty list of words. Matching is case-insensitive |
|
|
645
|
+
| `pattern`, `case_sensitive` | For `regex`: a valid regular expression, and whether it is case-sensitive (default `true`) |
|
|
646
|
+
| `style` | A style string, below |
|
|
647
|
+
|
|
648
|
+
Rules are checked in order and the first matching keyword wins. A keyword rule takes priority over CodecQL's built-in categories for that extension, so with an empty `rules` list for `.cql` the built-in ChemQL highlighting applies unchanged.
|
|
649
|
+
|
|
650
|
+
> ⚠️ Currently only `keywords` rules affect how text is drawn. `regex` rules are validated but **not yet applied**.
|
|
651
|
+
|
|
652
|
+
**Style strings** combine space-separated parts:
|
|
653
|
+
|
|
654
|
+
| Part | Effect |
|
|
655
|
+
|---|---|
|
|
656
|
+
| `keyword` `command` `operator` `string` `comment` `number` `constant` `type` `source` `condition` `property` `builtin` | A colour from the current theme |
|
|
657
|
+
| `bold` `dim` `italic` `underline` `reverse` `strike` | Text attributes |
|
|
658
|
+
| `#rrggbb` | 24-bit foreground colour |
|
|
659
|
+
| `bg:#rrggbb` | 24-bit background colour |
|
|
660
|
+
|
|
661
|
+
```json
|
|
662
|
+
"style": "bold #ff8800"
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
An unknown part is an error, so stick to this list.
|
|
666
|
+
|
|
667
|
+
#### Example: highlighting a new language
|
|
668
|
+
|
|
669
|
+
```json
|
|
670
|
+
{
|
|
671
|
+
".toml": {
|
|
672
|
+
"run-command": "cat $absoluteName",
|
|
673
|
+
"rules": [
|
|
674
|
+
{"name": "booleans", "type": "keywords", "values": ["true", "false"], "style": "constant"}
|
|
675
|
+
]
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
### Suggestion rules in depth
|
|
681
|
+
|
|
682
|
+
A suggestion rule says: *when the text before the cursor looks like this, offer these completions.*
|
|
683
|
+
|
|
684
|
+
```json
|
|
685
|
+
{
|
|
686
|
+
"name": "second-word",
|
|
687
|
+
"pattern": "(?:^|;|\\{\\{)\\s*search\\s+$",
|
|
688
|
+
"min-prefix": 0,
|
|
689
|
+
"suggestions": ["elements", "molecules", "reactions"]
|
|
690
|
+
}
|
|
691
|
+
```
|
|
692
|
+
|
|
693
|
+
| Field | Description |
|
|
694
|
+
|---|---|
|
|
695
|
+
| `name` | Unique, non-empty. Used by `$name$` references |
|
|
696
|
+
| `pattern` | Regular expression, searched **case-insensitively** in the *context* (below) |
|
|
697
|
+
| `suggestions` | Non-empty list of completions |
|
|
698
|
+
| `min-prefix` | Minimum number of characters already typed in the current word before the rule applies (default `0`) |
|
|
699
|
+
|
|
700
|
+
#### How a rule is chosen
|
|
701
|
+
|
|
702
|
+
1. The line up to the cursor is split into a **prefix** (the run of non-whitespace characters just before the cursor) and a **context** (everything before that prefix, including whitespace).
|
|
703
|
+
2. Rules are tried **in order**. The **first** rule whose pattern matches the context wins, and no later rule is consulted, even if the winner offers nothing for the current prefix.
|
|
704
|
+
3. From the winner's `suggestions`, the first entry that starts with the prefix (case-insensitively) and is longer than it is chosen. The untyped remainder is shown as ghost text, and `Tab` inserts it.
|
|
705
|
+
|
|
706
|
+
Practical consequences:
|
|
707
|
+
|
|
708
|
+
- **Order matters. Put specific rules before general ones.** A broad rule placed early will shadow everything after it.
|
|
709
|
+
- **Anchor with `$`.** To mean "the cursor follows this word", end the pattern with `\s+$`. The context always ends with the whitespace before the prefix.
|
|
710
|
+
- **Prefixes are whitespace-delimited.** In `help{ab`, the prefix is the whole `help{ab`, so completions after punctuation without a space are not possible. Design completions around spaces.
|
|
711
|
+
- **A suggestion may contain spaces.** `"{{ search elements"` is offered once the prefix is `{`, and it is inserted as a whole.
|
|
712
|
+
- **Use `min-prefix: 1` for free-form positions**, so a ghost does not appear (and `Tab` still inserts a tab) before you have typed anything.
|
|
713
|
+
- **Remember JSON escaping.** Every regex backslash is doubled: `\s` is written `"\\s"`.
|
|
714
|
+
|
|
715
|
+
#### References
|
|
716
|
+
|
|
717
|
+
| Syntax | In a `pattern` | In a `suggestions` entry |
|
|
718
|
+
|---|---|---|
|
|
719
|
+
| `$rule-name$` | Replaced by an alternation of that rule's suggestions, e.g. `(?:search\|source\|...)` | Replaced by all of that rule's suggestions |
|
|
720
|
+
| `$active-source-fields$` | *(not supported)* | Field names of the active source: the source in the current `search` statement if it names one, otherwise the most recent `source` command above the line. Empty if there is none |
|
|
721
|
+
| `$query-start-options$` | *(not supported)* | The active source's fields, or the three sources when there is no active source |
|
|
722
|
+
| `$query-operators$` | *(not supported)* | `= != > < >= <= like like! likep has and or sort limit count return first last` |
|
|
723
|
+
|
|
724
|
+
A `$rule-name$` reference must point at a rule defined **earlier** in the list, which also rules out cycles. References are expanded one level: a referenced rule's own `$...$` entries are not expanded further.
|
|
725
|
+
|
|
726
|
+
#### Reference-only rules
|
|
727
|
+
|
|
728
|
+
A rule whose pattern is `(?!)` can never match, so it never fires. The bundled configuration uses this to hold named lists, such as all field names or all operators, which later rules splice into their patterns and suggestions:
|
|
729
|
+
|
|
730
|
+
```json
|
|
731
|
+
{ "name": "operators", "pattern": "(?!)", "min-prefix": 0,
|
|
732
|
+
"suggestions": ["=", "!=", ">", "<", ">=", "<=", "like", "like!", "likep", "has"] }
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
A later rule can then recognise "a field name followed by an operator" with `\\s(?:$all-fields$)\\s+(?:$operators$)\\s+$`.
|
|
736
|
+
|
|
737
|
+
#### Testing a rule
|
|
738
|
+
|
|
739
|
+
The engine is plain Python, so you can try rules without opening the editor:
|
|
740
|
+
|
|
741
|
+
```python
|
|
742
|
+
from chemql.highlighting import HighlightProfiles
|
|
743
|
+
|
|
744
|
+
profiles = HighlightProfiles("highlighting.json")
|
|
745
|
+
line = "search elements atomic_mass "
|
|
746
|
+
suffix = profiles.get_suggestion_suffix("x.cql", line, len(line), previous_lines=[])
|
|
747
|
+
print(line + suffix) # search elements atomic_mass >
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
`previous_lines` supplies the lines above, which is how the active `source` is found.
|
|
751
|
+
|
|
752
|
+
### What the bundled rules complete
|
|
753
|
+
|
|
754
|
+
The shipped `highlighting.json` defines about 70 rules for `.cql`. In summary:
|
|
755
|
+
|
|
756
|
+
| Context | Suggests |
|
|
757
|
+
|---|---|
|
|
758
|
+
| Start of a line, or after `;` (after 1 character) | Every ChemQL command and block keyword |
|
|
759
|
+
| After `{{` | Query commands (`search`, `findel`, `findmol`, `findre`, ...) |
|
|
760
|
+
| `search ` | Sources, `first`/`last`/`all`, and the active source's fields |
|
|
761
|
+
| `search SOURCE ` | That source's fields, plus `not`, `sort`, `limit`, `count` |
|
|
762
|
+
| After a field | Operators that suit its type: numeric (`>` `<` `=` ...), text (`like` `=` `has` ...), collection (`has`), boolean (`=` `!=`) |
|
|
763
|
+
| After `not` | Operators, or fields when negating a whole condition |
|
|
764
|
+
| After an operator | Known values for `phase`, `category`, `block`, `state` and `reversible` |
|
|
765
|
+
| After a complete condition | `and`, `or`, `sort`, `limit`, `count`, `return`, `union`, `intersection` |
|
|
766
|
+
| After `and`, `or`, `not`, `(` | Fields |
|
|
767
|
+
| After `sort`, `limit` | Fields, `asc`/`desc`, then `limit`/`count`/`return`; common limits |
|
|
768
|
+
| After `return` | Fields |
|
|
769
|
+
| After `union` / `intersection` | `search elements` / `molecules` / `reactions` |
|
|
770
|
+
| `findel`, `findmol`, `findre` | `return`, then that source's fields |
|
|
771
|
+
| `balance` | `+`, `->`, `<->` as appropriate |
|
|
772
|
+
| `set`, `add`, `remove` | Settings, `catalyst`, common temperature, pressure and catalyst values |
|
|
773
|
+
| `source`, `list`, `dump`, `help`, `load`, `install` | Their arguments, including standard-library modules and built-in names |
|
|
774
|
+
| `let` | `=`, then query, built-in and constant starters |
|
|
775
|
+
| `public`, `private`, `static`, `struct`, `record` | Declaration keywords, `from` |
|
|
776
|
+
| `for` | `in`, then `range(` or a query |
|
|
777
|
+
|
|
778
|
+
Value suggestions for `phase`, `category` and `block` reflect the standard periodic-table dataset. If your data uses different spellings, adjust the `value-...` rules.
|
|
779
|
+
|
|
780
|
+
### Colours: `colors.json`
|
|
781
|
+
|
|
782
|
+
CodecQL reads its theme from `colors.json` next to `codecql.py`. If the file is missing, a built-in palette is used.
|
|
783
|
+
|
|
784
|
+
```json
|
|
785
|
+
{
|
|
786
|
+
"syntax": {
|
|
787
|
+
"comment": {"ansi256": 244},
|
|
788
|
+
"string": {"ansi256": 114},
|
|
789
|
+
"number": {"ansi256": 179},
|
|
790
|
+
"formula": {"ansi256": 117},
|
|
791
|
+
"operator": {"ansi256": 213},
|
|
792
|
+
"delimiter": {"ansi256": 250},
|
|
793
|
+
"command": {"ansi256": 81},
|
|
794
|
+
"keyword": {"ansi256": 141},
|
|
795
|
+
"constant": {"ansi256": 215},
|
|
796
|
+
"type": {"ansi256": 150},
|
|
797
|
+
"source": {"ansi256": 110},
|
|
798
|
+
"condition": {"ansi256": 180},
|
|
799
|
+
"property": {"ansi256": 116},
|
|
800
|
+
"builtin": {"ansi256": 222}
|
|
801
|
+
},
|
|
802
|
+
"ui": {
|
|
803
|
+
"line_numbers": {"ansi256": 244},
|
|
804
|
+
"status_background": {"ansi256": 24, "channel": "background"},
|
|
805
|
+
"status_foreground": {"ansi256": 255}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
Each entry needs an `ansi256` number from 0 to 255, and an optional `channel` of `foreground` (default) or `background`. If you provide the file, include **every** category shown above.
|
|
811
|
+
|
|
812
|
+
### CodecQL known limitations
|
|
813
|
+
|
|
814
|
+
- Files are saved with `\n` line endings and **no trailing newline**.
|
|
815
|
+
- Inline suggestions appear only when the cursor is at the end of the line.
|
|
816
|
+
- `regex` highlighting rules are validated but **not yet applied**.
|
|
817
|
+
- Auto-dedent applies only after `endnamespace`.
|
|
818
|
+
- One file per session: there are no tabs or split editors.
|
|
819
|
+
- Tabs are drawn four columns wide.
|
|
820
|
+
- CodecQL's Windows Backspace / Ctrl+Backspace are intentionally inverted relative to POSIX.
|
|
821
|
+
|
|
822
|
+
---
|
|
823
|
+
|
|
824
|
+
## Standard library
|
|
825
|
+
|
|
826
|
+
Load with `load <pkg>`; call as `<pkg>::name{…}`.
|
|
827
|
+
|
|
828
|
+
| Package | Purpose |
|
|
829
|
+
|---|---|
|
|
830
|
+
| `math` | Constants, trigonometry, logarithms, number theory |
|
|
831
|
+
| `math::statistics` | Mean, median, mode, variance, standard deviation, quantiles |
|
|
832
|
+
| `text` | String transforms, splitting/joining, regex helpers |
|
|
833
|
+
| `collections` | Uniqueness, flattening, pairing, frequency counts, product |
|
|
834
|
+
| `datetime` | Dates, timestamps, local/UTC time, date arithmetic |
|
|
835
|
+
| `json` | JSON encode/decode helpers |
|
|
836
|
+
| `random` | Pseudo-random numbers and sequence sampling |
|
|
837
|
+
| `decimal` | Base-10 decimal arithmetic and quantization |
|
|
838
|
+
| `fractions` | Exact rational numbers and fraction arithmetic |
|
|
839
|
+
| `pathlib` | Path inspection and UTF-8 text file operations |
|
|
840
|
+
|
|
841
|
+
`help{stdlib}` lists them; `help{math}` and `help{math::sqrt}` document each.
|
|
842
|
+
|
|
843
|
+
---
|
|
844
|
+
|
|
845
|
+
## Built-in functions
|
|
846
|
+
|
|
847
|
+
General: `abs round min max sum len type str int float bool upper lower contains replace split join first last unique sort reversed read_text read_lines read_json read_csv write_text write_csv write_json file_exists list_files help`
|
|
848
|
+
|
|
849
|
+
Chemistry: `element count_atoms molar_mass empirical_formula`
|
|
850
|
+
|
|
851
|
+
`help` with a topic is documented from `_BUILTIN_HELP`.
|
|
852
|
+
|
|
853
|
+
---
|
|
854
|
+
|
|
855
|
+
## Package manager
|
|
856
|
+
|
|
857
|
+
```bash
|
|
858
|
+
chemql install <name> [--version V]
|
|
859
|
+
chemql upgrade <name> [--version V]
|
|
860
|
+
chemql uninstall <name>
|
|
861
|
+
chemql list
|
|
862
|
+
chemql search <query>
|
|
863
|
+
chemql info <name>
|
|
864
|
+
chemql build # requires cqlpackage.json / cqlpackage.toml
|
|
865
|
+
chemql upload # publish to the registry
|
|
866
|
+
chemql init [name] [-d dir]
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
Inside the REPL: `install <name> [--version V]`.
|
|
870
|
+
|
|
871
|
+
Package layout:
|
|
872
|
+
|
|
873
|
+
```
|
|
874
|
+
~/.chemql/packages/<name>/<version>/
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
## License and attribution
|
|
878
|
+
|
|
879
|
+
[MIT License](https://github.com/rakibulofficial1017/ChemQL/blob/main/LICENSE)
|
|
880
|
+
|
|
881
|
+
Created by [Mohammad Rakibul Islam](https://github.com/rakibulofficial1017).
|
|
882
|
+
Source code: [rakibulofficial1017/ChemQL](https://github.com/rakibulofficial1017/ChemQL).
|
|
883
|
+
|
|
884
|
+
------------------------------------------------------------------------
|
|
885
|
+
|
|
886
|
+
For the command reference that matches your installed build, type `help`
|
|
887
|
+
inside ChemQL. Use `list all` to inspect fields available in your
|
|
888
|
+
bundled datasets.
|