Skip to content
Snippets Groups Projects
Select Git revision
  • 151da1487c0d3c22dafbe995c687c673f7d8728c
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

parser.ts

Blame
  • parser.ts 9.05 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 <koya.sakuma.work@gmail.com>
     */
    
    import * as P from '../../../mol-util/monadic-parser';
    import * as h from '../helper';
    import { MolScriptBuilder } from '../../../mol-script/language/builder';
    const B = MolScriptBuilder;
    import { sstrucMap, sstrucDict, properties } from './properties';
    import { operators } from './operators';
    import { keywords } from './keywords';
    import { functions } from './functions';
    import { OperatorList } from '../types';
    import { Transpiler } from '../transpiler';
    
    // <, <=, = or ==, >=, >, and !=
    // lt, le, eq, ge, gt, and ne, =~
    const valueOperators: OperatorList = [
        {
            '@desc': 'multiplication, division',
            '@examples': [],
            name: 'mul-div',
            type: h.binaryLeft,
            rule: P.MonadicParser.regexp(/\s*(\*|\/)\s*/, 1),
            map: (op, e1, e2) => {
                switch (op) {
                    case '*': return B.core.math.mult([e1, e2]);
                    case '/': return B.core.math.div([e1, e2]);
                    default: throw new Error(`value operator '${op}' not supported`);
                }
            }
        },
        {
            '@desc': 'addition, substraction',
            '@examples': [],
            name: 'add-sub',
            type: h.binaryLeft,
            rule: P.MonadicParser.regexp(/\s*(-|\+)\s*/, 1),
            map: (op, e1, e2) => {
                switch (op) {
                    case '-': return B.core.math.sub([e1, e2]);
                    case '+': return B.core.math.add([e1, e2]);
                    default: throw new Error(`value operator '${op}' not supported`);
                }
            }
        },
        {
            '@desc': 'value comparisons',
            '@examples': [],
            name: 'comparison',
            type: h.binaryLeft,
            rule: P.MonadicParser.alt(P.MonadicParser.regexp(/\s*(=~|==|>=|<=|=|!=|>|<)\s*/, 1), P.MonadicParser.whitespace.result('=')),
            map: (op, e1, e2) => {
                let expr;
                if (e1.head !== undefined) {
                    if (e1.head.name === 'structure-query.atom-property.macromolecular.secondary-structure-flags') {
                        expr = B.core.flags.hasAny([e1, sstrucMap(e2)]);
                    }
                    if (e1.head.name === 'core.type.regex') {
                        expr = B.core.str.match([e1, B.core.type.str([e2])]);
                    }
                } else if (e2.head !== undefined) {
                    if (e2.head.name === 'structure-query.atom-property.macromolecular.secondary-structure-flags') {
                        expr = B.core.flags.hasAny([e2, sstrucMap(e1)]);
                    }
                    if (e2.head.name === 'core.type.regex') {