Select Git revision
parser.ts 8.58 KiB
/**
* Copyright (c) 2017-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
* @author Alexander Rose <alexander.rose@weirdbyte.de>
* @author Panagiotis Tourlas <panagiot_tourlov@hotmail.com>
*
* @author Koya Sakuma
* This module was taken from MolQL and modified in similar manner as pymol and vmd tranpilers. **/
import * as P from '../../../mol-util/monadic-parser';
import * as h from '../helper';
import { MolScriptBuilder } from '../../../mol-script/language/builder';
const B = MolScriptBuilder;
import { properties, structureMap } from './properties';
import { operators } from './operators';
import { keywords } from './keywords';
import { AtomGroupArgs } from '../types';
import { Transpiler } from '../transpiler';
import { OperatorList } from '../types';
//const propertiesDict = h.getPropertyRules(properties);
//const slash = P.MonadicParser.string('/');
// <, <=, =, >=, >, !=, and LIKE
const valueOperators: OperatorList = [
{
'@desc': 'value comparisons',
'@examples': [],
name: '=',
abbr: ['=='],
type: h.binaryLeft,
rule: P.MonadicParser.regexp(/\s*(LIKE|>=|<=|=|!=|>|<)\s*/i, 1),
map: (op, e1, e2) => {
// console.log(op, e1, e2)
let expr
if (e1 === 'structure') {
expr = B.core.flags.hasAny([B.ammp('secondaryStructureFlags'), structureMap(e2)])
} else if (e2 === 'structure') {
expr = B.core.flags.hasAny([B.ammp('secondaryStructureFlags'), structureMap(e1)])
} else if (e1.head === 'core.type.regex') {
expr = B.core.str.match([ e1, B.core.type.str([e2]) ])
} else if (e2.head === 'core.type.regex') {
expr = B.core.str.match([ e2, B.core.type.str([e1]) ])
} else if (op.toUpperCase() === 'LIKE') {
if (e1.head) {
expr = B.core.str.match([
B.core.type.regex([`^${e2}$`, 'i']),
B.core.type.str([e1])
])
} else {
expr = B.core.str.match([
B.core.type.regex([`^${e1}$`, 'i']),
B.core.type.str([e2])
])
}
}
if (!expr) {
if (e1.head) e2 = h.wrapValue(e1, e2)
if (e2.head) e1 = h.wrapValue(e2, e1)
switch (op) {
case '=':
expr = B.core.rel.eq([e1, e2])
break
case '!=':
expr = B.core.rel.neq([e1, e2])
break
case '>':
expr = B.core.rel.gr([e1, e2])