//***************************************************************************************** // Copyright (c) 2000 Michael Kurz // All rights reserved. // If you want to use this source in your applications conatct: // // $FileName : cLineParserWhiteSpace.pkg // $ProjectName : General shared classes // $Author : Michael Kurz // $Created : 12-31-2000 @ 09:00 // // Contents: // Separates a string to its parts which need to be seperated by a special character. // Special version of cLineParser that preserves the whitespace characters as // separate tokens. // // $Rev History // 11/09/2005 **WvA Added the possibility to skip parts in the parsing. This allows // us to parse UNC paths correctly while the sep character is set to "\" // //***************************************************************************************** Use cLineParser.pkg // This Class separates a string into his parts. Which need to be // seperated by a seperating character (psSepCharacter) // As the class is based on an array the parts can be retrieved by // "get value item iItem to sPart" and the number of items with a call // of "get Item_Count to iCount". Define CLINEPARSER_COMMAND For 0 Define CLINEPARSER_KEYWORD For 1 Define CLINEPARSER_COMMENT For 2 Define CLINEPARSER_STRING For 3 Define CLINEPARSER_EXPRESSION For 4 Define CLINEPARSER_INDICATOR For 5 Define CLINEPARSER_WHITESPACE For 6 // // Instead of touching the above parser code (and breaking stuff beyond reasonable doubt) // I did the silly thing and copied the code into a new class so I can experiment. // The goal is to parse dataflex code but preserve all space characters for // codepub. // Class cPreserveSpaceLineParser Is a cLineParser Procedure Add_Token Integer iType String sToken Set value Item (Item_Count(Self)) To sToken If ((Item_Count(Self)=1)And(iType<>CLINEPARSER_COMMENT)And(iType<>CLINEPARSER_INDICATOR)) Set value Of (oType(Self)) Item (Item_Count(Self)-1) To CLINEPARSER_COMMAND Else Set value Of (oType(Self)) Item (Item_Count(Self)-1) To iType End_Procedure Function ProcessStrToken String sChar String sLine Integer iCount Returns Integer String sToken sChr Move "" To sToken Move sChar To sChr Move (sToken+sChr) To sToken Move "" To sChr While ((sChr<>sChar)And(iCount<=(Length(sLine)))) Increment iCount Move (Mid(sLine,1,iCount)) To sChr Move (sToken+sChr) To sToken Loop If (sToken<>"") Send Add_Token CLINEPARSER_STRING sToken Function_Return iCount End_Function Function ProcessBrToken String sCharSt String sCharEn String sLine Integer iCount Returns Integer Integer iBr iStr iChr String sToken sChr Increment iBr // Start Move sCharSt To sToken While ((iBr<>0)And(iCount<=(Length(sLine)))) Increment iCount Move (Mid(sLine,1,iCount)) To sChr If (sChr='"') Begin If (iStr) Decrement iStr Else Begin If (Not(iChr)) Increment iStr End End If (sChr="'") Begin If (iChr) Decrement iChr Else Begin If (Not(iStr)) Increment iChr End End If ((Not(iStr))And(Not(iChr))) Begin If (sChr=sCharSt) Increment iBr If (sChr=sCharEn) Decrement iBr End Move (sToken+sChr) To sToken Loop If (sToken<>"") Begin If (sCharSt="[") Send Add_Token CLINEPARSER_INDICATOR sToken Else Send Add_Token CLINEPARSER_EXPRESSION sToken End Function_Return iCount End_Function Procedure ParseLineTkn String sLine Integer iPos iC iBlank iSepL iCount String sPart sToken sChar sSep sCom sNext sComLine String sWSToken // Whitespace token Move ('/'+'/') To sCom Move "" To sWSToken Move (psSepCharacter(Self)) To sSep Move (Length(sSep)) To iSepL Send Delete_Data If (sSep=" ") Move 1 To iBlank If (Left(sLine,2)=sCom) Begin Send Add_Token CLINEPARSER_COMMENT sLine Procedure_Return End If sCom In sLine Begin Move (Left(sLine, (Pos(sCom, sLine)-1))) To sToken Move (Replace(sToken, sLine, "")) To sLine Move (RTrim(sLine)) To sComLine Move sToken To sLine Move "" To sToken End While (iCount<=(Length(sLine))) Increment iCount Move (Mid(sLine,1,iCount)) To sChar If (Length(sWSToken)>0) Begin If (sChar<>sSep) Begin Send Add_Token CLINEPARSER_WHITESPACE sWSToken Move "" To sWSToken End End If (sChar='"' Or sChar="'") Begin Get ProcessStrToken sChar sLine iCount To iCount Move "" To sChar End Else If (sChar="(") Begin Get ProcessBrToken sChar ")" sLine iCount To iCount Move "" To sChar End Else If (sChar="[") Begin Get ProcessBrToken sChar "]" sLine iCount To iCount Move "" To sChar End Else If (sChar="/") Begin Increment iCount Move (Mid(sLine,1,iCount)) To sNext If (sNext="/") Begin Move (sChar+sNext+Right(sLine, iCount+1)) To sToken If (sToken<>"") Send Add_Token CLINEPARSER_COMMENT sToken Move (Length(sLine)+100) To iCount // Cancels parsing End Move "" To sChar End If (sChar=sSep) Begin If (sToken<>"") Begin Send Add_Token CLINEPARSER_KEYWORD sToken Move "" To sToken End Else Move (sWSToken+sChar) To sWSToken End If (sChar<>"") Move (sToken+sChar) To sToken Loop If (sComLine<>"") Send Add_Token CLINEPARSER_COMMENT sComLine End_Procedure Procedure ParseLineStd String sLine Integer iPos iC iBlank iSepL iCount String sPart sSkip sSwap sOld Boolean bSwapped Move (Length(psSepCharacter(Self))) To iSepL Send Delete_Data // *WvA: 11/09/2005 Added logic to skip parsing of specific parts. Move (false) To bSwapped Get psSkipSequence To sSkip Get psSwapOutSequence To sSwap If (sSkip<>"") Begin // temporarily replace our skip sequence with the swapvalue Move sLine To sOld Move (Replaces(sSkip,sLine,sSwap)) To sLine Move (sOld<>sLine) To bSwapped End If (psSepCharacter(Self)) Eq " " Move 1 To iBlank Repeat Increment iCount Move (Pos(psSepCharacter(Self),sLine)) To iPos If iPos Eq 0 Move (Length(sLine)) To iPos Move (Left(sLine,iPos+iSepL-1)) To sPart Move (Replace(sPart,sLine,"")) To sLine If (Right(sPart,iSepL)) Eq (psSepCharacter(Self)) ; Move (Left(sPart,length(sPart)-iSepL)) To sPart //move (Right(sLine,Length(sLine)-iPos)) to sLine //If iBlank Move (LTrim(sLine)) To sLine // *WvA: 11/09/2005 Added logic to skip parsing of specific parts. If ((bSwapped) And (Pos(sSwap,sPart)>0)) Begin // Move our skip sequence back in the part just before storing it. Move (Replaces(sSwap,sPart,sSkip)) To sPart End If (Not(piSkipEmptyParts(Self))) Set value Item (Item_Count(Self)) To sPart Else If (Trim(sPart)) Ne "" Set value Item (Item_Count(Self)) To sPart If iCount Gt 200 Begin // Send Info_Box "Failure!" Procedure_Return End Until (sLine Eq "") End_Procedure End_Class // cPreserveSpaceLineParser