|
From: <jom...@us...> - 2016-02-24 14:32:42
|
Revision: 1871
http://sourceforge.net/p/jason/svn/1871
Author: jomifred
Date: 2016-02-24 14:32:39 +0000 (Wed, 24 Feb 2016)
Log Message:
-----------
namespace directive
Modified Paths:
--------------
trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
trunk/src/jason/asSyntax/parser/as2j.java
trunk/src/jason/jeditplugin/Config.java
trunk/src/test/NSTest.java
Added Paths:
-----------
trunk/src/jason/asSyntax/directives/NameSpace.java
Modified: trunk/src/jason/asSyntax/directives/DirectiveProcessor.java
===================================================================
--- trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/asSyntax/directives/DirectiveProcessor.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -46,6 +46,7 @@
static {
addDirective("include", new Include());
addDirective("register_function", new FunctionRegister());
+ addDirective("namespace", new NameSpace());
addDirective("dg", new DG());
addDirective("bdg", new BDG());
Added: trunk/src/jason/asSyntax/directives/NameSpace.java
===================================================================
--- trunk/src/jason/asSyntax/directives/NameSpace.java (rev 0)
+++ trunk/src/jason/asSyntax/directives/NameSpace.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -0,0 +1,51 @@
+package jason.asSyntax.directives;
+
+import jason.asSemantics.Agent;
+import jason.asSyntax.Atom;
+import jason.asSyntax.Pred;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/** Implementation of the <code>namespace</code> directive. */
+public class NameSpace implements Directive {
+
+ //static Logger logger = Logger.getLogger(NameSpace.class.getName());
+
+ private Map<Atom,Atom> localNSs = new HashMap<Atom,Atom>();
+
+ public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
+ return innerContent;
+ }
+
+ public Atom declareNS(Pred directive) {
+ Atom ns = new Atom( ((Atom)directive.getTerm(0)).getFunctor() );
+ if (directive.getArity() > 1) {
+ String type = ((Atom)directive.getTerm(1)).getFunctor();
+ if (type.equals("local")) {
+ return addLocalNS(ns);
+ }
+ }
+ return ns;
+ }
+
+ public boolean isLocalNS(Atom ns) {
+ return localNSs.get(ns) != null;
+ }
+
+ public Atom map(Atom ns) {
+ Atom n = localNSs.get(ns);
+ if (n == null)
+ return ns;
+ else
+ return n;
+ }
+
+ static private int nsCounter = 0;
+ private synchronized Atom addLocalNS(Atom ns) {
+ nsCounter++;
+ Atom newNS = new Atom("#"+nsCounter+ns);
+ localNSs.put(ns,newNS);
+ return newNS;
+ }
+}
Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc
===================================================================
--- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2016-02-24 14:32:39 UTC (rev 1871)
@@ -50,9 +50,10 @@
import jason.jeditplugin.*;
public class as2j {
- private String asSource = null;
- private Agent curAg = null;
- private Atom namespace = Literal.DefaultNS;
+ private String asSource = null;
+ private Agent curAg = null;
+ private Atom namespace = Literal.DefaultNS;
+ private NameSpace nsDirective = new NameSpace();
private static Logger logger = Logger.getLogger("aslparser");
private static Set<String> parsedFiles = new HashSet<String>();
@@ -251,24 +252,34 @@
Agent resultOfDirective = null;
Agent bakAg = curAg;
boolean isEOF = false;
+ Atom oldNS = null;
}
{
"{"
( LOOKAHEAD(4)
<TK_BEGIN> dir = pred() "}"
- { Agent innerAg = new Agent(); innerAg.initAg(); }
+ { Agent innerAg = new Agent(); innerAg.initAg();
+ if (dir.getFunctor().equals("namespace")) {
+ Atom newNS = nsDirective.declareNS(dir); // to declare the namespace as local
+ oldNS = namespace;
+ setNS( newNS );
+ }
+ }
isEOF = agent(innerAg)
{ if (isEOF)
throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");
else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
+ resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
+ if (oldNS != null)
+ setNS( oldNS );
}
|
dir = pred() "}"
{ if (dir.toString().equals("end"))
return true;
- else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
+ if (dir.getFunctor().equals("namespace"))
+ nsDirective.declareNS(dir); // to declare the namespace as local
+ resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
}
)
{ if (resultOfDirective != null && outerAg != null) {
@@ -645,6 +656,7 @@
}
if (ASSyntax.isKeyword(F))
NS = Literal.DefaultNS;
+ NS = nsDirective.map(NS);
return new LiteralImpl(NS, type, F);
}
Modified: trunk/src/jason/asSyntax/parser/as2j.java
===================================================================
--- trunk/src/jason/asSyntax/parser/as2j.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/asSyntax/parser/as2j.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -19,9 +19,10 @@
import jason.jeditplugin.*;
public class as2j implements as2jConstants {
- private String asSource = null;
- private Agent curAg = null;
- private Atom namespace = Literal.DefaultNS;
+ private String asSource = null;
+ private Agent curAg = null;
+ private Atom namespace = Literal.DefaultNS;
+ private NameSpace nsDirective = new NameSpace();
private static Logger logger = Logger.getLogger("aslparser");
private static Set<String> parsedFiles = new HashSet<String>();
@@ -259,17 +260,25 @@
Agent resultOfDirective = null;
Agent bakAg = curAg;
boolean isEOF = false;
+ Atom oldNS = null;
jj_consume_token(30);
if (jj_2_1(4)) {
jj_consume_token(TK_BEGIN);
dir = pred();
jj_consume_token(31);
Agent innerAg = new Agent(); innerAg.initAg();
+ if (dir.getFunctor().equals("namespace")) {
+ Atom newNS = nsDirective.declareNS(dir); // to declare the namespace as local
+ oldNS = namespace;
+ setNS( newNS );
+ }
isEOF = agent(innerAg);
if (isEOF)
{if (true) throw new ParseException(getSourceRef(dir)+" The directive '{ begin "+dir+"}' does not end with '{ end }'.");}
else
resultOfDirective = DirectiveProcessor.process(dir, outerAg, innerAg);
+ if (oldNS != null)
+ setNS( oldNS );
} else {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case TK_BEGIN:
@@ -279,8 +288,9 @@
jj_consume_token(31);
if (dir.toString().equals("end"))
{if (true) return true;}
- else
- resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
+ if (dir.getFunctor().equals("namespace"))
+ nsDirective.declareNS(dir); // to declare the namespace as local
+ resultOfDirective = DirectiveProcessor.process(dir, outerAg, null);
break;
default:
jj_la1[8] = jj_gen;
@@ -977,6 +987,7 @@
}
if (ASSyntax.isKeyword(F))
NS = Literal.DefaultNS;
+ NS = nsDirective.map(NS);
{if (true) return new LiteralImpl(NS, type, F);}
throw new Error("Missing return statement in function");
@@ -1634,37 +1645,6 @@
finally { jj_save(3, xla); }
}
- final private boolean jj_3R_117() {
- if (jj_3R_124()) return true;
- return false;
- }
-
- final private boolean jj_3R_116() {
- if (jj_3R_123()) return true;
- return false;
- }
-
- final private boolean jj_3R_61() {
- if (jj_3R_66()) return true;
- return false;
- }
-
- final private boolean jj_3R_115() {
- if (jj_3R_122()) return true;
- return false;
- }
-
- final private boolean jj_3R_114() {
- if (jj_3R_121()) return true;
- return false;
- }
-
- final private boolean jj_3R_60() {
- if (jj_scan_token(TK_NOT)) return true;
- if (jj_3R_52()) return true;
- return false;
- }
-
final private boolean jj_3R_108() {
Token xsp;
xsp = jj_scanpos;
@@ -1700,6 +1680,12 @@
return false;
}
+ final private boolean jj_3R_53() {
+ if (jj_scan_token(52)) return true;
+ if (jj_3R_38()) return true;
+ return false;
+ }
+
final private boolean jj_3R_48() {
if (jj_scan_token(40)) return true;
return false;
@@ -1712,9 +1698,11 @@
return false;
}
- final private boolean jj_3R_53() {
- if (jj_scan_token(52)) return true;
- if (jj_3R_38()) return true;
+ final private boolean jj_3R_38() {
+ if (jj_3R_52()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_53()) jj_scanpos = xsp;
return false;
}
@@ -1728,14 +1716,6 @@
return false;
}
- final private boolean jj_3R_38() {
- if (jj_3R_52()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_53()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_33() {
if (jj_scan_token(36)) return true;
return false;
@@ -1751,6 +1731,12 @@
return false;
}
+ final private boolean jj_3R_39() {
+ if (jj_scan_token(50)) return true;
+ if (jj_3R_20()) return true;
+ return false;
+ }
+
final private boolean jj_3R_17() {
if (jj_scan_token(35)) return true;
if (jj_3R_20()) return true;
@@ -1767,12 +1753,6 @@
return false;
}
- final private boolean jj_3R_39() {
- if (jj_scan_token(50)) return true;
- if (jj_3R_20()) return true;
- return false;
- }
-
final private boolean jj_3R_31() {
if (jj_scan_token(39)) return true;
return false;
@@ -1789,11 +1769,6 @@
return false;
}
- final private boolean jj_3R_29() {
- if (jj_scan_token(37)) return true;
- return false;
- }
-
final private boolean jj_3R_20() {
if (jj_3R_38()) return true;
Token xsp;
@@ -1802,6 +1777,11 @@
return false;
}
+ final private boolean jj_3R_29() {
+ if (jj_scan_token(37)) return true;
+ return false;
+ }
+
final private boolean jj_3_2() {
Token xsp;
xsp = jj_scanpos;
@@ -1904,11 +1884,6 @@
return false;
}
- final private boolean jj_3R_59() {
- if (jj_scan_token(TK_LABEL_AT)) return true;
- return false;
- }
-
final private boolean jj_3R_76() {
if (jj_scan_token(50)) return true;
Token xsp;
@@ -1923,11 +1898,8 @@
return false;
}
- final private boolean jj_3R_46() {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_59()) jj_scanpos = xsp;
- if (jj_3R_16()) return true;
+ final private boolean jj_3R_59() {
+ if (jj_scan_token(TK_LABEL_AT)) return true;
return false;
}
@@ -1942,6 +1914,14 @@
return false;
}
+ final private boolean jj_3R_46() {
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_59()) jj_scanpos = xsp;
+ if (jj_3R_16()) return true;
+ return false;
+ }
+
final private boolean jj_3R_54() {
if (jj_scan_token(VAR)) return true;
return false;
@@ -2024,13 +2004,13 @@
return false;
}
- final private boolean jj_3R_128() {
- if (jj_3R_20()) return true;
+ final private boolean jj_3R_113() {
+ if (jj_3R_120()) return true;
return false;
}
- final private boolean jj_3R_113() {
- if (jj_3R_120()) return true;
+ final private boolean jj_3R_128() {
+ if (jj_3R_20()) return true;
return false;
}
@@ -2041,6 +2021,16 @@
return false;
}
+ final private boolean jj_3R_41() {
+ if (jj_3R_57()) return true;
+ Token xsp;
+ while (true) {
+ xsp = jj_scanpos;
+ if (jj_3R_79()) { jj_scanpos = xsp; break; }
+ }
+ return false;
+ }
+
final private boolean jj_3R_136() {
if (jj_scan_token(37)) return true;
return false;
@@ -2051,16 +2041,6 @@
return false;
}
- final private boolean jj_3R_41() {
- if (jj_3R_57()) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_79()) { jj_scanpos = xsp; break; }
- }
- return false;
- }
-
final private boolean jj_3R_139() {
if (jj_scan_token(46)) return true;
return false;
@@ -2071,6 +2051,12 @@
return false;
}
+ final private boolean jj_3R_111() {
+ if (jj_scan_token(37)) return true;
+ if (jj_3R_102()) return true;
+ return false;
+ }
+
final private boolean jj_3R_137() {
if (jj_scan_token(37)) return true;
return false;
@@ -2084,12 +2070,6 @@
return false;
}
- final private boolean jj_3R_111() {
- if (jj_scan_token(37)) return true;
- if (jj_3R_102()) return true;
- return false;
- }
-
final private boolean jj_3R_135() {
Token xsp;
xsp = jj_scanpos;
@@ -2127,21 +2107,16 @@
return false;
}
- final private boolean jj_3R_44() {
- if (jj_3R_19()) return true;
+ final private boolean jj_3R_109() {
+ if (jj_scan_token(NUMBER)) return true;
return false;
}
- final private boolean jj_3R_131() {
- if (jj_scan_token(44)) return true;
+ final private boolean jj_3R_44() {
+ if (jj_3R_19()) return true;
return false;
}
- final private boolean jj_3R_109() {
- if (jj_scan_token(NUMBER)) return true;
- return false;
- }
-
final private boolean jj_3R_23() {
if (jj_scan_token(42)) return true;
if (jj_3R_41()) return true;
@@ -2149,6 +2124,11 @@
return false;
}
+ final private boolean jj_3R_131() {
+ if (jj_scan_token(44)) return true;
+ return false;
+ }
+
final private boolean jj_3R_130() {
if (jj_scan_token(34)) return true;
return false;
@@ -2244,24 +2224,11 @@
return false;
}
- final private boolean jj_3_1() {
- if (jj_scan_token(TK_BEGIN)) return true;
- if (jj_3R_13()) return true;
- if (jj_scan_token(31)) return true;
- if (jj_3R_14()) return true;
- return false;
- }
-
final private boolean jj_3R_107() {
if (jj_scan_token(TK_INTMOD)) return true;
return false;
}
- final private boolean jj_3R_43() {
- if (jj_scan_token(30)) return true;
- return false;
- }
-
final private boolean jj_3R_106() {
if (jj_scan_token(TK_INTDIV)) return true;
return false;
@@ -2294,11 +2261,6 @@
return false;
}
- final private boolean jj_3R_37() {
- if (jj_scan_token(TK_FALSE)) return true;
- return false;
- }
-
final private boolean jj_3R_95() {
if (jj_3R_97()) return true;
Token xsp;
@@ -2309,6 +2271,19 @@
return false;
}
+ final private boolean jj_3R_37() {
+ if (jj_scan_token(TK_FALSE)) return true;
+ return false;
+ }
+
+ final private boolean jj_3_1() {
+ if (jj_scan_token(TK_BEGIN)) return true;
+ if (jj_3R_13()) return true;
+ if (jj_scan_token(31)) return true;
+ if (jj_3R_14()) return true;
+ return false;
+ }
+
final private boolean jj_3R_36() {
if (jj_scan_token(TK_TRUE)) return true;
return false;
@@ -2319,6 +2294,11 @@
return false;
}
+ final private boolean jj_3R_43() {
+ if (jj_scan_token(30)) return true;
+ return false;
+ }
+
final private boolean jj_3R_50() {
if (jj_3R_13()) return true;
return false;
@@ -2400,6 +2380,11 @@
return false;
}
+ final private boolean jj_3R_89() {
+ if (jj_3R_78()) return true;
+ return false;
+ }
+
final private boolean jj_3R_35() {
Token xsp;
xsp = jj_scanpos;
@@ -2414,11 +2399,6 @@
return false;
}
- final private boolean jj_3R_89() {
- if (jj_3R_78()) return true;
- return false;
- }
-
final private boolean jj_3R_88() {
if (jj_3R_77()) return true;
return false;
@@ -2437,13 +2417,13 @@
return false;
}
- final private boolean jj_3R_129() {
- if (jj_scan_token(TK_ELSE)) return true;
+ final private boolean jj_3R_87() {
+ if (jj_scan_token(58)) return true;
return false;
}
- final private boolean jj_3R_87() {
- if (jj_scan_token(58)) return true;
+ final private boolean jj_3R_129() {
+ if (jj_scan_token(TK_ELSE)) return true;
return false;
}
@@ -2452,6 +2432,11 @@
return false;
}
+ final private boolean jj_3R_85() {
+ if (jj_scan_token(56)) return true;
+ return false;
+ }
+
final private boolean jj_3R_125() {
Token xsp;
xsp = jj_scanpos;
@@ -2460,21 +2445,11 @@
return false;
}
- final private boolean jj_3R_85() {
- if (jj_scan_token(56)) return true;
- return false;
- }
-
final private boolean jj_3R_84() {
if (jj_scan_token(55)) return true;
return false;
}
- final private boolean jj_3R_28() {
- if (jj_3R_46()) return true;
- return false;
- }
-
final private boolean jj_3R_83() {
if (jj_scan_token(54)) return true;
return false;
@@ -2495,23 +2470,6 @@
return false;
}
- final private boolean jj_3R_27() {
- if (jj_3R_45()) return true;
- return false;
- }
-
- final private boolean jj_3R_121() {
- if (jj_scan_token(TK_IF)) return true;
- if (jj_scan_token(42)) return true;
- if (jj_3R_20()) return true;
- if (jj_scan_token(43)) return true;
- if (jj_3R_67()) return true;
- Token xsp;
- xsp = jj_scanpos;
- if (jj_3R_125()) jj_scanpos = xsp;
- return false;
- }
-
final private boolean jj_3R_74() {
Token xsp;
xsp = jj_scanpos;
@@ -2551,13 +2509,20 @@
return false;
}
- final private boolean jj_3R_73() {
- if (jj_3R_78()) return true;
+ final private boolean jj_3R_121() {
+ if (jj_scan_token(TK_IF)) return true;
+ if (jj_scan_token(42)) return true;
+ if (jj_3R_20()) return true;
+ if (jj_scan_token(43)) return true;
+ if (jj_3R_67()) return true;
+ Token xsp;
+ xsp = jj_scanpos;
+ if (jj_3R_125()) jj_scanpos = xsp;
return false;
}
- final private boolean jj_3R_26() {
- if (jj_3R_44()) return true;
+ final private boolean jj_3R_73() {
+ if (jj_3R_78()) return true;
return false;
}
@@ -2566,8 +2531,8 @@
return false;
}
- final private boolean jj_3R_25() {
- if (jj_3R_43()) return true;
+ final private boolean jj_3R_28() {
+ if (jj_3R_46()) return true;
return false;
}
@@ -2583,6 +2548,31 @@
return false;
}
+ final private boolean jj_3R_27() {
+ if (jj_3R_45()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_119() {
+ if (jj_3R_108()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_26() {
+ if (jj_3R_44()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_118() {
+ if (jj_scan_token(41)) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_25() {
+ if (jj_3R_43()) return true;
+ return false;
+ }
+
final private boolean jj_3R_14() {
Token xsp;
while (true) {
@@ -2605,16 +2595,37 @@
return false;
}
- final private boolean jj_3R_119() {
- if (jj_3R_108()) return true;
+ final private boolean jj_3R_117() {
+ if (jj_3R_124()) return true;
return false;
}
- final private boolean jj_3R_118() {
- if (jj_scan_token(41)) return true;
+ final private boolean jj_3R_61() {
+ if (jj_3R_66()) return true;
return false;
}
+ final private boolean jj_3R_116() {
+ if (jj_3R_123()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_115() {
+ if (jj_3R_122()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_60() {
+ if (jj_scan_token(TK_NOT)) return true;
+ if (jj_3R_52()) return true;
+ return false;
+ }
+
+ final private boolean jj_3R_114() {
+ if (jj_3R_121()) return true;
+ return false;
+ }
+
public as2jTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
Modified: trunk/src/jason/jeditplugin/Config.java
===================================================================
--- trunk/src/jason/jeditplugin/Config.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/jason/jeditplugin/Config.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -696,8 +696,11 @@
private String getJarFromEclipseInstallation(String file) {
String eclipse = System.getProperty("eclipse.launcher");
//eclipse = "/Applications/eclipse/eclipse";
- if (eclipse != null) {
- File f = new File( (new File(eclipse)).getParentFile()+"/"+getEclipseInstallationDirectory()+"/lib/"+file);
+ if (eclipse != null) {
+ File f = (new File(eclipse)).getParentFile().getParentFile();
+ if (eclipse.contains("Eclipse.app/Contents")) // MacOs case
+ f = f.getParentFile().getParentFile();
+ f = new File(f+"/"+getEclipseInstallationDirectory()+"/lib/"+file);
if (f.exists())
return f.getAbsolutePath();
}
Modified: trunk/src/test/NSTest.java
===================================================================
--- trunk/src/test/NSTest.java 2016-02-21 11:55:00 UTC (rev 1870)
+++ trunk/src/test/NSTest.java 2016-02-24 14:32:39 UTC (rev 1871)
@@ -242,4 +242,33 @@
parser.agent(a);
assertTrue(a.getPL().toString().contains("[source(self)] +NS::tick <- .print(ns33::NS)."));
}
+
+
+ public void testDirective() throws ParseException, JasonException {
+ as2j parser = new as2j(new StringReader(
+ "{begin namespace(ns1)}\n"+
+ " b1(t). "+
+ " +tick <- .print(t); !g(u). "+
+ "{end}\n"+
+ "{begin namespace(ns2,local)}\n"+
+ " b4(t). "+
+ " +tk <- .print(t); !g5(u). "+
+ "{end}\n"+
+ "b5(i)."+
+ "{namespace(ns3,local)}\n"+
+ "b2(t). +!g2(V) <- +b3(h); +ns1::tick; +ns2::tk; +ns3::b5(ns2::t). "
+ ));
+
+ Agent a = new Agent();
+ a.initAg();
+ parser.setNS(new Atom("nsd"));
+ parser.agent(a);
+ a.addInitialBelsInBB();
+ //System.out.println(a.getBB());
+ //System.out.println(a.getPL().toString());
+ assertTrue(a.getPL().toString().contains("+ns1::tick <- .print(ns1::t); !ns1::g(ns1::u)"));
+ assertTrue(a.getPL().toString().contains("+!nsd::g2(nsd::V) <- +nsd::b3(nsd::h); +ns1::tick; +#1ns2::tk; +#2ns3::b5(#1ns2::t)"));
+ assertTrue(a.getPL().toString().contains("+#1ns2::tk <- .print(#1ns2::t); !#1ns2::g5(#1ns2::u)"));
+
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|