Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: DIM2

DIM2.m

Go to the documentation of this file.
  1. DIM2 ;SFISC/XAK,GFT,TOAD-FileMan: M Syntax Checker, Exprs ; Jan 30, 2023@14:38:33
  1. ;;22.2;VA FileMan;**24**;Jan 05, 2016;Build 3
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. ;;Submitted to OSEHRA 5 January 2015 by the VISTA Expertise Network.
  1. ;;Based on Medsphere Systems Corporation's MSC FileMan 1051.
  1. ;;Licensed under the terms of the Apache License, Version 2.0.
  1. ;
  1. ;12277;4186487;4104;
  1. ;
  1. SUB ; "(": open paren situations (GG^DIM1)
  1. F %J=%I-1:-1 S %C1=$E(%,%J) Q:%C1'?1(1UN,1"%")
  1. S %C1=$E(%,%J+1,%I-1)
  1. I %C1]"",%C1'?1(1U,1"%").UN G ERR
  1. ;I %C1]"",%[("."_%C1) G ERR ;DID NOT ALLOW "W A(6)-$$X(.A)"
  1. S %(%N,0)=$S(%C1]""!($E(%,%J)="^"):"V^",$E(%,%J)="@":"@^",1:"0^")
  1. S %(%N,1)=0,%(%N,2)=0,%(%N,3)=0,%N=%N+1 G 1
  1. ;
  1. UP ; ")": close paren situations (GG^DIM1)
  1. I %N=0 G ERR
  1. I "(,"[$E(%,%I-1),$P($G(%(%N-1,0)),"^")'["P" G ERR
  1. I $E(%,%I+1)]"","<>_[]:/\?'+-=!&#*),"""'[$E(%,%I+1) G ERR
  1. S %N=%N-1,%(%N,1)=%(%N,1)+1,%F=$P(%(%N,0),"^") I %F D G ERR:%ERR
  1. . S %F=$P(%(%N,0),"^",2),%F1=%(%N,1)
  1. . I %F1<+%F S %ERR=1 Q ; not enough commas for this function
  1. . I %F1>$P(%F,";",2) S %ERR=1 Q ; too many commas for this function
  1. . I %(%N,2),'%(%N,3) S %ERR=1 ; we're in $S and haven't yet hit a :
  1. K %(%N+1)
  1. I '%F,%F'["V",%F'["@",%F'["P",%(%N,1)>1 G ERR
  1. G 1
  1. ;
  1. AR ; ",": comma situations -- "P" below means "parameters" (GG^DIM1)
  1. I %N<1 G ERR
  1. I "(,"[$E(%,%I-1),$P($G(%(%N-1,0)),"^")'["P" G ERR
  1. I '%(%N-1,3),%(%N-1,2) G ERR
  1. I "@("[$E(%,1,2) G ERR
  1. S %(%N-1,1)=%(%N-1,1)+1,%(%N-1,3)=0 G 1
  1. ;
  1. SEL ; ":": $SELECT delimiter (GG^DIM1)
  1. S %(%N-1,3)=%(%N-1,3)+1 G ERR:'%(%N-1,2)!(%(%N-1,3)>1),1
  1. ;
  1. GLO ; "^": global reference (GG^DIM1)
  1. D %INC G ERR:$E(%,%I,999)'?1U.UN.P.E&("%("'[%C)
  1. G ERR:"=+-\/<>(,#!&*':@[]_"'[$E(%,%I-2)
  1. S %I=%I-1 G 1
  1. ;
  1. PAT ; "?": pattern match (GG^DIM1)
  1. G ERR:%I=1,1:$E(%,%I+1)="@" D %INC,PATTERN G ERR:%ERR S %I=%I-1 G 1
  1. ;
  1. PATTERN F D PATATOM Q:%C'?1N&(%C'=".")!%ERR
  1. Q
  1. PATATOM D REPCOUNT Q:%ERR
  1. I %C="""" D STRLIT,%INC:'%ERR Q
  1. I %C="(" D ALTRN8 Q
  1. D PATCODE
  1. Q
  1. REPCOUNT ;
  1. I %C'?1N,%C'="." S %ERR=1 Q
  1. N FROM S FROM=+$E(%,%I,999) I %C?1N D INTLIT Q:%ERR
  1. I %C="." D %INC
  1. Q:%C'?1N I +$E(%,%I,999)<FROM S %ERR=1 Q
  1. D INTLIT Q
  1. INTLIT I %C'?1N S %ERR=1 Q
  1. F D %INC Q:%C'?1N
  1. Q
  1. STRLIT F D %INC Q:%C="" I %C="""" Q:$E(%,%I+1)'="""" S %I=%I+1
  1. I %C="" S %ERR=1
  1. Q
  1. PATCODE I "ACELNPU"'[%C!(%C="") S %ERR=1 Q
  1. F D %INC Q:%C="" Q:"ACELNPU"'[%C
  1. Q
  1. ALTRN8 I %C'="(" S %ERR=1 Q ;alternate patterns (AE) are within a set of parentheses
  1. D %INC,PATATOM Q:%ERR
  1. I %C="," F Q:","'[%C D %INC,PATATOM Q:%ERR ;AE elements that are seperated by comma
  1. F Q:%C=")" D PATATOM Q:%ERR ;AE elements that are not seperated ;p24
  1. I %C'=")" S %ERR=1 Q
  1. D %INC
  1. Q
  1. ;
  1. BINOP ; binary operator (GG^DIM1)
  1. S %Z1=""")%'",%Z2="""($+-^%@'." G OPCHK
  1. ;
  1. MTHOP ; math or relational operator (GG^DIM1)
  1. S %Z1=""")%",%Z2="""($+-^%@'." G OPCHK
  1. ;
  1. UNOP ; unary operator (GG^DIM1)
  1. S %Z1=""":<>+-'\/()%@#&!*=_][,"
  1. S %Z2="""($+-=&!^%.@'" I %C="'" S %Z2=%Z2_"<>?[]"
  1. G OPCHK
  1. ;
  1. IND ; "@": indirection (GG^DIM1)
  1. I $E(%COM)="F" G ERR
  1. S %Z1="^?@(%+-=\/#*!&'_<>[]:,.",%Z2="""(+^-'$@%" G OPCHK
  1. ;
  1. OPCHK ; ensure that the characters before and after the operator are OK
  1. S %L1=$E(%,%I-1),%L2=$E(%,%I+1) I %L1="'","[]&!<>="[%C S %L1=$E(%,%I-2)
  1. I %L1="","+-'@"'[%C G ERR ; binary: require before
  1. I %L1'?1UN,%Z1'[%L1 G ERR ; all: screen before
  1. F %F="*","]" I %C=%F,%L2=%F S %I=%I+1,%L2=$E(%,%I+1) Q
  1. I %L2="" G ERR ; all: require after
  1. I %L2'?1UN,%Z2'[%L2 G ERR ; all: screen after
  1. I %C="'","!&[]?=<>"'[%L2,%L1?1(1")",1UN) G ERR ;GFT: unary "'" may precede an operator, can't follow a variable name
  1. G 1
  1. ;
  1. 1 ; common exit point for all of ^DIM2
  1. G GG^DIM1
  1. ;
  1. DATA ; glvn arguments of $D,$G,$NA,$O, & $Q functions (FUNC^DIM1)
  1. D %INC G ERR:%C="",ERR:%C=")",DATA:"^@"[%C D VAR
  1. G ERR:"@(,)"'[%C!%ERR,GG1^DIM1
  1. ;
  1. VAR ; variables encountered while parsing exprs (DATA, GG^DIM1)
  1. N %START S %START=%I-1 I $E(%,%START)="^" S %START=%START-1
  1. I %C="%" D %INC
  1. N OUT S OUT=0 F %J=%I:1 S %C=$E(%,%J) D Q:OUT
  1. . I ",<>?/\[]+-=_()*&#!':"[%C S OUT=1 Q
  1. . I %C="@",$E(%,%J+1)="(",$E(%,%START)="@" S OUT=1 Q
  1. . I %C'?1UN S %ERR=1
  1. . I %C="^",$D(%(%N-1,"F")),%(%N-1,"F")["TEXT" S %ERR=0,OUT=1
  1. Q:%ERR
  1. I %C="@" S %I=%J Q
  1. S %F=$E(%,%I,%J-1)
  1. I %F="^",$E(%,%J)'="(" S %ERR=1
  1. I %F]"",%F'?1U.UN,$E(%,%I-1,%J-1)'?1"%".UN S %ERR=1
  1. S %I=%J Q
  1. ;
  1. %INC S %I=%I+1,%C=$E(%,%I)
  1. Q
  1. ;
  1. ERR S %ERR=1,%N=0
  1. FINISH G ERR:%N'=0 K %C,%,%F,%F1,%I,%J,%L1,%L2,%N,%T,%Z1,%Z2,%FN,%FZ
  1. Q Q