1-- Copyright (c) 1991-2002, The Numerical ALgorithms Group Ltd. 2-- All rights reserved. 3-- 4-- Redistribution and use in source and binary forms, with or without 5-- modification, are permitted provided that the following conditions are 6-- met: 7-- 8-- - Redistributions of source code must retain the above copyright 9-- notice, this list of conditions and the following disclaimer. 10-- 11-- - Redistributions in binary form must reproduce the above copyright 12-- notice, this list of conditions and the following disclaimer in 13-- the documentation and/or other materials provided with the 14-- distribution. 15-- 16-- - Neither the name of The Numerical ALgorithms Group Ltd. nor the 17-- names of its contributors may be used to endorse or promote products 18-- derived from this software without specific prior written permission. 19-- 20-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 24-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32 33--% Functions to handle specific errors (mostly syntax) 34 35)package "BOOT" 36 37syGeneralErrorHere() == 38 sySpecificErrorHere('S2CY0002, []) 39 40sySpecificErrorHere(key, args) == 41 sySpecificErrorAtToken($stok, key, args) 42 43sySpecificErrorAtToken(tok, key, args) == 44 pos := tokPosn tok 45 ncSoftError(pos, key, args) 46 47syIgnoredFromTo(pos1, pos2) == 48 if pfGlobalLinePosn pos1 = pfGlobalLinePosn pos2 then 49 ncSoftError(FromTo(pos1,pos2), 'S2CY0005, []) 50 else 51 ncSoftError(From pos1, 'S2CY0003, []) 52 ncSoftError(To pos2, 'S2CY0004, []) 53 54npMissingMate(close,open)== 55 ncSoftError(tokPosn open, 'S2CY0008, []) 56 npMissing close 57 58npMissing s== 59 ncSoftError(tokPosn $stok,'S2CY0007, [PNAME s]) 60 THROW("TRAPPOINT","TRAPPED") 61 62npCompMissing s == npEqKey s or npMissing s 63 64pfSourceStok x== 65 if pfLeaf? x 66 then x 67 else if null pfParts x 68 then 'NoToken 69 else pfSourceStok pfFirst x 70 71npTrapForm(x)== 72 a:=pfSourceStok x 73 EQ(a,'NoToken)=> 74 syGeneralErrorHere() 75 THROW("TRAPPOINT","TRAPPED") 76 ncSoftError(tokPosn a, 'S2CY0002, []) 77 THROW("TRAPPOINT","TRAPPED") 78 79npTrap()== 80 ncSoftError(tokPosn $stok,'S2CY0002,[]) 81 THROW("TRAPPOINT","TRAPPED") 82 83npRecoverTrap()== 84 npFirstTok() 85 pos1 := tokPosn $stok 86 npMoveTo 0 87 pos2 := tokPosn $stok 88 syIgnoredFromTo(pos1, pos2) 89 npPush [pfWrong(pfDocument ['"pile syntax error"],pfListOf [])] 90 91 92npListAndRecover(f)== 93 a:=$stack 94 b:=nil 95 $stack:=nil 96 done:=false 97 c:=$inputStream 98 while not done repeat 99 found:=CATCH("TRAPPOINT",APPLY(f,nil)) 100 if found="TRAPPED" 101 then 102 $inputStream:=c 103 npRecoverTrap() 104 else if not found 105 then 106 $inputStream:=c 107 syGeneralErrorHere() 108 npRecoverTrap() 109 if npEqKey "BACKSET" 110 then 111 c:=$inputStream 112 else if npEqPeek "BACKTAB" 113 then 114 done:=true 115 else 116 $inputStream:=c 117 syGeneralErrorHere() 118 npRecoverTrap() 119 if npEqPeek "BACKTAB" 120 then done:=true 121 else 122 npNext() 123 c:=$inputStream 124 b:=cons(npPop1(),b) 125 $stack:=a 126 npPush NREVERSE b 127 128npMoveTo n== 129 if null $inputStream 130 then true 131 else 132 if npEqPeek "BACKTAB" 133 then if n=0 134 then true 135 else (npNext();npMoveTo(n-1)) 136 else if npEqPeek "BACKSET" 137 then if n=0 138 then true 139 else (npNext();npMoveTo n) 140 else if npEqKey "SETTAB" 141 then npMoveTo(n+1) 142 else (npNext();npMoveTo n) 143