|
From: <jom...@us...> - 2008-04-17 17:34:18
|
Revision: 1219
http://jason.svn.sourceforge.net/jason/?rev=1219&view=rev
Author: jomifred
Date: 2008-04-17 10:34:11 -0700 (Thu, 17 Apr 2008)
Log Message:
-----------
plans body as term
first implementation (experimental) of .if internal action
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestAll.java
trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java
trunk/release-notes.txt
trunk/src/jason/asSyntax/PlanBody.java
trunk/src/jason/asSyntax/PlanBodyImpl.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/test/ASParserTest.java
Added Paths:
-----------
trunk/applications/as-unit-test/src/jason/tests/TestIF.java
trunk/src/jason/stdlib/conditional.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestAll.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/applications/as-unit-test/src/jason/tests/TestAll.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -9,8 +9,9 @@
BugVarsInInitBels.class,
TestAddLogExprInBB.class,
TestGoalSource.class,
+ TestIF.class,
TestKQML.class,
- /* TestPlanbodyAsTerm.class, */
+ TestPlanbodyAsTerm.class,
TestPlanFailure.class,
TestVarInContext.class
})
Added: trunk/applications/as-unit-test/src/jason/tests/TestIF.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestIF.java (rev 0)
+++ trunk/applications/as-unit-test/src/jason/tests/TestIF.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -0,0 +1,42 @@
+package jason.tests;
+
+import jason.asunit.TestAgent;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestIF {
+
+ TestAgent ag;
+
+ // initialisation of the agent test
+ @Before
+ public void setupAg() {
+ ag = new TestAgent();
+
+ // defines the agent's AgentSpeak code
+ ag.parseAScode(
+ "b(3). " +
+ "+!test1 <- a1; "+
+ " .conditional(b(X), {jason.asunit.print(X); b1}, {jason.asunit.print(no);b2}); "+
+ " a2. "+
+ "+!test2 <- -b(_); !test1. "
+ );
+ }
+
+ @Test
+ public void test1() {
+ ag.addGoal("test1");
+ ag.assertPrint("3", 5);
+ ag.assertAct("b1", 5);
+ ag.assertAct("a2", 5);
+ }
+
+ @Test
+ public void test2() {
+ ag.addGoal("test2");
+ ag.assertPrint("no", 5);
+ ag.assertAct("b2", 5);
+ ag.assertAct("a2", 5);
+ }
+}
Modified: trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/applications/as-unit-test/src/jason/tests/TestPlanbodyAsTerm.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -16,23 +16,33 @@
// defines the agent's AgentSpeak code
ag.parseAScode(
- "+!start <- +g(a(1); b; c); ?g(X); !g(X). "+
- "+!test2 <- !g(!g2(1)). "+
- "+!test3 <- !g2(-1 + 2). "+
- "+!g(A; R) <- A; !g(R). "+
- "+!g(A) <- A." +
- "+!g2(A) <- jason.asunit.print(A)."
+ "+!start <- +g( {a(1); b; c}); ?g(X); !g(X). " +
+ "+!test2 <- !g( {!g2(1)}). "+
+ "+!test3 <- !g2(-1 + 2)."+
+ "+!test4 <- X = {a(1); b; c}; !g(X)."+
+
+ "+!g({A; R}) <- A; !g(R). "+
+ "+!g(A) <- A." +
+ "+!g2(A) <- jason.asunit.print(A)."
);
}
@Test
- public void testProgram1() {
+ public void testProgram1a() {
ag.addGoal("start");
- ag.assertBel("g(a(1);b;c)", 5);
+ ag.assertBel("g({a(1);b;c})", 5);
ag.assertAct("a(1)", 4);
ag.assertAct("b", 4);
ag.assertAct("c", 4);
}
+
+ @Test
+ public void testProgram1b() {
+ ag.addGoal("test4");
+ ag.assertAct("a(1)", 4);
+ ag.assertAct("b", 4);
+ ag.assertAct("c", 4);
+ }
@Test
public void testProgram2() {
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/release-notes.txt 2008-04-17 17:34:11 UTC (rev 1219)
@@ -2,6 +2,11 @@
version 1.1.1
-------------
+New features
+. Terms can be body plans enclosed by |{ ... }", as in the following
+ example:
+ test({ a1; !g; ?b(X); .print(X) }, 10)
+
Bugs fixed:
. use nested source annotations in communication
. add "source(self)" in goals without source
Modified: trunk/src/jason/asSyntax/PlanBody.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBody.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/PlanBody.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -17,7 +17,7 @@
public BodyType getBodyType();
public Term getBodyTerm();
- public PlanBody getBodyNext();
+ public PlanBody getBodyNext();
public boolean isEmptyBody();
public int getPlanSize();
@@ -25,7 +25,10 @@
public void setBodyType(BodyType bt);
public void setBodyTerm(Term t);
public void setBodyNext(PlanBody bl);
+ public PlanBody getLastBody();
+ public boolean isBodyTerm();
+ public void setAsBodyTerm(boolean b);
public boolean add(PlanBody bl);
public boolean add(int index, PlanBody bl);
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -20,9 +20,11 @@
public static final String BODY_PLAN_FUNCTOR = ";";
private Term term = null;
- private PlanBody next = null;
+ private PlanBody next = null;
private BodyType formType = BodyType.none;
+ private boolean isTerm = false;
+
/** constructor for empty plan body */
public PlanBodyImpl() {
super(BODY_PLAN_FUNCTOR, 0);
@@ -60,6 +62,13 @@
term = t;
}
+ public boolean isBodyTerm() {
+ return isTerm;
+ }
+ public void setAsBodyTerm(boolean b) {
+ isTerm = b;
+ }
+
@Override
public boolean isPlanBody() {
return true;
@@ -152,12 +161,23 @@
next.add(bl);
return true;
}
+
+ public PlanBody getLastBody() {
+ if (next == null)
+ return this;
+ else
+ return next.getLastBody();
+ }
public boolean add(int index, PlanBody bl) {
if (index == 0) {
swap(bl);
- this.next = bl;
- } else {
+ PlanBody bak = this.next;
+ this.next = bl.getBodyNext();
+ PlanBody last = bl.getLastBody();
+ bl.setBodyNext(bak);
+ last.setBodyNext(bl);
+ } else if (next != null) {
next.add(index - 1, bl);
}
return true;
@@ -203,18 +223,29 @@
return new PlanBodyImpl();
PlanBodyImpl c = new PlanBodyImpl(formType, (Term)term.clone());
+ c.isTerm = isTerm;
if (next != null)
c.setBodyNext((PlanBody)getBodyNext().clone());
return c;
}
public String toString() {
- if (term == null)
+ if (term == null) {
return "";
- else if (next == null)
- return formType.toString() + term;
- else
- return formType.toString() + term + "; " + next;
+ } else {
+ String b, e;
+ if (isTerm) {
+ b = "{ ";
+ e = " }";
+ } else {
+ b = "";
+ e = "";
+ }
+ if (next == null)
+ return b+formType.toString() + term+e;
+ else
+ return b+formType.toString() + term + "; " + next+e;
+ }
}
/** get as XML */
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -874,7 +874,7 @@
}
// -----------------------
- // BodyLiteral interface implementation
+ // PlanBody interface implementation
// -----------------------
public BodyType getBodyType() {
@@ -898,6 +898,13 @@
return null;
}
+ public PlanBody getLastBody() {
+ if (value != null && getValue() instanceof PlanBody)
+ return ((PlanBody) getValue()).getLastBody();
+ else
+ return null;
+ }
+
public boolean isEmptyBody() {
if (value != null && getValue() instanceof PlanBody)
return ((PlanBody) getValue()).isEmptyBody();
@@ -927,6 +934,18 @@
((PlanBody) getValue()).setBodyNext(bl);
}
+ public boolean isBodyTerm() {
+ if (value != null && getValue() instanceof PlanBody)
+ return ((PlanBody) getValue()).isBodyTerm();
+ else
+ return false;
+ }
+
+ public void setAsBodyTerm(boolean b) {
+ if (value != null && getValue() instanceof PlanBody)
+ ((PlanBody) getValue()).setAsBodyTerm(b);
+ }
+
public boolean add(PlanBody bl) {
if (value != null && getValue() instanceof PlanBody)
return ((PlanBody) getValue()).add(bl);
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-04-17 17:34:11 UTC (rev 1219)
@@ -289,8 +289,8 @@
/* Plan */
Plan plan() : { Token k; Pred L = null;
Trigger T;
- Object C = null; PlanBody bl = null;
- Object B = null;
+ Object C = null;
+ PlanBody B = null;
int start = -1, end;}
{
[ k = <TK_LABEL_AT> L=pred() { start = k.beginLine; } ]
@@ -303,14 +303,13 @@
try { ial = checkInternalActionsInContext((LogicalFormula)C, curAg); } catch (Exception e) {}
if (ial != null)
throw new ParseException(getSourceRef(ial)+" The internal action '"+ial+"' can not be used in plan's context!");
- if (B != null) {
- if (!(B instanceof PlanBody))
- throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);
- bl = (PlanBody)B;
- if (bl.getBodyTerm().equals(Literal.LTrue))
- bl = (PlanBody)bl.getBodyNext();
- }
- Plan p = new Plan(L,T,(LogicalFormula)C, bl);
+ //if (B != null) {
+ //if (!(B instanceof PlanBody))
+ // throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);
+ //bl = (PlanBody)B;
+ if (B != null && B.getBodyTerm().equals(Literal.LTrue))
+ B = (PlanBody)B.getBodyNext();
+ Plan p = new Plan(L,T,(LogicalFormula)C, B);
p.setSrcLines(start,end);
p.setSrc(asSource);
return p;
@@ -341,21 +340,31 @@
/* Plan body */
-Object plan_body() : { Object F; Object R = null; }
+PlanBody plan_body() : { Object F; PlanBody R = null; }
{
F = body_formula()
[ ";" { if (!(F instanceof PlanBody)) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!"); }
- R = plan_body() { if (!(R instanceof PlanBody)) throw new ParseException(getSourceRef(R)+" "+R+" is not a body literal!"); }
+ R = plan_body()
]
- { if (F instanceof PlanBody && R instanceof PlanBody) {
- ((PlanBody)F).setBodyNext( (PlanBody)R );
+ { if (F instanceof PlanBody) {
+ ((PlanBody)F).setBodyNext( R );
}
- return F;
+ return (PlanBody)F;
}
}
+PlanBody plan_body_term(): { PlanBody B = null; }
+{
+ "{"
+ B = plan_body()
+ "}"
+ { B.setAsBodyTerm(true);
+ return B;
+ }
+}
+
Object body_formula() :
{ BodyType formType = BodyType.action; Object B; }
{
@@ -448,18 +457,11 @@
Term term() : { Object o;}
{
- ( o=list()
- | o=log_expr() //plan_body() // plan_body includes literals/atoms/structures
+ ( o=list()
+ | o=plan_body_term()
+ | o=log_expr() // log_expr includes literals/atoms/structures
)
- { // if the result is a PlanBody action with size = 1, it is indeed a literal and not a body literal
- /*if (o instanceof PlanBody) {
- PlanBody bl = (PlanBody)o;
- if (bl.getBodyType() == BodyType.action && bl.getPlanSize() == 1) {
- o = bl.getBodyTerm();
- }
- }*/
- return changeToAtom(o);
- }
+ { return changeToAtom(o); }
}
@@ -548,6 +550,7 @@
( op2 = arithm_expr()
| op2 = string()
| op2 = list()
+ | op2 = plan_body_term()
)
{ if ( ((Term)op1).isInternalAction() && operator != RelationalOp.literalBuilder)
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -316,8 +316,8 @@
final public Plan plan() throws ParseException {
Token k; Pred L = null;
Trigger T;
- Object C = null; PlanBody bl = null;
- Object B = null;
+ Object C = null;
+ PlanBody B = null;
int start = -1, end;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_LABEL_AT:
@@ -357,14 +357,13 @@
try { ial = checkInternalActionsInContext((LogicalFormula)C, curAg); } catch (Exception e) {}
if (ial != null)
{if (true) throw new ParseException(getSourceRef(ial)+" The internal action '"+ial+"' can not be used in plan's context!");}
- if (B != null) {
- if (!(B instanceof PlanBody))
- {if (true) throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);}
- bl = (PlanBody)B;
- if (bl.getBodyTerm().equals(Literal.LTrue))
- bl = (PlanBody)bl.getBodyNext();
- }
- Plan p = new Plan(L,T,(LogicalFormula)C, bl);
+ //if (B != null) {
+ //if (!(B instanceof PlanBody))
+ // throw new ParseException(getSourceRef(B)+" Unknown body formula:"+B);
+ //bl = (PlanBody)B;
+ if (B != null && B.getBodyTerm().equals(Literal.LTrue))
+ B = (PlanBody)B.getBodyNext();
+ Plan p = new Plan(L,T,(LogicalFormula)C, B);
p.setSrcLines(start,end);
p.setSrc(asSource);
{if (true) return p;}
@@ -435,27 +434,36 @@
}
/* Plan body */
- final public Object plan_body() throws ParseException {
- Object F; Object R = null;
+ final public PlanBody plan_body() throws ParseException {
+ Object F; PlanBody R = null;
F = body_formula();
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case 37:
jj_consume_token(37);
if (!(F instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(F)+" "+F+" is not a body literal!");}
R = plan_body();
- if (!(R instanceof PlanBody)) {if (true) throw new ParseException(getSourceRef(R)+" "+R+" is not a body literal!");}
break;
default:
jj_la1[17] = jj_gen;
;
}
- if (F instanceof PlanBody && R instanceof PlanBody) {
- ((PlanBody)F).setBodyNext( (PlanBody)R );
+ if (F instanceof PlanBody) {
+ ((PlanBody)F).setBodyNext( R );
}
- {if (true) return F;}
+ {if (true) return (PlanBody)F;}
throw new Error("Missing return statement in function");
}
+ final public PlanBody plan_body_term() throws ParseException {
+ PlanBody B = null;
+ jj_consume_token(27);
+ B = plan_body();
+ jj_consume_token(28);
+ B.setAsBodyTerm(true);
+ {if (true) return B;}
+ throw new Error("Missing return statement in function");
+ }
+
final public Object body_formula() throws ParseException {
BodyType formType = BodyType.action; Object B;
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -642,6 +650,9 @@
case 42:
o = list();
break;
+ case 27:
+ o = plan_body_term();
+ break;
case VAR:
case TK_TRUE:
case TK_FALSE:
@@ -662,13 +673,6 @@
jj_consume_token(-1);
throw new ParseException();
}
- // if the result is a PlanBody action with size = 1, it is indeed a literal and not a body literal
- /*if (o instanceof PlanBody) {
- PlanBody bl = (PlanBody)o;
- if (bl.getBodyType() == BodyType.action && bl.getPlanSize() == 1) {
- o = bl.getBodyTerm();
- }
- }*/
{if (true) return changeToAtom(o);}
throw new Error("Missing return statement in function");
}
@@ -940,6 +944,9 @@
case 42:
op2 = list();
break;
+ case 27:
+ op2 = plan_body_term();
+ break;
default:
jj_la1[38] = jj_gen;
jj_consume_token(-1);
@@ -1187,8 +1194,8 @@
return false;
}
- final private boolean jj_3R_14() {
- if (jj_scan_token(42)) return true;
+ final private boolean jj_3R_13() {
+ if (jj_3R_14()) return true;
return false;
}
@@ -1197,6 +1204,11 @@
return false;
}
+ final private boolean jj_3R_14() {
+ if (jj_scan_token(42)) return true;
+ return false;
+ }
+
final private boolean jj_3R_11() {
Token xsp;
xsp = jj_scanpos;
@@ -1214,11 +1226,6 @@
return false;
}
- final private boolean jj_3R_13() {
- if (jj_3R_14()) return true;
- return false;
- }
-
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
@@ -1236,7 +1243,7 @@
jj_la1_1();
}
private static void jj_la1_0() {
- jj_la1_0 = new int[] {0x8000000,0x10cb00,0x8000000,0x80000000,0x8000000,0x10000,0x10cb00,0x8000000,0x8000000,0x20000000,0x10000,0x0,0x0,0x0,0x80000000,0x80000000,0x30cb80,0x0,0x0,0x80000000,0x80000000,0x800,0x10cb00,0x10c000,0x0,0x0,0x0,0x3acf80,0x0,0x200080,0x0,0x3acb80,0x3acb80,0x0,0x0,0x3acf80,0x3acb80,0x0,0x3acb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x32cb80,0x200080,0x0,};
+ jj_la1_0 = new int[] {0x8000000,0x10cb00,0x8000000,0x80000000,0x8000000,0x10000,0x10cb00,0x8000000,0x8000000,0x20000000,0x10000,0x0,0x0,0x0,0x80000000,0x80000000,0x30cb80,0x0,0x0,0x80000000,0x80000000,0x800,0x10cb00,0x10c000,0x0,0x0,0x0,0x83acf80,0x0,0x200080,0x0,0x3acb80,0x3acb80,0x0,0x0,0x3acf80,0x3acb80,0x0,0x83acb80,0x0,0x0,0x0,0x3000,0x3000,0x0,0x32cb80,0x200080,0x0,};
}
private static void jj_la1_1() {
jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x0,0xc,0x0,0x0,0x0,0x0,0x0,0x1,0x2,0xc,0x10,0x10,0x0,0x20,0x4,0x5c,0x5c,0x0,0x0,0x0,0x80,0x400,0x200,0x488,0x200,0x400,0x800,0x488,0x488,0x800,0x2000,0x88,0x88,0x3fc000,0x488,0x3fc000,0xc,0xc,0xc00000,0xc00000,0x1000000,0x88,0x0,0x400,};
Added: trunk/src/jason/stdlib/conditional.java
===================================================================
--- trunk/src/jason/stdlib/conditional.java (rev 0)
+++ trunk/src/jason/stdlib/conditional.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -0,0 +1,81 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.dur.ac.uk/r.bordini
+// http://www.inf.furb.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+package jason.stdlib;
+
+import java.util.Iterator;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.IntendedMeans;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.LogicalFormula;
+import jason.asSyntax.PlanBody;
+import jason.asSyntax.Term;
+
+// TODO: comments
+// TODO: find a way to change the name of the IA to .if
+public class conditional extends DefaultInternalAction {
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ if ( !(args[0] instanceof LogicalFormula))
+ throw new JasonException("The first argument of .if must be a logical formula.");
+
+ LogicalFormula logExpr = (LogicalFormula)args[0];
+ PlanBody whattoadd = null;
+
+ Iterator<Unifier> iu = logExpr.logicalConsequence(ts.getAg(), un);
+ if (iu.hasNext()) {
+ // THEN
+ un.compose(iu.next());
+ whattoadd = (PlanBody)args[1];
+ } else if (args.length == 3) {
+ // ELSE
+ whattoadd = (PlanBody)args[2];
+ }
+
+ if (whattoadd != null) {
+ if ( !whattoadd.isPlanBody())
+ throw new JasonException("The second and third arguments of .if must be a plan body term.");
+
+ IntendedMeans im = ts.getC().getSelectedIntention().peek();
+ PlanBody ifia = im.getCurrentStep();
+ whattoadd.setAsBodyTerm(false);
+ if (ifia.getPlanSize() == 1)
+ ifia.add(whattoadd);
+ else
+ ifia.add(1,whattoadd);
+ }
+ return true;
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new JasonException("The internal action 'if' has not received the required arguments.");
+ } catch (JasonException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new JasonException("Error in internal action 'if': " + e, e);
+ }
+ }
+}
Modified: trunk/src/test/ASParserTest.java
===================================================================
--- trunk/src/test/ASParserTest.java 2008-04-16 16:46:46 UTC (rev 1218)
+++ trunk/src/test/ASParserTest.java 2008-04-17 17:34:11 UTC (rev 1219)
@@ -4,11 +4,12 @@
import jason.asSemantics.Agent;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
-import jason.asSyntax.PlanBody;
+import jason.asSyntax.Literal;
import jason.asSyntax.LogExpr;
import jason.asSyntax.LogicalFormula;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Plan;
+import jason.asSyntax.PlanBody;
import jason.asSyntax.RelExpr;
import jason.asSyntax.parser.as2j;
import jason.infra.centralised.CentralisedAgArch;
@@ -164,18 +165,18 @@
}
public void testParsingPlanBody() {
- // TODO: think about this
- /*
- Literal l = Literal.parseLiteral("p(a1;a2, a3, !g, ?b;.print(oi), 10)");
+ Literal l = Literal.parseLiteral("p( {a1(f);a2}, a3, {!g}, {?b;.print(oi) }, 10)");
+ assertEquals("p({ a1(f); a2 },a3,{ !g },{ ?b; .print(oi) },10)", l.toString());
assertEquals(5,l.getArity());
- assertTrue(l.getTerm(0) instanceof BodyLiteral);
+ assertTrue(l.getTerm(0) instanceof PlanBody);
assertTrue(l.getTerm(0).isPlanBody());
+ PlanBody pb = (PlanBody)l.getTerm(0);
+ assertTrue(pb.isBodyTerm());
assertFalse(l.getTerm(1).isPlanBody());
assertTrue(l.getTerm(2).isPlanBody());
assertTrue(l.getTerm(3).isPlanBody());
assertFalse(l.getTerm(4).isPlanBody());
- */
}
public void testParsingAllSources() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|