Recent

Author Topic: String probelm(Solved)  (Read 2864 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #15 on: March 01, 2023, 01:12:58 am »
@Zvoni Wow the amount of work is getting out of hand. One of us need to get a new hobby.

"Anyway, it's an interesting excersize, so i came up with a "new" Version."

This is my third week on this problem. Seems everything works pretty well but misses a few here and there.
with the last version i got running but have an issue in the test bed and it not striping some thing. Example:

protected procedure TControlActionLink.SetCaption(  const Value: string ); override; after striping
TControlActionLink.SetCaption(  const Value: string ); override;

so the name comes out TControlActionLink.SetCaption, but that's my code causing the problem. I think all told it missed three Items.

Maybe I'll go to you newest. It looks really complicated. May not be able to implement.

Thanks

I could post the test data on my google drive. It my even zip and post here it all text.

 
« Last Edit: March 01, 2023, 01:25:02 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #16 on: March 01, 2023, 06:46:07 am »
@Zvoni  I have to be doing something wrong but can't figure it out.

The Call: MyChar:=GetFuncHeaderParamsR (Source2,MyParamArray,MyParam,MyResult,MyClass,MyMethod,
                            MyLeadModifiers,MyTrailModifiers);       

//Source2 ='protected procedure TLazLoggerLogGroupList.Remove(const AConfigName:string);virtual;'

The results:

//MyParamArray ='const AConfigName:string')
//MyParam ='const AConfigName:string'
//MyResult = nil
//MyClass = nil
//MyMethod = nil
//MyLeadModifiers = nil
//MyTrailModifiers ='virtual')

I don't see anything that would allow me to parse the name "Remove"

project attached       
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: String probelm
« Reply #17 on: March 01, 2023, 09:49:00 am »
@Zvoni  I have to be doing something wrong but can't figure it out.

The Call: MyChar:=GetFuncHeaderParamsR (Source2,MyParamArray,MyParam,MyResult,MyClass,MyMethod,
                            MyLeadModifiers,MyTrailModifiers);       

//Source2 ='protected procedure TLazLoggerLogGroupList.Remove(const AConfigName:string);virtual;'

The results:

//MyParamArray ='const AConfigName:string')
//MyParam ='const AConfigName:string'
//MyResult = nil
//MyClass = nil
//MyMethod = nil
//MyLeadModifiers = nil
//MyTrailModifiers ='virtual')

I've just let it run again.
(I've added some lines. Don't forget to declare i:integer; in global vars)
Code: Pascal  [Select][+][-]
  1. Begin
  2.   MyChar:=GetFuncHeaderParamsR(Source2,MyParamArray,MyParam,MyResult,MyClass,MyMethod,MyLeadModifiers,MyTrailModifiers);    
  3.   Writeln('Function-Name: ',MyChar);
  4.   Writeln('Parameter-List: ',MyParam);
  5.   If Length(MyParamArray)>0 Then For i:=low(MyParamArray) to High(MyParamArray) Do Writeln('Parameter ',i,': ',MyParamArray[i]);
  6.   Writeln('Resulttype: ',MyResult);
  7.   Writeln('Classname: ',MyClass);
  8.   Writeln('Method is a: ',MyMethod);
  9.   If Length(MyLeadModifiers)>0 Then For i:=Low(MyLeadModifiers) To High(MyLeadModifiers) Do Writeln('Lead Modifier ',i,': ',MyLeadModifiers[i]);
  10.   If Length(MyTrailModifiers)>0 Then For i:=Low(MyTrailModifiers) To High(MyTrailModifiers) Do Writeln('Trail Modifier ',i,': ',MyTrailModifiers[i]);
  11. End.      
Returns:
Quote
Function-Name: Remove
Parameter-List: const AConfigName:string
Parameter 0: const AConfigName:string
Resulttype:
Classname: TLazLoggerLogGroupList
Method is a: procedure
Lead Modifier 0: protected
Trail Modifier 0: virtual

Quote

I don't see anything that would allow me to parse the name "Remove"

project attached     

Your Function-Name is the Result of my Function. You'll find it in "MyChar"
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: String probelm
« Reply #18 on: March 01, 2023, 12:29:38 pm »
This is my third week on this problem. Seems everything works pretty well but misses a few here and there.
On a sidenote:
My last code ignores generics, so if you need to parse generic functions, too, give a shout.
It's not that much more complicated as it is, since we only get one new leading modifier ("generic"), and two delimiters to look out for ("<" and ">") which would introduce a "second" Params-List.

It's not Rocket Science
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: String probelm
« Reply #19 on: March 01, 2023, 01:38:48 pm »
Now with Generics
Code: Pascal  [Select][+][-]
  1. program Project1;
  2. Uses SysUtils, Classes, StrUtils;
  3.  
  4. Type
  5.   TrimSpaces=(enmLeft, enmRight, enmBoth);
  6.  
  7. Var
  8.   Source1:String='strict protected procedure Erase (const AConfigName : string ; var f: file ;AValue :Integer = 0 )  ; cdecl; overload ;';
  9.   Source2:String='protected procedure TLazLoggerLogGroupList.Remove ( const AConfigName : string ) ; virtual;';
  10.   Source3:String='Function SomeFunc : String; Overload ; ';
  11.   Source4:String='Operator  :=  ( ALeft:String; ARight : String ) :  TSomeThing ; Overload ;';
  12.   Source5:String='Procedure DoSomething ; Overload ; cdecl;';
  13.   Source6:String='Strict Private Property SomeProperty[i : integer ] :  TSomeType Read FSomeProp Write FSomeProp ; default ; ';
  14.   Source7:String='Public   Property SomeProp2 [x : String ] : TSomeOtherType ; default; ';
  15.   Source8:String='Published  Property SomeProp3 ; ';
  16.   Source9:String='generic procedure printTArr <T , Y , Z> ( sarr: array of T ) ;';
  17.   Source10:String='generic Function GenFunc <X , T > ( GenArr: array of T ) : T ;';
  18.   Source11:String='generic Function GenFunc <T >  : T ;';
  19.   Source12:String='generic procedure printTArr <T > ;';
  20.  
  21.   MyChar:String='';
  22.   MyParam:String='';
  23.   MyGenericList:String='';
  24.   MyResult:String='';
  25.   MyClass:String='';
  26.   MyMethod:String='';
  27.   MyParamArray:TStringArray;
  28.   MyGenericArray:TStringArray;
  29.   MyLeadModifiers:TStringArray;
  30.   MyTrailModifiers:TStringArray;
  31.   i:Integer;
  32.  
  33. Const
  34.   Colon=':';
  35.   Semicolon=';';
  36.   CloseParanthesis=')';
  37.   OpenParanthesis='(';
  38.   CloseIndex=']';
  39.   OpenIndex='[';
  40.   CloseGeneric='>';
  41.   OpenGeneric='<';
  42.   ReadS=' read ';
  43.   WriteS=' write ';
  44.   Comma=',';
  45.   Equal='=';
  46.   Dot='.';
  47.   Blank=' ';
  48.  
  49. Function CleanUp2(Const ASource:String;Const OldValue:TStringArray;Const ATrimType:TrimSpaces):String;
  50. Var
  51.   i:Integer;
  52.   a:String;
  53.   s:String;
  54.  
  55.   Function InternalReplace:String;
  56.   Begin
  57.     Result:=s.Replace(a,OldValue[i],[rfReplaceAll]);
  58.   end;
  59.  
  60. Begin
  61.   s:=ASource;
  62.   i:=Low(OldValue);
  63.   Repeat
  64.     Case ATrimType Of
  65.       enmLeft:  Begin
  66.                   a:=Blank+OldValue[i];
  67.                   s:=InternalReplace;
  68.                 end;
  69.       enmRight: Begin
  70.                   a:=OldValue[i]+Blank;
  71.                   s:=InternalReplace;
  72.                 end;
  73.       enmBoth:  Begin
  74.                   a:=Blank+OldValue[i];
  75.                   s:=InternalReplace;
  76.                   a:=OldValue[i]+Blank;
  77.                   s:=InternalReplace;
  78.                 end;
  79.     End;
  80.     Inc(i);
  81.   Until i>High(OldValue);
  82.   Result:=s;
  83. End;
  84.  
  85. Function Min(AValue:Array Of Integer):Integer;
  86. Var
  87.   i:Integer;
  88. Begin
  89.   Result:=High(Integer);
  90.   If Low(AValue)=High(AValue) Then Exit(AValue[0]);               //Error. Only one Element. Return Value
  91.   For i:=Low(AValue) To High(AValue) Do
  92.     If (AValue[i]>0) And (AValue[i]<Result) Then
  93.       Result:=AValue[i];
  94. end;                
  95.  
  96. Function GetFuncHeaderParamsR(Var ASource:String;
  97.                               Var AParamArray:TStringArray;
  98.                               Var AParamList:String;
  99.                               Var AGenericList:String;
  100.                               Var AGenericArray:TStringArray;
  101.                               Var AResultType:String;
  102.                               Var AClassName:String;
  103.                               Var AMethod:String;
  104.                               Var ALeadModifiers:TStringArray;
  105.                               Var ATrailModifiers:TStringArray):String;
  106. Var
  107.   i:Integer;
  108.   l:Integer;       //For Length of ASource
  109.   sc:Integer;      //For Semicolon
  110.   sc1:Integer;     //Save-Variable for old position of Semicolon
  111.   co:Integer;      //For Colon
  112.   cp:Integer;      //For closing Paranthesis
  113.   op:Integer;      //For opening Paranthesis
  114.   oi:Integer;      //For opening Index
  115.   ci:Integer;      //For closing Index
  116.   r:Integer;       //For read modifier
  117.   w:Integer;       //For write modifier.
  118.   og:Integer;      //For open generic
  119.   cg:Integer;      //For close generic
  120.   dt:Integer;      //For Dot
  121.   bl:Integer;      //For Blank
  122.   bl1:Integer;     //Save-Variable for old position of Blank
  123.   //temp. Variables
  124.   t:Integer;
  125.   t1:String;
  126.   t2:String;
  127.   cc:String;
  128.   oo:String;
  129.   pc:Integer;
  130.   po:Integer;
  131.  
  132.  
  133.   Function InternalGetResultType:String;
  134.   Begin
  135.     t1:=Copy(ASource,co,l-co+1);
  136.     t1:=CleanUp2(t1,[Colon,SemiColon],enmBoth);
  137.     t2:=Copy(ASource,1,co-1);
  138.     AResultType:=Copy(t1,2,Pos(SemiColon,t1)-2);
  139.     Result:=t2+t1;
  140.   End;
  141.  
  142. Begin
  143.   //Remove leading/trailing Whitespace and remove duplicate spaces
  144.   ASource:=DelSpace1(Trim(ASource));
  145.   //We're starting from the right looking for ';', ':' and ')'
  146.   //----------------------------------------------------------
  147.   //Should return Length(ASource) --> Sanity-Check
  148.   l:=Length(ASource);
  149.   sc:=RPosEx(Semicolon,ASource,l);
  150.   If sc<l Then Exit('');     //ERROR! Missing last ';'
  151.  
  152.   co:=RPosEx(Colon,ASource,l);
  153.   //If cp=0 then no Parameter-List. op MUST also be 0.
  154.   //If cp>0 then op MUST also be >0.
  155.   //In case of cp>0 And op>0, co>cp MUST represent Function-Result (Colon right of closing Paranthesis)
  156.   //otherwise colon is inside Parameter-List, and it's a Procedure (No Result)
  157.   //If ci=0 Then no Index. oi MUST also be 0
  158.   //If ci>0 then oi MUST also be >0.
  159.   //In case of ci>0 and oi>0 it's a Property. cp and op MUST be 0. co>ci MUST represent the Type
  160.   //otherwise the colon is inside the Index, and we have an Error
  161.   //For Properties there must be 1 colon for the Type, and Optional a second colon if there is an Index
  162.   //If cg=0 then not a Generic. og MUST be 0
  163.   //If cg>0, og MUST also be >0
  164.   op:=RPosEx(OpenParanthesis,ASource,l);
  165.   cp:=RPosEx(CloseParanthesis,ASource,l);
  166.   oi:=RPosEx(OpenIndex,ASource,l);
  167.   ci:=RPosEx(CloseIndex,ASource,l);
  168.   og:=RPosEx(OpenGeneric,ASource,l);
  169.   cg:=RPosEx(CloseGeneric,ASource,l);
  170.   If (cp=0) And (op>0) Then Exit('');      //ERROR
  171.   If (cp>0) And (op=0) Then Exit('');      //ERROR
  172.   If (ci=0) And (oi>0) Then Exit('');      //ERROR
  173.   If (ci>0) And (oi=0) Then Exit('');      //ERROR
  174.   If (og>0) And (cg=0) Then Exit('');      //ERROR
  175.   If (og=0) And (cg>0) Then Exit('');      //ERROR
  176.   //we're looking for the left most semicolon
  177.   Repeat
  178.     sc1:=sc;                             //Save the prior position of semicolon
  179.     sc:=RPosEx(Semicolon,ASource,sc-1);
  180.   until (sc<=cp) Or (sc<=co) Or (sc<=ci) Or (sc<=cg); //If no Parameter-List, no Generic-List Or Index and no Result, sc can return 0
  181.   //------------------------------------------------------------
  182.   //We've reached either a colon, a closing Paranthesis, a closing Index, a closing Generic or the beginning of the line.
  183.   //sc1 represents the last position of Semicolon. Everything right of it are trailing modifiers
  184.   //Getting trailing modifiers. "cdecl", "Overload", "Virtual", "default" etc.
  185.   If sc1<l then
  186.     Begin
  187.       t1:=Copy(ASource,sc1,l-sc1+1);
  188.       t1:=CleanUp2(t1,[SemiColon],enmBoth);
  189.       t2:=Copy(ASource,1,sc1-1);
  190.       ASource:=t2+t1;
  191.       ATrailModifiers:=t1.Split([SemiColon],TStringSplitOptions.ExcludeEmpty);
  192.       l:=Length(ASource);
  193.     End;
  194.   //End of getting trailing modifiers
  195.   //------------------------------------------------------------
  196.   //Getting Result-Type
  197.   //The following If-Conditions are mutually exclusive
  198.   //It's a function with Parameter-List, Generic-List or an operator
  199.   If co>0 Then
  200.     //We have a Parameter-List, or Generic-List without Parameter
  201.     If ((cp>0) And (co>cp)) xor ((cg>0) And (co>cg) And (cp=0)) Then
  202.       Begin
  203.         ASource:=InternalGetResultType;
  204.         l:=Length(ASource);
  205.       end
  206.     //It's a Property with an Index. Checking for "Read"/"Write"-Modifiers
  207.     Else If (ci>0) And (co>ci) Then
  208.       Begin
  209.         t1:=Copy(ASource,co,l-co);
  210.         t1:=CleanUp2(t1,[SemiColon,Colon],enmBoth);
  211.         t2:=Copy(ASource,1,co-1);
  212.         ASource:=T2+t1;
  213.         l:=Length(ASource);
  214.         sc:=RPosEx(SemiColon,ASource,sc1);
  215.         If (sc>0) And (sc<=sc1) Then sc1:=sc;
  216.         r:=RPosEx(LowerCase(ReadS),LowerCase(ASource),l);
  217.         w:=RPosEx(LowerCase(WriteS),LowerCase(ASource),l);
  218.         t:=Min([r,w]);              //Which is the most left?
  219.         If t>0 Then                 //t=0 indicates no "read" and "write" modifier
  220.           AResultType:=Copy(ASource,co+1,t-co-1)
  221.         Else
  222.           AResultType:=Copy(ASource,co+1,sc1-co-1);
  223.       End
  224.     //It's a function without Parameter-List and without Generics.
  225.     //Can't be an Operator
  226.     //It's a Property without Index
  227.     //There can't be any more colons
  228.     Else If (cp=0) And (ci=0) And (cg=0) Then
  229.       Begin
  230.         ASource:=CleanUp2(InternalGetResultType,[Colon],enmBoth);
  231.         l:=Length(ASource);
  232.       end;
  233.   //End of Getting Result-Type
  234.   //------------------------------------------------------------
  235.   //Getting Parameter-List. It doesn't matter if Operator, Procedure or Function
  236.   //If it's an Index of a Property, we're using [] instead of ()
  237.   If (cp>0) Or (ci>0) Then              //It has Index or Parameter-List
  238.     Begin
  239.       If cp>0 Then
  240.         Begin
  241.           cc:=CloseParanthesis;
  242.           oo:=OpenParanthesis;
  243.           pc:=cp;
  244.           po:=op;
  245.         end
  246.       Else If ci>0 Then
  247.         Begin
  248.           cc:=CloseIndex;
  249.           oo:=OpenIndex;
  250.           pc:=ci;
  251.           po:=oi;
  252.         End;
  253.       t1:=Copy(ASource,pc,l-pc+1);
  254.       t1:=CleanUp2(t1,[cc,Colon,SemiColon],enmBoth);
  255.       t2:=Copy(ASource,1,pc-1);
  256.       ASource:=t2+t1;
  257.       l:=Length(ASource);
  258.       t1:=Copy(ASource,po,l-po+1);
  259.       t1:=CleanUp2(t1,[oo,cc,Colon,SemiColon,Equal],enmBoth);
  260.       t2:=Copy(ASource,1,po-1);
  261.       AParamList:=Copy(t1,2,Pos(cc,t1)-2);
  262.       AParamArray:=AParamList.Split([SemiColon],TStringSplitOptions.ExcludeEmpty);
  263.       ASource:=CleanUp2(t2+t1,[cc,oo],enmBoth);
  264.       l:=Length(ASource);
  265.     end;
  266.   //If it's a Generic, we have to check if it's with or without Parameter-list following
  267.   If cg>0 Then                    //We have Generics
  268.       Begin
  269.         t1:=Copy(ASource,cg,l-cg+1);
  270.         t1:=CleanUp2(t1,[CloseGeneric,Colon,Semicolon,OpenParanthesis],enmBoth); //Closing Generic is followed optionally by opening Paranthesis
  271.         t2:=Copy(ASource,1,cg-1);
  272.         ASource:=t2+t1;
  273.         l:=Length(ASource);
  274.         t1:=Copy(ASource,og,l-og+1);
  275.         t1:=CleanUp2(t1,[OpenGeneric,CloseGeneric,Colon,Semicolon,Comma],enmBoth);
  276.         t2:=Copy(ASource,1,og-1);
  277.         AGenericList:=Copy(t1,2,Pos(CloseGeneric,t1)-2);
  278.         AGenericArray:=AGenericList.Split([Comma],TStringSplitOptions.ExcludeEmpty);
  279.         ASource:=CleanUp2(t2+t1,[OpenGeneric,CloseGeneric],enmBoth);
  280.         l:=Length(ASource);
  281.       end;
  282.   //End of Getting Parameter-List
  283.   //------------------------------------------------------------
  284.   //It's a Procedure without Parameter-List or a Published Property
  285.   //Semicolon is the only legal Delimiter here
  286.   //There can't be anymore semicolons left of sc1
  287.   //Just cleaning up
  288.   If (co=0) And (cp=0) And (ci=0) Then
  289.     ASource:=CleanUp2(ASource,[SemiColon],enmBoth);
  290.   //------------------------------------------------------------
  291.   //Getting Method-Name
  292.   l:=Length(ASource);
  293.   sc:=RPosEx(SemiColon,ASource,sc1);
  294.   sc1:=sc;
  295.   cp:=RPosEx(CloseParanthesis,ASource,cp);
  296.   op:=RPosEx(OpenParanthesis,ASource,op);
  297.   ci:=RPosEx(CloseIndex,ASource,ci);
  298.   oi:=RPosEx(OpenIndex,ASource,oi);
  299.   co:=RPosEx(Colon,ASource,co);
  300.   og:=RPosEx(OpenGeneric,ASource,og);
  301.   cg:=RPosEx(CloseGeneric,ASource,cg);
  302.   //get the most left Position of either colon, open Paranthesis, open Index or Semicolon
  303.   t:=Min([sc1,op,oi,co,og]);
  304.   If (t=0) Or (t>l) Then Exit('Ooops. Something went wrong');          //ERROR. There is something wrong  
  305.   //Checking for a dot '.' if Method is part of a Class, Record, Object
  306.   //There can only be one Dot
  307.   dt:=RPosEx(Dot,ASource,t);
  308.   bl:=RPosEx(Blank,ASource,t);
  309.   If bl=0 Then Exit('');         //ERROR. "Procedure" etc. Missing
  310.   //THE NAME OF THE METHOD
  311.   If (dt>0) And (bl>0) And (bl<dt) Then   //It's part of a class, record, object
  312.     Begin
  313.       Result:=Copy(ASource,dt+1,t-dt-1);
  314.       AClassName:=Copy(ASource,bl+1,dt-bl-1);
  315.     end
  316.   Else If (bl>0) And (dt=0) Then
  317.     Result:=Copy(ASource,bl+1,t-bl-1);
  318.   //End of Getting Method-Name
  319.   //------------------------------------------------------------
  320.   //Getting the Method. "Procedure", "Function" etc.
  321.   If bl>0 Then bl1:=bl;            //Save the last Position of blank
  322.   //Check for next blank to the left
  323.   bl:=RPosEx(Blank,ASource,bl-1);
  324.   //Get Method
  325.   AMethod:=Copy(ASource,bl+1,bl1-bl-1);
  326.   //End of getting Method
  327.   //------------------------------------------------------------
  328.   //Getting leading modifiers
  329.   //If bl is >0 here then we have leading modifiers
  330.   If bl>0 Then
  331.     Begin
  332.       t1:=Copy(ASource,1,bl-1);
  333.       ALeadModifiers:=t1.Split([Blank],TStringSplitOptions.ExcludeEmpty);
  334.     End;
  335.   //End of getting leading modifiers
  336. End;
  337.  
  338. begin
  339.   MyChar:=GetFuncHeaderParamsR(Source12,MyParamArray,MyParam,MyGenericList,MyGenericArray,MyResult,MyClass,MyMethod,MyLeadModifiers,MyTrailModifiers);
  340.   Writeln('Function-Name: ',MyChar);
  341.   Writeln('Generic-List: ',MyGenericList);
  342.   If Length(MyGenericArray)>0 Then For i:=low(MyGenericArray) to High(MyGenericArray) Do Writeln('Generic ',i,': ',MyGenericArray[i]);
  343.   Writeln('Parameter-List: ',MyParam);
  344.   If Length(MyParamArray)>0 Then For i:=low(MyParamArray) to High(MyParamArray) Do Writeln('Parameter ',i,': ',MyParamArray[i]);
  345.   Writeln('Resulttype: ',MyResult);
  346.   Writeln('Classname: ',MyClass);
  347.   Writeln('Method is a: ',MyMethod);
  348.   If Length(MyLeadModifiers)>0 Then For i:=Low(MyLeadModifiers) To High(MyLeadModifiers) Do Writeln('Lead Modifier ',i,': ',MyLeadModifiers[i]);
  349.   If Length(MyTrailModifiers)>0 Then For i:=Low(MyTrailModifiers) To High(MyTrailModifiers) Do Writeln('Trail Modifier ',i,': ',MyTrailModifiers[i]);
  350. end.
« Last Edit: March 01, 2023, 01:47:19 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #20 on: March 01, 2023, 01:48:45 pm »
@Zvoni

Thanks I'll work on it today.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #21 on: March 01, 2023, 11:19:47 pm »
@Zvoni Have built a test bed. The latest code.

I have run it under the debugger 4 or 5 times and  can't figure out where it goes wrong.

I may have implemented it wrong, but this version doesn't work well. You can install in one directory compile and go. The load button will load a 'test.txt' file if found. if not found it does nothing.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: String probelm
« Reply #22 on: March 02, 2023, 09:21:17 am »
@Zvoni Have built a test bed. The latest code.

I have run it under the debugger 4 or 5 times and  can't figure out where it goes wrong.

I may have implemented it wrong, but this version doesn't work well. You can install in one directory compile and go. The load button will load a 'test.txt' file if found. if not found it does nothing.

I've downloaded your code.
There is no "test.txt".
You got one for  me?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #23 on: March 02, 2023, 04:34:56 pm »
Yes l  test data attached. Just copy it in same directory.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: String probelm
« Reply #24 on: March 02, 2023, 05:12:30 pm »
Yes l  test data attached. Just copy it in same directory.

Thanks.

From your Text-File:
Code: [Select]
124 lazutils procedure DebuglnStack(const s: string = '' ); procedure DebuglnStack(LogEnabled: TLazLoggerLogEnabled; const s: string = '' );
124 lazutils procedure DebuglnStack(const s: string = '' ); procedure DebuglnStack(LogEnabled: TLazLoggerLogEnabled; const s: string = '' );
How is this supposed to work?? 2 Procedures in the same line? Of course my Parser chokes on that.

With my test-Data all lines pass. See modified Project of yours
Bottom Line: Get Your Input-Data in Order: One procedure/Function/Whatever per line
« Last Edit: March 02, 2023, 05:15:09 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: String probelm
« Reply #25 on: March 02, 2023, 06:06:02 pm »
If it‘ too much i can write a pre-parser to separate your lines
Not that difficult
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #26 on: March 02, 2023, 07:00:23 pm »
No it's not to much. I do that already. I'll resend. Take me a few min.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #27 on: March 02, 2023, 07:38:17 pm »
One per line.
I think the code I posted will do multi items per line.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: String probelm
« Reply #28 on: March 08, 2023, 07:16:20 am »
Abd the Answer is: i think?

My deliminters are changed from:
('(', ' = ', '; ', ':', '[', ',', ':= ', '-',' ');
To:
('(','=',';', ':','[', ',', ':=', '-','+',' ');
This allows me to search a string for a Char.

I can strip the following from: 

procedure ClrEol;
protected procedure TCustomBitBtn.CMAppShowBtnGlyphChanged(var Message: TLMessage); message;
procedure Continue;
protected procedure TCustomGrid.AddSelectedRange;
procedure DebugLnExit; overload;
protected procedure TControl.EndAutoSizing;
procedure Exclude(var S: TSetType; E: TSetElement);

To:                         do a Char by Char search left to right of the string for one of the deliminter.
Fitst delimiter found do a  sName:=Copy2Symb( AString,AChar);
 
ClrEol;           
CMAppShowBtnGlyphChanged(var Message: TLMessage); message;
Continue;
AddSelectedRange;
DebugLnExit; overload;
EndAutoSizing;
Exclude(var S: TSetType; E: TSetElement);

Anyway it seem to work.

So I thing I'll marked it solved.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018