quasilyte / phpgrep

Syntax-aware grep for PHP code.
MIT License
236 stars 10 forks source link

Question: Possible to get whole body of function not one line? #66

Open klebann opened 3 years ago

klebann commented 3 years ago

Is that possible to get whole body of function as a string when you find specific function in this function?

Example:

function(){
    $var = "not important";
    notme();
}

function2(){
    $var = "important";
    imhere();
}

Command: phpgrep find only imhere();

Output:

    $var = "important";
    imhere();
quasilyte commented 3 years ago

Will context lines option be enought here (like -C in grep) or do you need an enclosing function?

What should happen if imhere() is located outside of the function? What if containing function is 1000 lines long? :)

klebann commented 3 years ago

do you need an enclosing function?

yes

What if containing function is 1000 lines long?

nothing , I have plenty of memory 😄

What should happen if imhere() is located outside of the function?

do I have a choice?whatever will happen, I can handle it.

quasilyte commented 3 years ago

do I have a choice?whatever will happen, I can handle it.

I can't implement a feature if its semantics are not well-defined, this is why I'm asking corner-case questions.

The match can happen at a global scope where we have no function to print. Should these matches be ignored or they should be intermixed with function matches?

klebann commented 3 years ago

Intermixed with function matches