[fpc-devel] rebuilding source form passrc parser token tree

Graeme Geldenhuys graemeg.lists at gmail.com
Sat Aug 21 18:12:03 CEST 2010


On 21 August 2010 16:54, Michael Van Canneyt wrote:
>
> Ehm. Are you sure this is about fcl-passrc ?

Yes, but I have to apologize. While creating a test app to show the
problem, I found my problem in my own code. Inserting into my list,
instead of Adding to my list! Dope!!! :-(

My stupid mistake. Sorry for the false alarm.


> Where do you see the token list ? I searched for tokenlist, but didn't
> see it anywhere ? The scanner doesnt produce a list, and the parser is
> private.

I maintained my own list of tokens and values, so I can rebuild the
source code later. Here is the bit of code I use to parse the files.
If there is a better way of doing this, please let me know - I'm
rather new to the fcl-passrc code and how to use it.

TPasTokenList is my own class that holds a list of tokens and values
for later usage.


function TPasTokenList.ParseSource(AFileName: string): boolean;
var
  pas: TPascalScanner;
  fr: TFileResolver;
  token: TToken;
begin
  Result := False;
  fr := TFileResolver.Create;
  pas := TPascalScanner.Create(fr);
  try
    pas.OpenFile(AFileName);
    repeat
      token := pas.FetchToken;
      Add(token, pas.CurTokenString);
    until pas.CurToken = tkEOF;
    Result := True;
  finally
    pas.Free;
    fr.Free;
  end;
end;


BTW:
I used this code with a recursive directory scanner. One of my little
test apps take a directory as a parameter, then recursively runs
through files and outputs the source file being parsed and OK or FAIL
if it managed to parse it. A nice and quick way to run the fcl-passrc
parser through it's paces of all the FPC source code, or any of my own
projects.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-devel mailing list