Skip to content

Commit

Permalink
Added correct parse of IS [NOT] NULL
Browse files Browse the repository at this point in the history
fixed crash of parsing following code (from unittest):
IF V_BUF IS NULL THEN
null;
end if;
  • Loading branch information
xuthus authored and jsotuyod committed Nov 22, 2016
1 parent 051f50e commit 90862cc
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pmd-plsql/etc/grammar/PldocAST.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Andreas Dangel 11/2016
*/

/**
* Added ASTIsNullCondition node
*
* Sergey Yanzin 11/2016
*/

//
options {
DEBUG_PARSER = false ;
Expand Down Expand Up @@ -1972,12 +1978,33 @@ ASTUnaryExpressionNotPlusMinus UnaryExpressionNotPlusMinus() :
(<NOT>) {sb.append(" NOT "); }
(simpleNode = UnaryExpression(false) ) { sb.append(simpleNode.getImage()); }
|
(simpleNode = IsOfTypeCondition() ) {sb.append(simpleNode.getImage()); }
(simpleNode = IsNullCondition() ) {sb.append(simpleNode.getImage()); }
)
{
jjtThis.setImage(sb.toString()); return jjtThis;
}
}
ASTIsNullCondition IsNullCondition() : //yanzin
{ PLSQLNode simpleNode = null; PLSQLNode name = null; StringBuilder sb = new StringBuilder(); }
{
(
LOOKAHEAD(<IDENTIFIER> <IS> (<NOT> <NULL>|<NULL>))
(
(name = Name()) {sb.append(name.getImage());} <IS> {sb.append(" IS");} [<NOT> {sb.append(" NOT");}] <NULL> {sb.append(" NULL");}
)
|
(
simpleNode = IsOfTypeCondition()
)
{
sb.append(simpleNode.getImage());
}
)
{
jjtThis.setImage(sb.toString());
return jjtThis;
}
}

ASTIsOfTypeCondition IsOfTypeCondition() :
{ PLSQLNode simpleNode = null; PLSQLNode name = null; StringBuilder sb = new StringBuilder(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ public Object visit(ASTIsOfTypeCondition node, Object data) {
return visit((PLSQLNode) node, data);
}

@Override
public Object visit(ASTIsNullCondition node, Object data) {
return visit((PLSQLNode) node, data);
}

/*
* Treat all Executable Code
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public void testBug1520IsOfType() throws Exception {
public void testBug1520Using() throws Exception {
parsePLSQL(IOUtils.toString(PLSQLParserTest.class.getResourceAsStream("ast/Using.pls")));
}

@Test
public void testIsNull() throws Exception {
parsePLSQL(IOUtils.toString(PLSQLParserTest.class.getResourceAsStream("ast/IsNull.pls")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
PROCEDURE IsNull (
dummy IN number
)
is
V_BUF varchar(1);
BEGIN

IF V_BUF IS NULL THEN
null;
end if;

IF V_BUF IS NOT NULL THEN
null;
end if;

end;

0 comments on commit 90862cc

Please sign in to comment.