Skip to content
Snippets Groups Projects
Select Git revision
  • 7c3d76e9fea81165ee85b7d4ba54ae0108688454
  • 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 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])