Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions bridgepoint/oal.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,9 @@ class OALParser(object):
'PARAM',
'RCVD_EVT',
'SELF',
'SELECTED'
'SELECTED',
'LOOP',
'THEN'
)

tokens = keywords + (
Expand Down Expand Up @@ -1436,26 +1438,47 @@ def p_delete_statement(self, p):
p[0] = DeleteNode(variable_name=p[4])

@track_production
def p_for_statement(self, p):
def p_for_statement_1(self, p):
'''statement : FOR EACH variable_name IN variable_name LOOP block END_FOR'''
p[0] = ForEachNode(instance_variable_name=p[3],
set_variable_name=p[5],
block=p[7])

@track_production
def p_for_statement_2(self, p):
'''statement : FOR EACH variable_name IN variable_name block END_FOR'''
p[0] = ForEachNode(instance_variable_name=p[3],
set_variable_name=p[5],
block=p[6])

@track_production
def p_while_statement(self, p):
def p_while_statement_1(self, p):
'''statement : WHILE expression LOOP block END_WHILE'''
p[0] = WhileNode(expression=p[2],
block=p[4])

@track_production
def p_while_statement_2(self, p):
'''statement : WHILE expression block END_WHILE'''
p[0] = WhileNode(expression=p[2],
block=p[3])

@track_production
def p_if_statement(self, p):
def p_if_statement_1(self, p):
'''statement : IF expression THEN block elif_list else_clause END_IF'''
p[0] = IfNode(expression=p[2],
block=p[4],
elif_list=p[5],
else_clause=p[6])

@track_production
def p_if_statement_2(self, p):
'''statement : IF expression block elif_list else_clause END_IF'''
p[0] = IfNode(expression=p[2],
block=p[3],
elif_list=p[4],
else_clause=p[5])

@track_production
def p_elif_list_1(self, p):
'''elif_list : '''
Expand All @@ -1468,7 +1491,13 @@ def p_elif_list_2(self, p):
p[0].children.insert(0, p[2])

@track_production
def p_elif_clause(self, p):
def p_elif_clause_1(self, p):
'''elif_clause : expression THEN block'''
p[0] = ElIfNode(expression=p[1],
block=p[3])

@track_production
def p_elif_clause_2(self, p):
'''elif_clause : expression block'''
p[0] = ElIfNode(expression=p[1],
block=p[2])
Expand Down
29 changes: 28 additions & 1 deletion tests/test_bridgepoint/test_foreach.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def setUp(self):
relate(pe_pe, o_obj, 8001)

@prebuild_docstring
def test_for_each_loop(self):
def test_for_each(self):
'''
create object instance of A;
create object instance of A;
Expand All @@ -57,6 +57,33 @@ def test_for_each_loop(self):

o_obj = one(act_for).O_OBJ[670]()
self.assertEqual(o_obj.Key_Lett, 'A')

@prebuild_docstring
def test_for_each_loop(self):
'''
create object instance of A;
create object instance of A;
select many a_set from instances of A;
for each a in a_set loop
end for;
'''
act_for = self.metamodel.select_one('ACT_FOR')
self.assertTrue(act_for.is_implicit)

act_smt = one(act_for).ACT_SMT[603]()
self.assertIsNotNone(act_smt)

act_blk = one(act_for).ACT_BLK[605]()
self.assertIsNotNone(act_blk)

v_var = one(act_for).V_VAR[614]()
self.assertEqual(v_var.Name, 'a')

v_var = one(act_for).V_VAR[652]()
self.assertEqual(v_var.Name, 'a_set')

o_obj = one(act_for).O_OBJ[670]()
self.assertEqual(o_obj.Key_Lett, 'A')


if __name__ == "__main__":
Expand Down
45 changes: 42 additions & 3 deletions tests/test_bridgepoint/test_ifs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestIfStatements(PrebuildFunctionTestCase):
@prebuild_docstring
def test_single_if_true(self):
'''
if ( 0 == 0 )
if ( 0 == 0 ) then
return 1;
end if;
return 0;
Expand All @@ -53,6 +53,45 @@ def test_single_if_true(self):

@prebuild_docstring
def test_elif(self):
'''
assign x = 0;
if (1 == 0) then
assign x = 1;
elif (1 == 1) then
assign x = 2;
end if;
return x;
'''
act_if = self.metamodel.select_one('ACT_IF')
self.assertIsNotNone(act_if)

act_smt = one(act_if).ACT_SMT[603]()
self.assertIsNotNone(act_smt)

v_val = one(act_if).V_VAL[625]()
self.assertIsNotNone(v_val)

act_blk = one(act_if).ACT_BLK[607]()
self.assertIsNotNone(act_blk)

act_el = many(act_if).ACT_EL[682]()
self.assertEqual(len(act_el), 1)

act_el = one(act_if).ACT_EL[682]()
act_smt = one(act_el).ACT_SMT[603]()
self.assertIsNotNone(act_smt)

v_val = one(act_el).V_VAL[659]()
self.assertIsNotNone(v_val)

act_blk = one(act_el).ACT_BLK[658]()
self.assertIsNotNone(act_blk)

act_e = one(act_if).ACT_E[683]()
self.assertIsNone(act_e)

@prebuild_docstring
def test_elif_no_then(self):
'''
assign x = 0;
if (1 == 0)
Expand Down Expand Up @@ -94,9 +133,9 @@ def test_elif(self):
def test_elif_else(self):
'''
assign x = 0;
if (1 == 0)
if (1 == 0) then
assign x = 1;
elif (1 == 1)
elif (1 == 1) then
assign x = 2;
else
assign x = 3;
Expand Down
26 changes: 23 additions & 3 deletions tests/test_bridgepoint/test_while.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class TestWhileLoop(PrebuildFunctionTestCase):

@prebuild_docstring
def test_while_loop(self):
def test_while(self):
'''
assign x = 10;
while (x > 0)
Expand All @@ -44,12 +44,32 @@ def test_while_loop(self):

act_blk = one(act_whl).ACT_BLK[608]()
self.assertIsNotNone(act_blk)

@prebuild_docstring
def test_while_loop(self):
'''
assign x = 10;
while (x > 0) loop
assign x = x - 1;
end while;
return x;
'''
act_whl = self.metamodel.select_one('ACT_WHL')
self.assertIsNotNone(act_whl)

act_smt = one(act_whl).ACT_SMT[603]()
self.assertIsNotNone(act_smt)

v_val = one(act_whl).V_VAL[626]()
self.assertIsNotNone(v_val)

act_blk = one(act_whl).ACT_BLK[608]()

@prebuild_docstring
def test_while_loop_with_break(self):
'''
assign x = 10;
while (x > 0)
while (x > 0) loop
if (x == 5)
break;
end if;
Expand All @@ -68,7 +88,7 @@ def test_while_loop_with_break(self):
def test_while_loop_with_continue(self):
'''
assign x = 10;
while (x > 0)
while (x > 0) loop
if (x == 5)
continue;
end if;
Expand Down