简体   繁体   中英

Regex: Get separate parameters and parameter type of the CPP function (c#)

I do not know much regex, how to get the type of a variable and a variable?

Example source text:

func (int arg1, float *arg2, float *arg3)
func2 (const char * name, int arg1, int arg2, int arg3, void * mem)

Example regex

(\\(.*?)\\) 

— all variables at once, but how to get them separately?

\\((.*?),(.*?),(.*?)\\)

int arg1 float *arg2 float *arg3 , but may be more than 3 options ... And I need to get the type and parameter separately.

You should get yourself a copy of Antlr:

http://www.antlr.org/

If you've trying to parse C/C++ header files, there's more to it than just function declarations. Especially if it's C++.

Antlr is a great too for doing the sort of partial parse and tranformations that you seem to be talking about. Besides that, you get a C grammar for free, which might be sufficient for your needs (but I wouldn't count on it).

Get Terrance Parr's books, too:

如果您坚持使用正则表达式并假定函数签名不会变得非常复杂,则可以针对所有var_type var对进行循环,如下所示while(s/(.*?) (\\S+),//)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM