Skip to content
Snippets Groups Projects
Commit 693a3f5f authored by David Sehnal's avatar David Sehnal
Browse files

wip mol-script, execute parsed/transpiled query

parent 6e17f5bb
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,6 @@ import Expression from './expression'
const { isLiteral, isSymbol, isArgumentsArray } = Expression;
export default function format(e: Expression) {
const writer = new Writer();
_format(e, writer);
return writer.getStr();
}
class Writer {
private value: string[] = [];
private currentLineLength = 0;
......@@ -128,4 +122,10 @@ function _format(e: Expression, writer: Writer) {
_format(e.args[a], writer);
}
writer.pop();
}
\ No newline at end of file
}
export function formatMolScript(e: Expression) {
const writer = new Writer();
_format(e, writer);
return writer.getStr();
}
......@@ -20,7 +20,7 @@ namespace Expression {
export function isArgumentsArray(e?: Arguments): e is Expression[] { return !!e && Array.isArray(e); }
export function isArgumentsMap(e?: Arguments): e is { [name: string]: Expression } { return !!e && !Array.isArray(e); }
export function isLiteral(e: Expression): e is Expression.Literal { return !isApply(e); }
export function isLiteral(e: Expression): e is Expression.Literal { return !isApply(e) && !isSymbol(e); }
export function isApply(e: Expression): e is Expression.Apply { return !!e && !!(e as Expression.Apply).head && typeof e === 'object'; }
export function isSymbol(e: Expression): e is Expression.Symbol { return !!e && typeof (e as any).name === 'string' }
}
......
......@@ -134,8 +134,10 @@ function _compile(ctx: QueryCompilerCtx, expression: Expression): CompiledQueryF
}
if (Expression.isSymbol(expression)) {
// TODO: check for "nullary symbols" and automatically apply them?
return CompiledQueryFn.Const(expression.name);
const runtime = ctx.table.getRuntime(expression.name);
if (!runtime) return CompiledQueryFn.Const(expression.name);
return runtime.compile(ctx);
}
if (!Expression.isSymbol(expression.head)) {
......@@ -143,7 +145,6 @@ function _compile(ctx: QueryCompilerCtx, expression: Expression): CompiledQueryF
}
const compiler = ctx.table.getRuntime(expression.head.name);
if (!compiler) {
throw new Error(`Symbol '${expression.head.name}' is not implemented.`);
}
......
This diff is collapsed.
......@@ -6,6 +6,8 @@ import { CustomPropSymbol } from 'mol-script/language/symbol';
import Type from 'mol-script/language/type';
import { parseMolScript } from 'mol-script/language/parser';
import * as util from 'util'
import { transpileMolScript } from 'mol-script/script/mol-script/symbols';
import { formatMolScript } from 'mol-script/language/expression-formatter';
// import Examples from 'mol-script/script/mol-script/examples'
// import { parseMolScript } from 'mol-script/script/mol-script/parser'
......@@ -15,14 +17,25 @@ import * as util from 'util'
// const expr = parseMolScript(e.value)[0];
// console.log(e.name, util.inspect(expr, true, 10, true));
// }
// const exprs = parseMolScript(`(sel.atom.atom-groups
// :residue-test (= atom.auth_comp_id ALA)
// ;; ho ho ho
// :atom-test (set.has { _C _N } atom.el)) ; comm
// ;; this is a comment
// ((hi) (ho))`);
const exprs = parseMolScript(`(sel.atom.atom-groups
:residue-test (= atom.auth_comp_id ALA)
;; ho ho ho
:atom-test (set.has { _C _N } atom.el)) ; comm
;; this is a comment
((hi) (ho))`);
:residue-test (= atom.label_comp_id REA)
:atom-test (= atom.el _C))`);
const tsp = transpileMolScript(exprs[0]);
//console.log(util.inspect(exprs, true, 10, true));
console.log(util.inspect(exprs, true, 10, true));
console.log(util.inspect(tsp, true, 10, true));
console.log(formatMolScript);
console.log(formatMolScript(tsp));
// //console.log(expr);
const expr = MolScriptBuilder.core.math.add([1, 2, 3]);
......@@ -49,7 +62,7 @@ export async function testQ() {
const frame = await readCifFile('e:/test/quick/1cbs_updated.cif');
const { structure } = await getModelsAndStructure(frame);
const expr = MolScriptBuilder.struct.generator.atomGroups({
let expr = MolScriptBuilder.struct.generator.atomGroups({
'atom-test': MolScriptBuilder.core.rel.eq([
MolScriptBuilder.struct.atomProperty.core.elementSymbol(),
MolScriptBuilder.es('C')
......@@ -61,10 +74,12 @@ export async function testQ() {
'residue-test': MolScriptBuilder.core.rel.inRange([CustomProp.symbols.residueIndex.symbol(), 1, 5])
});
expr = tsp;
const compiled = compile<StructureQuery>(expr);
const result = compiled(new QueryContext(structure));
console.log(result);
}
// testQ();
\ No newline at end of file
testQ();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment