Ejemplo n.º 1
0
 public void End(Pred directive, as2j parser)
 {
     if (oldNS.Peek() != null)
     {
         parser.SetNS(oldNS.Pop());
     }
 }
Ejemplo n.º 2
0
        public void ParseAs(StreamReader asIn, string sourceId)
        {
            as2j parser = new as2j(asIn);

            parser.SetASLSource(sourceId);
            parser.AgentMethod(this);
        }
Ejemplo n.º 3
0
        public void Begin(Pred directive, as2j parser)
        {
            if (!directive.GetTerm(0).IsAtom())
            {
                return;
            }
            Atom ns = new Atom(((Atom)directive.GetTerm(0)).GetFunctor());

            if (directive.GetArity() > 1)
            {
                if (!directive.GetTerm(1).IsAtom())
                {
                    return;
                }
                string type = ((Atom)directive.GetTerm(1)).GetFunctor();
                if (!type.Equals("local") && !type.Equals("global"))
                {
                    return;
                }
                if (type.Equals("global") && IsLocalNS(ns))
                {
                    localNSs.Remove(ns);
                }
                if (type.Equals("local"))
                {
                    ns = AddLocalNS(ns);
                }
            }

            oldNS.Push(parser.GetNS());
            parser.SetNS(ns);
        }
Ejemplo n.º 4
0
        public static Rule ParseRule(string sRule)
        {
            as2j parser = new as2j(new StringReader(sRule));
            Rule r      = (Rule)parser.Belief();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + r + " for parameter '" + sRule + "'");
            }
            return(r);
        }
Ejemplo n.º 5
0
        public static ILogicalFormula ParseFormula(string sExpr)
        {
            as2j            parser = new as2j(new StringReader(sExpr));
            ILogicalFormula l      = (ILogicalFormula)parser.Log_expr();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + l + " for parameter '" + sExpr + "'");
            }
            return(l);
        }
Ejemplo n.º 6
0
        public static IListTerm ParseList(string sList)
        {
            as2j      parser = new as2j(new StringReader(sList));
            IListTerm l      = parser.List();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + l + " for parameter '" + sList + "'");
            }
            return(l);
        }
Ejemplo n.º 7
0
        public static Trigger ParseTrigger(string sTe)
        {
            as2j    parser = new as2j(new StringReader(sTe));
            Trigger te     = parser.Trigger();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + te + " for parameter '" + sTe + "'");
            }
            return(te);
        }
Ejemplo n.º 8
0
        public static IPlanBody ParsePlanBody(string sPlanBody)
        {
            as2j      parser = new as2j(new StringReader(sPlanBody));
            IPlanBody p      = parser.Plan_body();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + p + " for parameter '" + sPlanBody + "'");
            }
            return(p);
        }
Ejemplo n.º 9
0
        public static ITerm ParseTerm(string sTerm)
        {
            as2j  parser = new as2j(new StringReader(sTerm));
            ITerm t      = parser.TermMethod();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + t + " for parameter '" + sTerm + "'");
            }
            return(t);
        }
Ejemplo n.º 10
0
        public static VarTerm ParseVar(string sVar)
        {
            as2j    parser = new as2j(new StringReader(sVar));
            VarTerm v      = parser.Var(Literal.DefaultNS);

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + v + " for parameter '" + sVar + "'");
            }
            return(v);
        }
Ejemplo n.º 11
0
        public static Literal ParseLiteral(string sLiteral)
        {
            as2j    parser = new as2j(new StringReader(sLiteral));
            Literal l      = parser.LiteralMethod();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + l + " for parameter '" + sLiteral + "'");
            }
            return(l);
        }
Ejemplo n.º 12
0
        public void SetOptions(string options)
        {
            as2j parser = new as2j(new StringReader(options));

            try
            {
                SetOptions(parser.ASoptions());
                Debug.Log("Sttings are " + userParameters);
            }
            catch (Exception e)
            {
                Debug.Log("Error parseing options " + options);
            }
        }
Ejemplo n.º 13
0
        public static Structure ParseStructure(string sStructure)
        {
            as2j  parser = new as2j(new StringReader(sStructure));
            ITerm t      = parser.TermMethod();

            if (parser.getNextToken().kind != as2jConstants.EOF)
            {
                throw new ParseException("Expected <EOF> after " + t + " for parameter '" + sStructure + "'");
            }
            if (t.GetType() == typeof(Structure))
            {
                return((Structure)t);
            }
            else
            {
                return(new Structure((Literal)t));
            }
        }
Ejemplo n.º 14
0
 public void End(Pred directive, as2j parser)
 {
 }
Ejemplo n.º 15
0
 public void Begin(Pred directive, as2j parser)
 {
 }
