plsql_parser is a production-ready SQL parser written in pure Erlang. plsql_parser is aligned to the Oracle PL/SQL language and enriched with some specific features.
CREATE PACKAGE my_package
IS
FUNCTION my_function
RETURN BOOLEAN;
END my_package;
1> {ok, {ParseTree, Tokens}} = plsql_parser:parsetree_with_tokens("CREATE PACKAGE my_package IS FUNCTION my_function RETURN BOOLEAN; END my_package;").
{ok,{[#{plsqlUnit =>
#{createPackage@ =>
#{createPackage =>
#{plsqlPackageSource@ =>
#{plsqlPackageSource =>
#{asIs@ => "IS",
packageItemList@ =>
[#{packageFunctionDeclaration =>
#{functionHeading@ =>
#{functionHeading =>
#{name@ =>
"my_function",
return@ =>
#{dataType =>
#{class@ =>
plsql,
type@ =>
"BOOLEAN"}}}}}}],
packageNameEnd@ => "my_package",
packageNameStart@ => "my_package"}}}}}}],
[{'CREATE',1},
{'PACKAGE',1},
{'NAME',10,"my_package"},
{'IS',1},
{'FUNCTION',1},
{'NAME',11,"my_function"},
{'RETURN',1},
{'BOOLEAN',1},
{';',1},
{'END',1},
{'NAME',10,"my_package"},
{';',1}]}}
2> ParseTree.
[#{plsqlUnit =>
#{createPackage@ =>
#{createPackage =>
#{plsqlPackageSource@ =>
#{plsqlPackageSource =>
#{asIs@ => "IS",
packageItemList@ =>
[#{packageFunctionDeclaration =>
#{functionHeading@ =>
#{functionHeading =>
#{name@ =>
"my_function",
return@ =>
#{dataType =>
#{class@ =>
plsql,
type@ =>
"BOOLEAN"}}}}}}],
packageNameEnd@ => "my_package",
packageNameStart@ => "my_package"}}}}}}]
3> Tokens.
[{'CREATE',1},
{'PACKAGE',1},
{'NAME',10,"my_package"},
{'IS',1},
{'FUNCTION',1},
{'NAME',11,"my_function"},
{'RETURN',1},
{'BOOLEAN',1},
{';',1},
{'END',1},
{'NAME',10,"my_package"},
{';',1}]
4> plsql_parser_fold:top_down(plsql_parser_format_flat, ParseTree, []).
<<"create package my_package IS function my_function return BOOLEAN; end my_package;">>
The documentation for plsql_parser is available here: Wiki.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request