From: Andrew J. S. <as...@te...> - 2021-06-25 13:07:21
|
Hi Jürgen, On Fri, Jun 25, 2021 at 10:09:54AM +0200, Jürgen Kahrs via Gawkextlib-users wrote: > I think he wants to detect the presence (and not the value) of a > certain AWK rule at run-time. The term "rule" here seems to mean > a keyword that exists after being declared by the plugin. I'm not sure that I understand what "rule" means in an awk script. >From the POSIX spec: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html An awk program is composed of pairs of the form: pattern { action } So what's a "rule"? In the source code, it appears that the word "rule" is used to refer to the combination of a pattern and an action. So is the idea that this API hook would depend on detecting whether a combined pattern & action is present? > I agree with you (Andrew) that the script example that he gave > should be accompanied by a more detailed implementation of > the plugin. Maybe it would suffice to have a way of looking up > all the keywords that are defined after loading a plugin. The implementation of BEGINFILE and ENDFILE requires a lot of special support in the interpreter. It seems to me that implementing this sort of thing requires diving into the guts of how a program is compiled in awkgram.y, which is quite frankly an area of the code that I've never messed with. In main.c, the program is parsed into code_block: INSTRUCTION *code_block = NULL; ... /* Read in the program */ if (parse_program(& code_block, false) != 0 || dash_v_errs > 0) exit(EXIT_FAILURE); And then it runs the program by calling interpret(code_block). So any info about the running program would have to be extracted by parsing the INSTRUCTION data pointed to by code_block, as far as I can tell. Regards, Andy |