Ejemplo n.º 16
0
        public override Agent Process(Pred directive, Agent outerContent, Agent innerContent)
        {
            if (outerContent == null)
            {
                return(null);
            }

            // handles file (arg[0])
            string file = ((IStringTerm)directive.GetTerm(0)).GetString().Replace("\\\\", "/");

            try
            {
                TextReader input = null; //Es posible que haya que cambiarlo a streamreader
                // test include from jar
                if (file.StartsWith("$"))
                { // the case of "$jasonJar/src/a.asl"
                  //string jar = file.Substring(1, file.IndexOf("/"));
                  //string result;
                  //if (Config.Get().TryGetValue(jar, out result))
                  //{
                  //    return null;
                  //}

                    //Config.Get().TryGetValue(jar, out result);
                    //string path =  result.ToString();
                    //file = "jar:file:" + path + "!" + file.Substring(file.IndexOf("/"));
                    ////este file tiene que ser una ruta al archivo asl
                    ////input = new URL(file).openStream();
                    //input = File.OpenText(file);
                }

                else
                {
                    string outerPrefix = outerContent.GetASLSrc(); // the source file that has the include directive
                    if (outerContent != null && outerPrefix != null)
                    {
                        // check if the outer is URL
                        if (outerPrefix.StartsWith("jar"))
                        {
                            //outerPrefix = outerPrefix.Substring(0, outerPrefix.IndexOf("!") + 1) + "/";
                            //file = aslSourcePath.FixPath(file, outerPrefix);
                            //input = File.OpenText(file);
                        }

                        else if (outerPrefix.StartsWith(SourcePath.CRPrefix))
                        {
                            //// outer is loaded from a resource ("application".jar) file, used for java web start
                            //int posSlash = outerPrefix.LastIndexOf("/");
                            //SourcePath newpath = new SourcePath();
                            //if (outerPrefix.IndexOf("/") != posSlash)
                            //{ // has only one slash
                            //    newpath.AddPath(outerPrefix.Substring(SourcePath.CRPrefix.Length + 1, posSlash));
                            //}
                            //newpath.AddAll(aslSourcePath);

                            //file = newpath.FixPath(file, SourcePath.CRPrefix + "/");
                            ///*Esto esta buscando en el paquete concreto de bdi agent*/
                            ////En input tenemos que acabar abriendo un textreader
                            ////Tenemos que ver exactamente donde esta esta cosa
                            ////Esto para hacerlo bien Unity hay que usar el sistema de getión de recursos de Unity: Resource.Load(string);
                            ////input = Agent.GetResource(file.Substring(SourcePath.CRPrefix.Length)).openStream();//Mirar los resources de unity por si acaso hay algo
                            //input = new StringReader(file.Substring(SourcePath.CRPrefix.Length));
                            ////Esto hay que hacerlo con unity porque esto es raruno
                        }

                        else if (outerPrefix.StartsWith("file:") || outerPrefix.StartsWith("http:") || outerPrefix.StartsWith("https:"))
                        {
                            ////URL url = new URL(new URL(outerPrefix), file);
                            ////file = url.ToString();
                            //file = outerPrefix + file;
                            //input = File.OpenText(file);
                        }

                        else if (file.StartsWith("jar:") || file.StartsWith("file:") || file.StartsWith("http:") || file.StartsWith("https:"))
                        {
                            ////URL url = new URL(file);
                            ////file = url.ToString(); //Mirar arriba
                            ////input = url.openStream();
                            //file = outerPrefix + file;
                            //input = File.OpenText(file);
                        }

                        else ///ESTE DE AQUI
                        {
                            // get the directory of the source of the outer agent and
                            // try to find the included source in the same directory
                            // or in the source paths
                            SourcePath newpath = new SourcePath();
                            newpath.AddPath(Path.GetFullPath((new StreamReader(outerPrefix)).ToString()));
                            // new StreamReader(outerPrefix).GetAbsoluteFile().getParent()
                            newpath.AddAll(aslSourcePath);
                            file  = newpath.FixPath(file, null);
                            input = new StreamReader(file);
                        }
                    }

                    else //ESTE DE AQUI
                    {
                        input = new StreamReader(aslSourcePath.FixPath(file, null));
                    }
                }

                // handles namespace (args[1])
                Atom ns = directive.GetNS();
                if (directive.GetArity() > 1)
                {
                    if (directive.GetTerm(1).IsVar())
                    {
                        ns = new Atom("ns" + NameSpace.GetUniqueID());
                        directive.SetTerm(1, ns);
                    }

                    else
                    {
                        if (directive.GetTerm(1).IsAtom())
                        {
                            ns = new Atom(((Atom)directive.GetTerm(1)).GetFunctor());
                        }
                    }
                }
                Agent ag = new Agent();
                ag.InitAg();

                as2j sparser = new as2j(input);
                sparser.SetASLSource(file);
                sparser.SetNS(ns);
                sparser.AgentMethod(ag);

                return(ag);
            }

            catch (FileNotFoundException e) {
            }
            catch (Exception e) {
            }
            return(null);
        }