|
From: Vinícius d. S. O. <vin...@gm...> - 2021-06-25 22:55:37
|
Em sex., 25 de jun. de 2021 às 10:07, Andrew J. Schorr <as...@te...> escreveu: > 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 mean the pattern. On plugin startup, I want to traverse all the program rules to check if any pattern in them matches the AST "somevar". I'll code the plugin's behaviour to depend on whether such a rule exists in the program. The end result gives an approximation of what's offered by BEGINFILE rules to deal with errors on single files, but for record-level errors. > 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. Thanks for the pointer. Now I know where to start. -- Vinícius dos Santos Oliveira https://vinipsmaker.github.io/ |