From: <jom...@us...> - 2014-06-10 15:00:36
|
Revision: 1790 http://sourceforge.net/p/jason/svn/1790 Author: jomifred Date: 2014-06-10 15:00:32 +0000 (Tue, 10 Jun 2014) Log Message: ----------- fix a bug related to .puts reported by B. Smilga. in jason list Modified Paths: -------------- trunk/doc/faq/faq.tex trunk/release-notes.txt trunk/src/jason/asSyntax/InternalActionLiteral.java trunk/src/jason/asSyntax/Structure.java trunk/src/jason/stdlib/puts.java Modified: trunk/doc/faq/faq.tex =================================================================== --- trunk/doc/faq/faq.tex 2014-06-07 14:10:43 UTC (rev 1789) +++ trunk/doc/faq/faq.tex 2014-06-10 15:00:32 UTC (rev 1790) @@ -573,10 +573,14 @@ % \htlink{Log4J}{http://logging.apache.org/log4j/} to output messages into the console (the default console is called MASConsole). To change the log level or device, select the menu -``Plugins -> Jason -> Edit Log properties''. The default configuration -file has comments that helps you customise your log. For instance, -to output messages both into an XML file and in the console, you only -need to set the log handler as in the following line: +``Plugins -> Jason -> Edit Log properties'' in the jEdit plugin. If +you are not using jEdit, you can copy de default configuration file +from +\texttt{..../JASON_HOME_DIRECTORY/src/templates/logging.properties} to +your application directory. The default configuration file has +comments that helps you customise your log. For instance, to output +messages both into an XML file and in the console, you only need to +set the log handler as in the following line: \begin{verbatim} handlers = java.util.logging.FileHandler, java.util.logging.ConsoleHandler \end{verbatim} Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2014-06-07 14:10:43 UTC (rev 1789) +++ trunk/release-notes.txt 2014-06-10 15:00:32 UTC (rev 1790) @@ -1,4 +1,15 @@ --------------------------- +version 1.4.1 + +revision X on SVN +--------------------------- + +New features + +- web view of agent's mind (url usually is http://localhost:3272) + + +--------------------------- version 1.4.0 revision 1759 on SVN Modified: trunk/src/jason/asSyntax/InternalActionLiteral.java =================================================================== --- trunk/src/jason/asSyntax/InternalActionLiteral.java 2014-06-07 14:10:43 UTC (rev 1789) +++ trunk/src/jason/asSyntax/InternalActionLiteral.java 2014-06-10 15:00:32 UTC (rev 1790) @@ -26,6 +26,7 @@ import jason.asSemantics.Agent; import jason.asSemantics.InternalAction; import jason.asSemantics.Unifier; +import jason.stdlib.puts; import java.util.ConcurrentModificationException; import java.util.Iterator; @@ -81,6 +82,16 @@ public boolean isAtom() { return false; } + + @Override + public Literal makeVarsAnnon(Unifier un) { + Literal t = super.makeVarsAnnon(un); + if (t.getFunctor().equals(".puts")) { // vars inside strings like in .puts("bla #{X}") should be also replace + // TODO: should it work for any string? if so, proceed this replacement inside StringTermImpl + ((puts)puts.create()).makeVarsAnnon(t,un); + } + return t; + } @SuppressWarnings("unchecked") public Iterator<Unifier> logicalConsequence(Agent ag, Unifier un) { Modified: trunk/src/jason/asSyntax/Structure.java =================================================================== --- trunk/src/jason/asSyntax/Structure.java 2014-06-07 14:10:43 UTC (rev 1789) +++ trunk/src/jason/asSyntax/Structure.java 2014-06-10 15:00:32 UTC (rev 1790) @@ -346,7 +346,7 @@ private final static boolean useShortUnnamedVars = Config.get().getBoolean(Config.SHORT_UNNAMED_VARS); - protected VarTerm varToReplace(Term t, Unifier un) { + public VarTerm varToReplace(Term t, Unifier un) { VarTerm vt = (VarTerm)t; VarTerm deref = un.deref(vt); //if (deref.isUnnamedVar()) Modified: trunk/src/jason/stdlib/puts.java =================================================================== --- trunk/src/jason/stdlib/puts.java 2014-06-07 14:10:43 UTC (rev 1789) +++ trunk/src/jason/stdlib/puts.java 2014-06-10 15:00:32 UTC (rev 1790) @@ -1,13 +1,17 @@ package jason.stdlib; +import jason.JasonException; import jason.asSemantics.DefaultInternalAction; import jason.asSemantics.InternalAction; import jason.asSemantics.TransitionSystem; import jason.asSemantics.Unifier; import jason.asSyntax.ASSyntax; +import jason.asSyntax.Literal; import jason.asSyntax.StringTerm; import jason.asSyntax.StringTermImpl; +import jason.asSyntax.Structure; import jason.asSyntax.Term; +import jason.asSyntax.VarTerm; import jason.asSyntax.parser.ParseException; import java.util.regex.Matcher; @@ -73,15 +77,21 @@ } //Pattern regex = Pattern.compile("#\\{\\p{Upper}\\p{Alnum}*\\}"); - Pattern regex = Pattern.compile("#\\{\\p{Alnum}+\\}"); + Pattern regex = Pattern.compile("#\\{[\\p{Alnum}_]+\\}"); + + @Override public int getMinArgs() { return 1; } + @Override public int getMaxArgs() { return 2; } + @Override protected void checkArguments(Term[] args) throws JasonException { + super.checkArguments(args); // check number of arguments + if (!args[0].isString()) + throw JasonException.createWrongArgument(this,"first argument must be a string"); + } + @Override - public Object execute(TransitionSystem ts, Unifier un, Term[] args) - throws Exception { - if (!args[0].isString()) { - return false; - } - + public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception { + checkArguments(args); + StringBuffer sb = new StringBuffer(); for (Term term : args) { if (!term.isString()) { @@ -123,4 +133,31 @@ return true; } } + + public void makeVarsAnnon(Literal l, Unifier un) { + try { + for (int i=0; i<l.getArity(); i++) { + Term t = l.getTerm(i); + if (t.isString()) { + StringTerm st = (StringTerm)t; + Matcher matcher = regex.matcher(st.getString()); + StringBuffer sb = new StringBuffer(); + + while (matcher.find()) { + String sVar = matcher.group(); + sVar = sVar.substring(2, sVar.length() - 1); + Term v = ASSyntax.parseTerm(sVar); + if (v.isVar()) { + VarTerm to = ((Structure)l).varToReplace(v, un); + matcher.appendReplacement(sb, "#{"+to.toString()+"}"); + } + } + matcher.appendTail(sb); + l.setTerm(i, new StringTermImpl(sb.toString())); + } + } + } catch (ParseException pe) { + pe.printStackTrace(); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |