diff --git a/src/mol-script/script.ts b/src/mol-script/script.ts index 9bcbcb37c2f0bd3ead7f478afa496885482d9300..b9022c38e33e8fe9ddd3a278c70c701cf98c8cfd 100644 --- a/src/mol-script/script.ts +++ b/src/mol-script/script.ts @@ -4,6 +4,8 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ +import { transpileMolScript } from './script/mol-script/symbols'; +import { parseMolScript } from './language/parser'; import { parse } from './transpile'; import { Expression } from './language/expression'; import { StructureElement, QueryContext, StructureSelection, Structure, QueryFn, QueryContextOptions } from '../mol-model/structure'; @@ -19,7 +21,7 @@ function Script(expression: string, language: Script.Language): Script { } namespace Script { - export type Language = 'pymol' + export type Language = 'mol-script' | 'pymol' | 'vmd' | 'jmol' export function is(x: any): x is Script { return !!x && typeof (x as Script).expression === 'string' && !!(x as Script).language; @@ -31,10 +33,18 @@ namespace Script { export function toExpression(script: Script): Expression { switch (script.language) { - case 'pymol': - const parsed = parse("pymol",script.expression); - return parsed as Expression; + case 'mol-script': + const parsed = parseMolScript(script.expression); + if (parsed.length === 0) throw new Error('No query'); + return transpileMolScript(parsed[0]); + case 'pymol': + return parse("pymol",script.expression) as Expression; + case 'jmol': + return parse("jmol",script.expression) as Expression; + case 'vmd': + return parse("vmd",script.expression) as Expression; } + throw new Error('unsupported script language'); }