Ejemplo n.º 1
0
 internal override void Start()
 {
     base.Start();
     repl = new Repl {
                Output = Out,
                CurrentGameObject = DefaultGameObject??gameObject,
                OnChangeKB = KBChanged
            };
     WindowTitle = "Prolog console: " + repl.CurrentKnowledgeBase.Name;
     Prolog.TraceOutput = Out;
     PrologChecker.Check();
 }
 internal override void Start()
 {
     base.Start();
     repl = new Repl {
         Output            = Out,
         CurrentGameObject = DefaultGameObject ?? gameObject,
         OnChangeKB        = KBChanged
     };
     WindowTitle        = "Prolog console: " + repl.CurrentKnowledgeBase.Name;
     Prolog.TraceOutput = Out;
     PrologChecker.Check();
 }
Ejemplo n.º 3
0
 internal override void Start()
 {
     //Header = "Prolog REPL";
     WindowTitle = "Prolog console";
     base.Start();
     repl = new Repl {
         Output            = Out,
         CurrentGameObject = DefaultGameObject ?? gameObject
     };
     Prolog.TraceOutput = Out;
     PrologChecker.Check();
 }
Ejemplo n.º 4
0
 internal override void Start()
 {
     //Header = "Prolog REPL";
     WindowTitle = "Prolog console";
     base.Start();
     repl = new Repl {
                Output = Out,
                CurrentGameObject = DefaultGameObject??gameObject
            };
     Prolog.TraceOutput = Out;
     PrologChecker.Check();
 }
Ejemplo n.º 5
0
        // ReSharper disable once InconsistentNaming
        public void Read(Action <int, Structure> rowHandler)
        {
            var row = 1;

            try
            {
                this.ReadHeaderRow();
                row++;
                while (reader.Peek() >= 0)
                {
                    // Windows excel generates invalid CSV files that contain
                    // \r\n rather than \r as is defined by the spec.
                    if (reader.Peek() == '\n')
                    {
                        reader.Read();
                    }
                    if (reader.Peek() == '%')
                    {
                        SkipLine(); // Skip comment lines
                    }
                    else
                    {
                        rowHandler(row, this.ReadFactRow());
                    }
                    row++;
                }
            }
            catch (InferenceStepsExceededException e)
            {
                Repl.RecordExceptionSourceLocation(e, row);
                throw;
            }
            catch (Exception e)
            {
                var wrapper = new PrologError(e,
                                              string.Format("{0} row {1}",
                                                            Path.GetFileName(Prolog.CurrentSourceFile),
                                                            row));
                Debug.LogException(wrapper);
                Repl.RecordExceptionSourceLocation(e, row);
                throw wrapper;
            }
        }
Ejemplo n.º 6
0
        // ReSharper disable once InconsistentNaming
        public void Read(Action <int, Structure> rowHandler)
        {
            var row = 1;

            try
            {
                this.ReadHeaderRow();
                row++;
                while (reader.Peek() >= 0)
                {
                    if (reader.Peek() == '%')
                    {
                        SkipLine(); // Skip comment lines
                    }
                    else
                    {
                        rowHandler(row, this.ReadFactRow());
                    }
                    row++;
                }
            }
            catch (InferenceStepsExceededException e)
            {
                Repl.RecordExceptionSourceLocation(e, row);
                throw;
            }
            catch (Exception e)
            {
                var wrapper = new PrologError(e,
                                              string.Format("{0} row {1}",
                                                            Path.GetFileName(Prolog.CurrentSourceFile),
                                                            row));
                UnityEngine.Debug.LogException(wrapper);
                Repl.RecordExceptionSourceLocation(e, row);
                throw wrapper;
            }
        }
Ejemplo n.º 7
0
        public void Consult(TextReader inStream)
        {
            sourceFiles.NoteFile(Prolog.CurrentSourceFile);
            var reader = new ISOPrologReader(inStream);

            reader.SkipLayout();
            int lastLine = reader.LineNumber;

            using (var context = PrologContext.Allocate(this, this))
            {
                try
                {
                    object unexpanded;
                    Prolog.CurrentSourceLineNumber = lastLine;
                    while ((unexpanded = reader.ReadTerm()) != Symbol.EndOfFile)
                    {
                        // Perform user-level macroexpansion.
                        object assertion = TermExpansion(unexpanded);
                        if (ELProlog.IsELTerm(assertion))
                        {
                            // It's an EL term.
                            ELProlog.Update(assertion, this);
                        }
                        else
                        {
                            // It's a normal Prolog term
                            var t = Term.Structurify(
                                assertion,
                                "Assertions in prolog files must be valid propositions or predicates.");

                            // Perform built-in macroexpansion.
                            t = t.Expand();

                            if (t.IsFunctor(Symbol.Implication, 1))
                            {
                                context.Reset();
                                var goal = Term.Structurify(
                                    t.Argument(0),
                                    "Argument to a :- directive must be an atom or structure.");
                                // Run t once, but don't backtrack for a second solution (since it's presumably an imperative anyway).
                                Prove(goal.Functor, goal.Arguments, context, 0).GetEnumerator().MoveNext();
                            }
                            else
                            {
                                Assert(t, true, true);
                            }
                        }
                        reader.SkipLayout();
                        lastLine = reader.LineNumber;
                        Prolog.CurrentSourceLineNumber = lastLine;
                    }
                }
                catch (InferenceStepsExceededException e)
                {
                    Repl.RecordExceptionSourceLocation(e, lastLine);
                    throw;
                }
                catch (Exception e)
                {
                    UnityEngine.Debug.LogException(e);
                    Repl.RecordExceptionSourceLocation(e, lastLine);
                    throw new PrologError(
                              e,
                              context.StackTrace(Prolog.CurrentSourceFile, Prolog.CurrentSourceLineNumber, "consult/1", false));
                }
            }
        }