Reputation: 880
I need to take hunreds of pl/sql files which contain stored procedures, views and functions and split them all into individual files.
example:
create or replace function practice_function(hello in table.hello%type) return varchar2 as
hello2 varchar2(6);
begin
if hello is not null then
hello2 := "hi";
end if;
return hello2;
end practice_function
/
This is just an example of a stored function. The file could contain 10 or 20 of these with comments and block comments etc. Could somebody give me advice on a high or low level of how I should go about it and how I should go about writing a parser.
At the moment I'm using Java to read in a file line by line and parse each line as they come in. This for instance has caused problems when I need to ignore code which has a block comment.
Any advice would be great
Upvotes: 0
Views: 1057
Reputation: 16526
Writing a PL/SQL or almost any other parser is a challenging task. Basically you need to:
And even a task to remove comments from your code may become quite challenging. Walking this tree and removing comment nodes should be no problem. Difficult might be the part when you want to print your new tree because the natural walking order might not be the same as the correct textual order.
You may try using an existing ANTLR parser. This will complete the first two steps.
An article on how to start with ANTLR: antlr: is there a simple example?
Upvotes: 1