How to find encapsulating function name from line number?

I am looking at a log file which just tells me the filename and the line number inside that file that has the Error. What I am interested is knowing the encapsulating function. For example, here are the contents of the log file

   Error: foo.file on line wxy
        Error: foo.file on line xyz
        .
        .
        .

and here are the contents of the file foo.file

 function abc(...)
        .
        .
        .
        
        
        endfunction
        
        function def()
        .
        .
        .
       //Following line number is  WXY
        assign Z ==== X;
        
        endfunction
        
        
        function ghi(...)
        .
        .
        .
      
    
      //Following line number is  XYZ
        assign X = X;
        endfunction
    
       .
       .
       .

Based on the above log file, I want to get function names def and ghi returned. I have googled but can't find good pointers or starting points to solve this.

As you know, it always helps us help you if you tell us what operating system you're using, what shell you're using, and anything you have done to try to solve this problem on your own.

A better description of the constraints on the code function definition lines and the endfunction lines would also be required to be able to reliably identify function boundaries.

After converting your QUOTE tags to CODE tags, we can see that the function and endfunction keywords in the language you're using have varying amounts of leading whitespace.

What characters are allowed in function names?

Can there be anything on a function definition line other than leading whitespace, the function keyword, a single space character, the name of the function and a pair of parentheses

Can there be anything on the end function line other than leading whitespace and the endfunction keyword?

What is the name of your log file?

Why is there so much variation in the leading whitespace in your log file? (Most log files don't waste space with a lot of leading whitespace characters, nor to they have varying amounts of leading whitespace characters.) What is the specification for the format of the log file you will be processing?

Do the source files for the language you are trying to parse here really have the filename extension .file ?

The characters that are allowed in the function name are alphanumeric characters including underscore _.
There can be one more than one space between keyword function and function name as well as between function name and (

Assume No leading white space. I put it by mistake. There is no leading white space on the line with endfunction keyword

Log file name is error.log

The filename do have extension which is .v (for verilog) and .sv( for systemverilog) but there could be more extensions as well.

Is that an interpreted language, or a compiled one? For the latter, the compiler should generate a symbol table or equivalent, for debugging purposes amongst other things. For the former, wouldn't a simple numbered listing suffice?