public void HandleToggleBreakpoints()
        {
            Console.Write("Available breakpoint positions:\n  ");

            PrintSequenceContext contextBp = new PrintSequenceContext();

            contextBp.bpPosCounter = 0;
            SequencePrinter.PrintSequence(debugSequences.Peek(), contextBp, debugSequences.Count);
            Console.WriteLine();

            if (contextBp.bpPosCounter == 0)
            {
                Console.WriteLine("No breakpoint positions available!");
                return;
            }

            int pos = HandleTogglePoint("breakpoint", contextBp.bpPosCounter);

            if (pos == -1)
            {
                return;
            }

            TogglePointInAllInstances(pos, false);
        }
Exemple #2
0
 public static void ChoosePointPrintHeader(PrintSequenceContext context, double pointToExecute)
 {
     WorkaroundManager.Workaround.PrintHighlighted("Please choose: Which point in the interval series (corresponding to a sequence) to execute?", HighlightingMode.Choicepoint);
     Console.WriteLine(" Pre-selecting point " + pointToExecute + " chosen by random.");
     Console.WriteLine("Press (e) to enter a point in the interval series of the sequence to show."
                       + " Press (s) or (n) to commit to the pre-selected sequence and continue.");
 }
        public void HandleToggleChoicepoints()
        {
            Console.Write("Available choicepoint positions:\n  ");

            PrintSequenceContext contextCp = new PrintSequenceContext();

            contextCp.cpPosCounter = 0;
            SequencePrinter.PrintSequence(debugSequences.Peek(), contextCp, debugSequences.Count);
            Console.WriteLine();

            if (contextCp.cpPosCounter == 0)
            {
                Console.WriteLine("No choicepoint positions available!");
                return;
            }

            int pos = HandleTogglePoint("choicepoint", contextCp.cpPosCounter);

            if (pos == -1)
            {
                return;
            }

            TogglePointInAllInstances(pos, true);
        }
Exemple #4
0
 public static void ChooseMatchSomeFromSetPrintHeader(PrintSequenceContext context, int totalMatchToExecute)
 {
     WorkaroundManager.Workaround.PrintHighlighted("Please choose: Which match to execute?", HighlightingMode.Choicepoint);
     Console.WriteLine(" Pre-selecting match " + totalMatchToExecute + " chosen by random.");
     Console.WriteLine("Press (0)...(9) to pre-select the corresponding match or (e) to enter the number of the match to show."
                       + " Press (s) or (n) to commit to the pre-selected match and continue.");
 }
Exemple #5
0
        public static int ChooseDirection(PrintSequenceContext context, IDebuggerEnvironment env, int direction, Sequence seq)
        {
            WorkaroundManager.Workaround.PrintHighlighted("Please choose: Which branch to execute first?", HighlightingMode.Choicepoint);
            Console.Write(" (l)eft or (r)ight or (s)/(n) to continue with random choice?  (Random has chosen " + (direction == 0 ? "(l)eft" : "(r)ight") + ") ");

            do
            {
                ConsoleKeyInfo key = env.ReadKeyWithCancel();
                switch (key.KeyChar)
                {
                case 'l':
                    Console.WriteLine();
                    return(0);

                case 'r':
                    Console.WriteLine();
                    return(1);

                case 's':
                case 'n':
                    Console.WriteLine();
                    return(direction);

                default:
                    Console.WriteLine("Illegal choice (Key = " + key.Key
                                      + ")! Only (l)eft branch, (r)ight branch, (s)/(n) to continue allowed! ");
                    break;
                }
            }while(true);
        }
Exemple #6
0
 public static void ChooseMatchPrintHeader(PrintSequenceContext context, int numFurtherMatchesToApply)
 {
     WorkaroundManager.Workaround.PrintHighlighted("Please choose: Which match to apply?", HighlightingMode.Choicepoint);
     Console.WriteLine(" Showing the match chosen by random. (" + numFurtherMatchesToApply + " following)");
     Console.WriteLine("Press (0)...(9) to show the corresponding match or (e) to enter the number of the match to show."
                       + " Press (s) or (n) to commit to the currently shown match and continue.");
 }
        /// <summary>
        /// Called from shell after an debugging abort highlighting the lastly executed rule
        /// </summary>
        public static void PrintSequence(Sequence seq, Sequence highlight)
        {
            PrintSequenceContext context = new PrintSequenceContext();

            context.highlightSeq = highlight;
            PrintSequence(seq, context, 0);
            // TODO: what to do if abort came within sequence called from top sequence?
        }
Exemple #8
0
 public static void ChooseSequencePrintHeader(PrintSequenceContext context, int seqToExecute)
 {
     WorkaroundManager.Workaround.PrintHighlighted("Please choose: Which sequence to execute?", HighlightingMode.Choicepoint);
     Console.WriteLine(" Pre-selecting sequence " + seqToExecute + " chosen by random.");
     Console.WriteLine("Press (0)...(9) to pre-select the corresponding sequence or (e) to enter the number of the sequence to show."
                       + " Press (s) or (n) to commit to the pre-selected sequence and continue."
                       + " Pressing (u) or (o) works like (s)/(n) but does not ask for the remaining contained sequences.");
 }
 private static void PrintChoice(SequenceRandomChoice seq, PrintSequenceContext context)
 {
     if (seq.Choice)
     {
         WorkaroundManager.Workaround.PrintHighlighted("-%" + context.cpPosCounter + "-:", HighlightingMode.Choicepoint);
     }
     else
     {
         WorkaroundManager.Workaround.PrintHighlighted("+%" + context.cpPosCounter + "+:", HighlightingMode.Choicepoint);
     }
 }
 private static void PrintBreak(SequenceSpecial seq, PrintSequenceContext context)
 {
     if (seq.Special)
     {
         WorkaroundManager.Workaround.PrintHighlighted("-%" + context.bpPosCounter + "-:", HighlightingMode.Breakpoint);
     }
     else
     {
         WorkaroundManager.Workaround.PrintHighlighted("+%" + context.bpPosCounter + "+:", HighlightingMode.Breakpoint);
     }
 }
        private static void PrintChildren(Sequence seq, PrintSequenceContext context)
        {
            bool first = true;

            foreach (Sequence seqChild in seq.Children)
            {
                if (!first)
                {
                    Console.Write(", ");
                }
                PrintSequence(seqChild, seq, context);
                first = false;
            }
        }
        private static void PrintListOfMatchesNumbers(PrintSequenceContext context, ref int numCurTotalMatch, int numMatches)
        {
            WorkaroundManager.Workaround.PrintHighlighted("(", HighlightingMode.Choicepoint);
            bool first = true;

            for (int i = 0; i < numMatches; ++i)
            {
                if (!first)
                {
                    WorkaroundManager.Workaround.PrintHighlighted(",", HighlightingMode.Choicepoint);
                }
                WorkaroundManager.Workaround.PrintHighlighted(numCurTotalMatch.ToString(), HighlightingMode.Choicepoint);
                ++numCurTotalMatch;
                first = false;
            }
            WorkaroundManager.Workaround.PrintHighlighted(")", HighlightingMode.Choicepoint);
        }
        private static void PrintSequenceRulePrefixedSequence(SequenceRulePrefixedSequence seqRulePrefixedSequence, Sequence parent, PrintSequenceContext context)
        {
            if (!(parent is SequenceMultiRulePrefixedSequence))
            {
                Console.Write("[");
            }

            Console.Write("for{");
            PrintSequence(seqRulePrefixedSequence.Rule, seqRulePrefixedSequence, context);
            Console.Write(";");
            PrintSequence(seqRulePrefixedSequence.Sequence, seqRulePrefixedSequence, context);
            Console.Write("}");

            if (!(parent is SequenceMultiRulePrefixedSequence))
            {
                Console.Write("]");
            }
        }
        /// <summary>
        /// Prints the given sequence adding parentheses if needed according to the print context.
        /// </summary>
        /// <param name="seq">The sequence to be printed</param>
        /// <param name="parent">The parent of the sequence or null if the sequence is a root</param>
        /// <param name="context">The print context</param>
        private static void PrintSequence(Sequence seq, Sequence parent, PrintSequenceContext context)
        {
            // print parentheses, if neccessary
            if (parent != null && seq.Precedence < parent.Precedence)
            {
                Console.Write("(");
            }

            switch (seq.SequenceType)
            {
            case SequenceType.ThenLeft:
            case SequenceType.ThenRight:
            case SequenceType.LazyOr:
            case SequenceType.LazyAnd:
            case SequenceType.StrictOr:
            case SequenceType.Xor:
            case SequenceType.StrictAnd:
                PrintSequenceBinary((SequenceBinary)seq, parent, context);
                break;

            case SequenceType.IfThen:
                PrintSequenceIfThen((SequenceIfThen)seq, parent, context);
                break;

            case SequenceType.Not:
                PrintSequenceNot((SequenceNot)seq, parent, context);
                break;

            case SequenceType.IterationMin:
                PrintSequenceIterationMin((SequenceIterationMin)seq, parent, context);
                break;

            case SequenceType.IterationMinMax:
                PrintSequenceIterationMinMax((SequenceIterationMinMax)seq, parent, context);
                break;

            case SequenceType.Transaction:
                PrintSequenceTransaction((SequenceTransaction)seq, parent, context);
                break;

            case SequenceType.Backtrack:
                PrintSequenceBacktrack((SequenceBacktrack)seq, parent, context);
                break;

            case SequenceType.MultiBacktrack:
                PrintSequenceMultiBacktrack((SequenceMultiBacktrack)seq, parent, context);
                break;

            case SequenceType.MultiSequenceBacktrack:
                PrintSequenceMultiSequenceBacktrack((SequenceMultiSequenceBacktrack)seq, parent, context);
                break;

            case SequenceType.Pause:
                PrintSequencePause((SequencePause)seq, parent, context);
                break;

            case SequenceType.ForContainer:
                PrintSequenceForContainer((SequenceForContainer)seq, parent, context);
                break;

            case SequenceType.ForIntegerRange:
                PrintSequenceForIntegerRange((SequenceForIntegerRange)seq, parent, context);
                break;

            case SequenceType.ForIndexAccessEquality:
                PrintSequenceForIndexAccessEquality((SequenceForIndexAccessEquality)seq, parent, context);
                break;

            case SequenceType.ForIndexAccessOrdering:
                PrintSequenceForIndexAccessOrdering((SequenceForIndexAccessOrdering)seq, parent, context);
                break;

            case SequenceType.ForAdjacentNodes:
            case SequenceType.ForAdjacentNodesViaIncoming:
            case SequenceType.ForAdjacentNodesViaOutgoing:
            case SequenceType.ForIncidentEdges:
            case SequenceType.ForIncomingEdges:
            case SequenceType.ForOutgoingEdges:
            case SequenceType.ForReachableNodes:
            case SequenceType.ForReachableNodesViaIncoming:
            case SequenceType.ForReachableNodesViaOutgoing:
            case SequenceType.ForReachableEdges:
            case SequenceType.ForReachableEdgesViaIncoming:
            case SequenceType.ForReachableEdgesViaOutgoing:
            case SequenceType.ForBoundedReachableNodes:
            case SequenceType.ForBoundedReachableNodesViaIncoming:
            case SequenceType.ForBoundedReachableNodesViaOutgoing:
            case SequenceType.ForBoundedReachableEdges:
            case SequenceType.ForBoundedReachableEdgesViaIncoming:
            case SequenceType.ForBoundedReachableEdgesViaOutgoing:
            case SequenceType.ForNodes:
            case SequenceType.ForEdges:
                PrintSequenceForFunction((SequenceForFunction)seq, parent, context);
                break;

            case SequenceType.ForMatch:
                PrintSequenceForMatch((SequenceForMatch)seq, parent, context);
                break;

            case SequenceType.ExecuteInSubgraph:
                PrintSequenceExecuteInSubgraph((SequenceExecuteInSubgraph)seq, parent, context);
                break;

            case SequenceType.IfThenElse:
                PrintSequenceIfThenElse((SequenceIfThenElse)seq, parent, context);
                break;

            case SequenceType.LazyOrAll:
            case SequenceType.LazyAndAll:
            case SequenceType.StrictOrAll:
            case SequenceType.StrictAndAll:
                PrintSequenceNAry((SequenceNAry)seq, parent, context);
                break;

            case SequenceType.WeightedOne:
                PrintSequenceWeightedOne((SequenceWeightedOne)seq, parent, context);
                break;

            case SequenceType.SomeFromSet:
                PrintSequenceSomeFromSet((SequenceSomeFromSet)seq, parent, context);
                break;

            case SequenceType.MultiRulePrefixedSequence:
                PrintSequenceMultiRulePrefixedSequence((SequenceMultiRulePrefixedSequence)seq, parent, context);
                break;

            case SequenceType.MultiRuleAllCall:
                PrintSequenceMultiRuleAllCall((SequenceMultiRuleAllCall)seq, parent, context);
                break;

            case SequenceType.RulePrefixedSequence:
                PrintSequenceRulePrefixedSequence((SequenceRulePrefixedSequence)seq, parent, context);
                break;

            case SequenceType.SequenceCall:
            case SequenceType.RuleCall:
            case SequenceType.RuleAllCall:
            case SequenceType.RuleCountAllCall:
            case SequenceType.BooleanComputation:
                PrintSequenceBreakpointable((Sequence)seq, parent, context);
                break;

            case SequenceType.AssignSequenceResultToVar:
            case SequenceType.OrAssignSequenceResultToVar:
            case SequenceType.AndAssignSequenceResultToVar:
                PrintSequenceAssignSequenceResultToVar((SequenceAssignSequenceResultToVar)seq, parent, context);
                break;

            case SequenceType.AssignUserInputToVar:
            case SequenceType.AssignRandomIntToVar:
            case SequenceType.AssignRandomDoubleToVar:
                PrintSequenceAssignChoiceHighlightable((Sequence)seq, parent, context);
                break;

            case SequenceType.SequenceDefinitionInterpreted:
                PrintSequenceDefinitionInterpreted((SequenceDefinitionInterpreted)seq, parent, context);
                break;

            // Atoms (assignments)
            case SequenceType.AssignVarToVar:
            case SequenceType.AssignConstToVar:
            case SequenceType.AssignContainerConstructorToVar:
            case SequenceType.DeclareVariable:
                Console.Write(seq.Symbol);
                break;

            default:
                Debug.Assert(false);
                Console.Write("<UNKNOWN_SEQUENCE_TYPE>");
                break;
            }

            // print parentheses, if neccessary
            if (parent != null && seq.Precedence < parent.Precedence)
            {
                Console.Write(")");
            }
        }
 private static void PrintSequenceForIndexAccessEquality(SequenceForIndexAccessEquality seqFor, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("for{");
     Console.Write(seqFor.Var.Name);
     Console.Write(" in {");
     Console.Write(seqFor.IndexName);
     Console.Write("==");
     Console.Write(seqFor.Expr.Symbol);
     Console.Write("}; ");
     PrintSequence(seqFor.Seq, seqFor, context);
     Console.Write("}");
 }
Exemple #16
0
 /// <summary>
 /// Called from shell after an debugging abort highlighting the lastly executed rule
 /// </summary>
 public static void PrintSequence(Sequence seq, Sequence highlight, IWorkaround workaround)
 {
     PrintSequenceContext context = new PrintSequenceContext(workaround);
     context.highlightSeq = highlight;
     PrintSequence(seq, context, 0);
     // TODO: what to do if abort came within sequence called from top sequence?
 }
Exemple #17
0
        void HandleToggleChoicepoints()
        {
            Console.Write("Available choicepoint positions:\n  ");

            PrintSequenceContext contextCp = new PrintSequenceContext(grShellImpl.Workaround);
            contextCp.cpPosCounter = 0;
            PrintSequence(debugSequences.Peek(), contextCp, debugSequences.Count);
            Console.WriteLine();

            if (contextCp.cpPosCounter == 0)
            {
                Console.WriteLine("No choicepoint positions available!");
                return;
            }

            int pos = HandleTogglePoint("choicepoint", contextCp.cpPosCounter);
            if (pos == -1)
                return;

            TogglePointInAllInstances(pos, true);
        }
Exemple #18
0
 static void PrintChildren(Sequence seq, PrintSequenceContext context)
 {
     bool first = true;
     foreach(Sequence seqChild in seq.Children)
     {
         if(!first) Console.Write(", ");
         PrintSequence(seqChild, seq, context);
         first = false;
     }
 }
Exemple #19
0
 static void PrintBreak(SequenceSpecial seq, PrintSequenceContext context)
 {
     if(seq.Special)
         context.workaround.PrintHighlighted("-%" + context.bpPosCounter + "-:", HighlightingMode.Breakpoint);
     else
         context.workaround.PrintHighlighted("+%" + context.bpPosCounter + "+:", HighlightingMode.Breakpoint);
 }
        private static void PrintSequenceWeightedOne(SequenceWeightedOne seqWeighted, Sequence parent, PrintSequenceContext context)
        {
            if (context.cpPosCounter >= 0)
            {
                PrintChoice(seqWeighted, context);
                ++context.cpPosCounter;
                Console.Write((seqWeighted.Choice ? "$%" : "$") + seqWeighted.OperatorSymbol + "(");
                bool first = true;
                for (int i = 0; i < seqWeighted.Sequences.Count; ++i)
                {
                    if (first)
                    {
                        Console.Write("0.00 ");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                    PrintSequence(seqWeighted.Sequences[i], seqWeighted, context);
                    Console.Write(" ");
                    Console.Write(seqWeighted.Numbers[i]); // todo: format auf 2 nachkommastellen
                    first = false;
                }
                Console.Write(")");
                return;
            }

            bool highlight = false;

            foreach (Sequence seqChild in seqWeighted.Children)
            {
                if (seqChild == context.highlightSeq)
                {
                    highlight = true;
                }
            }
            if (highlight && context.choice)
            {
                WorkaroundManager.Workaround.PrintHighlighted("$%" + seqWeighted.OperatorSymbol + "(", HighlightingMode.Choicepoint);
                bool first = true;
                for (int i = 0; i < seqWeighted.Sequences.Count; ++i)
                {
                    if (first)
                    {
                        Console.Write("0.00 ");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                    if (seqWeighted.Sequences[i] == context.highlightSeq)
                    {
                        WorkaroundManager.Workaround.PrintHighlighted(">>", HighlightingMode.Choicepoint);
                    }

                    Sequence highlightSeqBackup = context.highlightSeq;
                    context.highlightSeq = null; // we already highlighted here
                    PrintSequence(seqWeighted.Sequences[i], seqWeighted, context);
                    context.highlightSeq = highlightSeqBackup;

                    if (seqWeighted.Sequences[i] == context.highlightSeq)
                    {
                        WorkaroundManager.Workaround.PrintHighlighted("<<", HighlightingMode.Choicepoint);
                    }
                    Console.Write(" ");
                    Console.Write(seqWeighted.Numbers[i]); // todo: format auf 2 nachkommastellen
                    first = false;
                }
                WorkaroundManager.Workaround.PrintHighlighted(")", HighlightingMode.Choicepoint);
                return;
            }

            Console.Write((seqWeighted.Choice ? "$%" : "$") + seqWeighted.OperatorSymbol + "(");
            bool ffs = true;

            for (int i = 0; i < seqWeighted.Sequences.Count; ++i)
            {
                if (ffs)
                {
                    Console.Write("0.00 ");
                }
                else
                {
                    Console.Write(" ");
                }
                PrintSequence(seqWeighted.Sequences[i], seqWeighted, context);
                Console.Write(" ");
                Console.Write(seqWeighted.Numbers[i]); // todo: format auf 2 nachkommastellen
                ffs = false;
            }
            Console.Write(")");
        }
        private static void PrintSequenceNAry(SequenceNAry seqN, Sequence parent, PrintSequenceContext context)
        {
            if (context.cpPosCounter >= 0)
            {
                PrintChoice(seqN, context);
                ++context.cpPosCounter;
                Console.Write((seqN.Choice ? "$%" : "$") + seqN.OperatorSymbol + "(");
                bool first = true;
                foreach (Sequence seqChild in seqN.Children)
                {
                    if (!first)
                    {
                        Console.Write(", ");
                    }
                    PrintSequence(seqChild, seqN, context);
                    first = false;
                }
                Console.Write(")");
                return;
            }

            bool highlight = false;

            foreach (Sequence seqChild in seqN.Children)
            {
                if (seqChild == context.highlightSeq)
                {
                    highlight = true;
                }
            }
            if (highlight && context.choice)
            {
                WorkaroundManager.Workaround.PrintHighlighted("$%" + seqN.OperatorSymbol + "(", HighlightingMode.Choicepoint);
                bool first = true;
                foreach (Sequence seqChild in seqN.Children)
                {
                    if (!first)
                    {
                        Console.Write(", ");
                    }
                    if (seqChild == context.highlightSeq)
                    {
                        WorkaroundManager.Workaround.PrintHighlighted(">>", HighlightingMode.Choicepoint);
                    }
                    if (context.sequences != null)
                    {
                        for (int i = 0; i < context.sequences.Count; ++i)
                        {
                            if (seqChild == context.sequences[i])
                            {
                                WorkaroundManager.Workaround.PrintHighlighted("(" + i + ")", HighlightingMode.Choicepoint);
                            }
                        }
                    }

                    Sequence highlightSeqBackup = context.highlightSeq;
                    context.highlightSeq = null; // we already highlighted here
                    PrintSequence(seqChild, seqN, context);
                    context.highlightSeq = highlightSeqBackup;

                    if (seqChild == context.highlightSeq)
                    {
                        WorkaroundManager.Workaround.PrintHighlighted("<<", HighlightingMode.Choicepoint);
                    }
                    first = false;
                }
                WorkaroundManager.Workaround.PrintHighlighted(")", HighlightingMode.Choicepoint);
                return;
            }

            Console.Write((seqN.Choice ? "$%" : "$") + seqN.OperatorSymbol + "(");
            PrintChildren(seqN, context);
            Console.Write(")");
        }
        private static void PrintSequenceDefinitionInterpreted(SequenceDefinitionInterpreted seqDef, Sequence parent, PrintSequenceContext context)
        {
            HighlightingMode mode = HighlightingMode.None;

            if (seqDef.ExecutionState == SequenceExecutionState.Success)
            {
                mode = HighlightingMode.LastSuccess;
            }
            if (seqDef.ExecutionState == SequenceExecutionState.Fail)
            {
                mode = HighlightingMode.LastFail;
            }
            WorkaroundManager.Workaround.PrintHighlighted(seqDef.Symbol + ": ", mode);
            PrintSequence(seqDef.Seq, seqDef.Seq, context);
        }
        private static void PrintSequenceSomeFromSet(SequenceSomeFromSet seqSome, Sequence parent, PrintSequenceContext context)
        {
            if (context.cpPosCounter >= 0 &&
                seqSome.Random)
            {
                PrintChoice(seqSome, context);
                ++context.cpPosCounter;
                Console.Write(seqSome.Choice ? "$%{<" : "${<");
                bool first = true;
                foreach (Sequence seqChild in seqSome.Children)
                {
                    if (!first)
                    {
                        Console.Write(", ");
                    }
                    int cpPosCounterBackup = context.cpPosCounter;
                    context.cpPosCounter = -1; // rules within some-from-set are not choicepointable
                    PrintSequence(seqChild, seqSome, context);
                    context.cpPosCounter = cpPosCounterBackup;
                    first = false;
                }
                Console.Write(")}");
                return;
            }

            bool highlight = false;

            foreach (Sequence seqChild in seqSome.Children)
            {
                if (seqChild == context.highlightSeq)
                {
                    highlight = true;
                }
            }
            if (highlight && context.choice)
            {
                WorkaroundManager.Workaround.PrintHighlighted("$%{<", HighlightingMode.Choicepoint);
                bool first            = true;
                int  numCurTotalMatch = 0;
                foreach (Sequence seqChild in seqSome.Children)
                {
                    if (!first)
                    {
                        Console.Write(", ");
                    }
                    if (seqChild == context.highlightSeq)
                    {
                        WorkaroundManager.Workaround.PrintHighlighted(">>", HighlightingMode.Choicepoint);
                    }
                    if (context.sequences != null)
                    {
                        for (int i = 0; i < context.sequences.Count; ++i)
                        {
                            if (seqChild == context.sequences[i] && context.matches[i].Count > 0)
                            {
                                PrintListOfMatchesNumbers(context, ref numCurTotalMatch, seqSome.IsNonRandomRuleAllCall(i) ? 1 : context.matches[i].Count);
                            }
                        }
                    }

                    Sequence highlightSeqBackup = context.highlightSeq;
                    context.highlightSeq = null; // we already highlighted here
                    PrintSequence(seqChild, seqSome, context);
                    context.highlightSeq = highlightSeqBackup;

                    if (seqChild == context.highlightSeq)
                    {
                        WorkaroundManager.Workaround.PrintHighlighted("<<", HighlightingMode.Choicepoint);
                    }
                    first = false;
                }
                WorkaroundManager.Workaround.PrintHighlighted(">}", HighlightingMode.Choicepoint);
                return;
            }

            bool succesBackup = context.success;

            if (highlight)
            {
                context.success = true;
            }
            Console.Write(seqSome.Random ? (seqSome.Choice ? "$%{<" : "${<") : "{<");
            PrintChildren(seqSome, context);
            Console.Write(">}");
            context.success = succesBackup;
        }
        // Choice highlightable user assignments
        private static void PrintSequenceAssignChoiceHighlightable(Sequence seq, Sequence parent, PrintSequenceContext context)
        {
            if (context.cpPosCounter >= 0 &&
                (seq is SequenceAssignRandomIntToVar || seq is SequenceAssignRandomDoubleToVar))
            {
                PrintChoice((SequenceRandomChoice)seq, context);
                Console.Write(seq.Symbol);
                ++context.cpPosCounter;
                return;
            }

            if (seq == context.highlightSeq && context.choice)
            {
                WorkaroundManager.Workaround.PrintHighlighted(seq.Symbol, HighlightingMode.Choicepoint);
            }
            else
            {
                Console.Write(seq.Symbol);
            }
        }
 private static void PrintSequenceAssignSequenceResultToVar(SequenceAssignSequenceResultToVar seqAss, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("(");
     PrintSequence(seqAss.Seq, seqAss, context);
     Console.Write(seqAss.OperatorSymbol);
     Console.Write(seqAss.DestVar.Name);
     Console.Write(")");
 }
        private static void PrintSequenceBreakpointable(Sequence seq, Sequence parent, PrintSequenceContext context)
        {
            if (context.bpPosCounter >= 0)
            {
                PrintBreak((SequenceSpecial)seq, context);
                Console.Write(seq.Symbol);
                ++context.bpPosCounter;
                return;
            }

            if (context.cpPosCounter >= 0 && seq is SequenceRandomChoice &&
                ((SequenceRandomChoice)seq).Random)
            {
                PrintChoice((SequenceRandomChoice)seq, context);
                Console.Write(seq.Symbol);
                ++context.cpPosCounter;
                return;
            }

            HighlightingMode mode = HighlightingMode.None;

            if (seq == context.highlightSeq)
            {
                if (context.choice)
                {
                    mode |= HighlightingMode.Choicepoint;
                }
                else if (context.success)
                {
                    mode |= HighlightingMode.FocusSucces;
                }
                else
                {
                    mode |= HighlightingMode.Focus;
                }
            }
            if (seq.ExecutionState == SequenceExecutionState.Success)
            {
                mode |= HighlightingMode.LastSuccess;
            }
            if (seq.ExecutionState == SequenceExecutionState.Fail)
            {
                mode |= HighlightingMode.LastFail;
            }
            if (context.sequences != null && context.sequences.Contains(seq))
            {
                if (context.matches != null && context.matches[context.sequences.IndexOf(seq)].Count > 0)
                {
                    mode |= HighlightingMode.FocusSucces;
                }
            }
            WorkaroundManager.Workaround.PrintHighlighted(seq.Symbol, mode);
        }
Exemple #27
0
 /// <summary>
 /// Prints the given root sequence adding parentheses if needed according to the print context.
 /// </summary>
 /// <param name="seq">The sequence to be printed</param>
 /// <param name="context">The print context</param>
 /// <param name="nestingLevel">The level the sequence is nested in</param>
 private static void PrintSequence(Sequence seq, PrintSequenceContext context, int nestingLevel)
 {
     context.workaround.PrintHighlighted(nestingLevel + ">", HighlightingMode.SequenceStart);
     PrintSequence(seq, null, context);
 }
 private static void PrintSequenceForIntegerRange(SequenceForIntegerRange seqFor, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("for{");
     Console.Write(seqFor.Var.Name);
     Console.Write(" in [");
     Console.Write(seqFor.Left.Symbol);
     Console.Write(":");
     Console.Write(seqFor.Right.Symbol);
     Console.Write("]; ");
     PrintSequence(seqFor.Seq, seqFor, context);
     Console.Write("}");
 }
Exemple #29
0
        /// <summary>
        /// Prints the given sequence adding parentheses if needed according to the print context.
        /// </summary>
        /// <param name="seq">The sequence to be printed</param>
        /// <param name="parent">The parent of the sequence or null if the sequence is a root</param>
        /// <param name="context">The print context</param>
        private static void PrintSequence(Sequence seq, Sequence parent, PrintSequenceContext context)
        {
            // print parentheses, if neccessary
            if(parent != null && seq.Precedence < parent.Precedence) Console.Write("(");

            switch(seq.SequenceType)
            {
                // Binary
                case SequenceType.ThenLeft:
                case SequenceType.ThenRight:
                case SequenceType.LazyOr:
                case SequenceType.LazyAnd:
                case SequenceType.StrictOr:
                case SequenceType.Xor:
                case SequenceType.StrictAnd:
                    {
                        SequenceBinary seqBin = (SequenceBinary)seq;

                        if(context.cpPosCounter >= 0 && seqBin.Random)
                        {
                            int cpPosCounter = context.cpPosCounter;
                            ++context.cpPosCounter;
                            PrintSequence(seqBin.Left, seq, context);
                            PrintChoice(seqBin, context);
                            Console.Write(seq.Symbol + " ");
                            PrintSequence(seqBin.Right, seq, context);
                            break;
                        }

                        if(seqBin == context.highlightSeq && context.choice)
                        {
                            context.workaround.PrintHighlighted("(l)", HighlightingMode.Choicepoint);
                            PrintSequence(seqBin.Left, seq, context);
                            context.workaround.PrintHighlighted("(l) " + seq.Symbol + " (r)", HighlightingMode.Choicepoint);
                            PrintSequence(seqBin.Right, seq, context);
                            context.workaround.PrintHighlighted("(r)", HighlightingMode.Choicepoint);
                            break;
                        }

                        PrintSequence(seqBin.Left, seq, context);
                        Console.Write(" " + seq.Symbol + " ");
                        PrintSequence(seqBin.Right, seq, context);
                        break;
                    }
                case SequenceType.IfThen:
                    {
                        SequenceIfThen seqIfThen = (SequenceIfThen)seq;
                        Console.Write("if{");
                        PrintSequence(seqIfThen.Left, seq, context);
                        Console.Write(";");
                        PrintSequence(seqIfThen.Right, seq, context);
                        Console.Write("}");
                        break;
                    }

                // Unary
                case SequenceType.Not:
                    {
                        SequenceNot seqNot = (SequenceNot)seq;
                        Console.Write(seq.Symbol);
                        PrintSequence(seqNot.Seq, seq, context);
                        break;
                    }
                case SequenceType.IterationMin:
                    {
                        SequenceIterationMin seqMin = (SequenceIterationMin)seq;
                        PrintSequence(seqMin.Seq, seq, context);
                        Console.Write("[" + seqMin.Min + ":*]");
                        break;
                    }
                case SequenceType.IterationMinMax:
                    {
                        SequenceIterationMinMax seqMinMax = (SequenceIterationMinMax)seq;
                        PrintSequence(seqMinMax.Seq, seq, context);
                        Console.Write("[" + seqMinMax.Min + ":" + seqMinMax.Max + "]");
                        break;
                    }
                case SequenceType.Transaction:
                    {
                        SequenceTransaction seqTrans = (SequenceTransaction)seq;
                        Console.Write("<");
                        PrintSequence(seqTrans.Seq, seq, context);
                        Console.Write(">");
                        break;
                    }
                case SequenceType.Backtrack:
                    {
                        SequenceBacktrack seqBack = (SequenceBacktrack)seq;
                        Console.Write("<<");
                        PrintSequence(seqBack.Rule, seq, context);
                        Console.Write(";;");
                        PrintSequence(seqBack.Seq, seq, context);
                        Console.Write(">>");
                        break;
                    }
                case SequenceType.Pause:
                    {
                        SequencePause seqPause = (SequencePause)seq;
                        Console.Write("/");
                        PrintSequence(seqPause.Seq, seq, context);
                        Console.Write("/");
                        break;
                    }
                case SequenceType.ForContainer:
                    {
                        SequenceForContainer seqFor = (SequenceForContainer)seq;
                        Console.Write("for{");
                        Console.Write(seqFor.Var.Name);
                        if(seqFor.VarDst != null) Console.Write("->" + seqFor.VarDst.Name);
                        Console.Write(" in " + seqFor.Container.Name);
                        Console.Write("; ");
                        PrintSequence(seqFor.Seq, seq, context);
                        Console.Write("}");
                        break;
                    }
                case SequenceType.ForIntegerRange:
                    {
                        SequenceForIntegerRange seqFor = (SequenceForIntegerRange)seq;
                        Console.Write("for{");
                        Console.Write(seqFor.Var.Name);
                        Console.Write(" in [");
                        Console.Write(seqFor.Left.Symbol);
                        Console.Write(":");
                        Console.Write(seqFor.Right.Symbol);
                        Console.Write("]; ");
                        PrintSequence(seqFor.Seq, seq, context);
                        Console.Write("}");
                        break;
                    }
                case SequenceType.ForIndexAccessEquality:
                    {
                        SequenceForIndexAccessEquality seqFor = (SequenceForIndexAccessEquality)seq;
                        Console.Write("for{");
                        Console.Write(seqFor.Var.Name);
                        Console.Write(" in {");
                        Console.Write(seqFor.IndexName);
                        Console.Write("==");
                        Console.Write(seqFor.Expr.Symbol);
                        Console.Write("}; ");
                        PrintSequence(seqFor.Seq, seq, context);
                        Console.Write("}");
                        break;
                    }
                case SequenceType.ForIndexAccessOrdering:
                    {
                        SequenceForIndexAccessOrdering seqFor = (SequenceForIndexAccessOrdering)seq;
                        Console.Write("for{");
                        Console.Write(seqFor.Var.Name);
                        Console.Write(" in {");
                        if(seqFor.Ascending)
                            Console.Write("ascending");
                        else
                            Console.Write("descending");
                        Console.Write("(");
                        if(seqFor.From() != null && seqFor.To() != null)
                        {
                            Console.Write(seqFor.IndexName);
                            Console.Write(seqFor.DirectionAsString(seqFor.Direction));
                            Console.Write(seqFor.Expr.Symbol);
                            Console.Write(",");
                            Console.Write(seqFor.IndexName);
                            Console.Write(seqFor.DirectionAsString(seqFor.Direction2));
                            Console.Write(seqFor.Expr2.Symbol);
                        }
                        else if(seqFor.From() != null)
                        {
                            Console.Write(seqFor.IndexName);
                            Console.Write(seqFor.DirectionAsString(seqFor.Direction));
                            Console.Write(seqFor.Expr.Symbol);
                        }
                        else if(seqFor.To() != null)
                        {
                            Console.Write(seqFor.IndexName);
                            Console.Write(seqFor.DirectionAsString(seqFor.Direction));
                            Console.Write(seqFor.Expr.Symbol);
                        }
                        else
                        {
                            Console.Write(seqFor.IndexName);
                        }
                        Console.Write(")");
                        Console.Write("}; ");
                        PrintSequence(seqFor.Seq, seq, context);
                        Console.Write("}");
                        break;
                    }
                case SequenceType.ForAdjacentNodes:
                case SequenceType.ForAdjacentNodesViaIncoming:
                case SequenceType.ForAdjacentNodesViaOutgoing:
                case SequenceType.ForIncidentEdges:
                case SequenceType.ForIncomingEdges:
                case SequenceType.ForOutgoingEdges:
                case SequenceType.ForReachableNodes:
                case SequenceType.ForReachableNodesViaIncoming:
                case SequenceType.ForReachableNodesViaOutgoing:
                case SequenceType.ForReachableEdges:
                case SequenceType.ForReachableEdgesViaIncoming:
                case SequenceType.ForReachableEdgesViaOutgoing:
                case SequenceType.ForBoundedReachableNodes:
                case SequenceType.ForBoundedReachableNodesViaIncoming:
                case SequenceType.ForBoundedReachableNodesViaOutgoing:
                case SequenceType.ForBoundedReachableEdges:
                case SequenceType.ForBoundedReachableEdgesViaIncoming:
                case SequenceType.ForBoundedReachableEdgesViaOutgoing:
                case SequenceType.ForNodes:
                case SequenceType.ForEdges:
                    {
                        SequenceForFunction seqFor = (SequenceForFunction)seq;
                        Console.Write("for{");
                        Console.Write(seqFor.Var.Name);
                        Console.Write(" in ");
                        Console.Write(seqFor.FunctionSymbol + ";");
                        PrintSequence(seqFor.Seq, seq, context);
                        Console.Write("}");
                        break;
                    }
                case SequenceType.ForMatch:
                    {
                        SequenceForMatch seqFor = (SequenceForMatch)seq;
                        Console.Write("for{");
                        Console.Write(seqFor.Var.Name);
                        Console.Write(" in [?");
                        PrintSequence(seqFor.Rule, seq, context);
                        Console.Write("]; ");
                        PrintSequence(seqFor.Seq, seq, context);
                        Console.Write("}");
                        break;
                    }
                case SequenceType.ExecuteInSubgraph:
                    {
                        SequenceExecuteInSubgraph seqExecInSub = (SequenceExecuteInSubgraph)seq;
                        Console.Write("in ");
                        Console.Write(seqExecInSub.SubgraphVar.Name);
                        if(seqExecInSub.AttributeName != null)
                            Console.Write("." + seqExecInSub.AttributeName);
                        Console.Write(" {");
                        PrintSequence(seqExecInSub.Seq, seq, context);
                        Console.Write("}");
                        break;
                    }

                // Ternary
                case SequenceType.IfThenElse:
                    {
                        SequenceIfThenElse seqIf = (SequenceIfThenElse)seq;
                        Console.Write("if{");
                        PrintSequence(seqIf.Condition, seq, context);
                        Console.Write(";");
                        PrintSequence(seqIf.TrueCase, seq, context);
                        Console.Write(";");
                        PrintSequence(seqIf.FalseCase, seq, context);
                        Console.Write("}");
                        break;
                    }

                // n-ary
                case SequenceType.LazyOrAll:
                case SequenceType.LazyAndAll:
                case SequenceType.StrictOrAll:
                case SequenceType.StrictAndAll:
                    {
                        SequenceNAry seqN = (SequenceNAry)seq;

                        if(context.cpPosCounter >= 0)
                        {
                            PrintChoice(seqN, context);
                            ++context.cpPosCounter;
                            Console.Write((seqN.Choice ? "$%" : "$") + seqN.Symbol + "(");
                            bool first = true;
                            foreach(Sequence seqChild in seqN.Children)
                            {
                                if(!first) Console.Write(", ");
                                PrintSequence(seqChild, seqN, context);
                                first = false;
                            }
                            Console.Write(")");
                            break;
                        }

                        bool highlight = false;
                        foreach(Sequence seqChild in seqN.Children)
                            if(seqChild == context.highlightSeq)
                                highlight = true;
                        if(highlight && context.choice)
                        {
                            context.workaround.PrintHighlighted("$%" + seqN.Symbol + "(", HighlightingMode.Choicepoint);
                            bool first = true;
                            foreach(Sequence seqChild in seqN.Children)
                            {
                                if(!first) Console.Write(", ");
                                if(seqChild == context.highlightSeq)
                                    context.workaround.PrintHighlighted(">>", HighlightingMode.Choicepoint);
                                if(context.sequences != null)
                                {
                                    for(int i = 0; i < context.sequences.Count; ++i)
                                    {
                                        if(seqChild == context.sequences[i])
                                            context.workaround.PrintHighlighted("(" + i + ")", HighlightingMode.Choicepoint);
                                    }
                                }

                                Sequence highlightSeqBackup = context.highlightSeq;
                                context.highlightSeq = null; // we already highlighted here
                                PrintSequence(seqChild, seqN, context);
                                context.highlightSeq = highlightSeqBackup;

                                if(seqChild == context.highlightSeq)
                                    context.workaround.PrintHighlighted("<<", HighlightingMode.Choicepoint);
                                first = false;
                            }
                            context.workaround.PrintHighlighted(")", HighlightingMode.Choicepoint);
                            break;
                        }

                        Console.Write((seqN.Choice ? "$%" : "$") + seqN.Symbol + "(");
                        PrintChildren(seqN, context);
                        Console.Write(")");
                        break;
                    }

                case SequenceType.WeightedOne:
                    {
                        SequenceWeightedOne seqWeighted = (SequenceWeightedOne)seq;

                        if(context.cpPosCounter >= 0)
                        {
                            PrintChoice(seqWeighted, context);
                            ++context.cpPosCounter;
                            Console.Write((seqWeighted.Choice ? "$%" : "$") + seqWeighted.Symbol + "(");
                            bool first = true;
                            for(int i = 0; i < seqWeighted.Sequences.Count; ++i)
                            {
                                if(first) Console.Write("0.00 ");
                                else Console.Write(" ");
                                PrintSequence(seqWeighted.Sequences[i], seqWeighted, context);
                                Console.Write(" ");
                                Console.Write(seqWeighted.Numbers[i]); // todo: format auf 2 nachkommastellen 
                                first = false;
                            }
                            Console.Write(")");
                            break;
                        }

                        bool highlight = false;
                        foreach(Sequence seqChild in seqWeighted.Children)
                            if(seqChild == context.highlightSeq)
                                highlight = true;
                        if(highlight && context.choice)
                        {
                            context.workaround.PrintHighlighted("$%" + seqWeighted.Symbol + "(", HighlightingMode.Choicepoint);
                            bool first = true;
                            for(int i = 0; i < seqWeighted.Sequences.Count; ++i)
                            {
                                if(first) Console.Write("0.00 ");
                                else Console.Write(" ");
                                if(seqWeighted.Sequences[i] == context.highlightSeq)
                                    context.workaround.PrintHighlighted(">>", HighlightingMode.Choicepoint);

                                Sequence highlightSeqBackup = context.highlightSeq;
                                context.highlightSeq = null; // we already highlighted here
                                PrintSequence(seqWeighted.Sequences[i], seqWeighted, context);
                                context.highlightSeq = highlightSeqBackup;

                                if(seqWeighted.Sequences[i] == context.highlightSeq)
                                    context.workaround.PrintHighlighted("<<", HighlightingMode.Choicepoint);
                                Console.Write(" ");
                                Console.Write(seqWeighted.Numbers[i]); // todo: format auf 2 nachkommastellen 
                                first = false;
                            }
                            context.workaround.PrintHighlighted(")", HighlightingMode.Choicepoint);
                            break;
                        }

                        Console.Write((seqWeighted.Choice ? "$%" : "$") + seqWeighted.Symbol + "(");
                        bool ffs = true;
                        for(int i = 0; i < seqWeighted.Sequences.Count; ++i)
                        {
                            if(ffs) Console.Write("0.00 ");
                            else Console.Write(" ");
                            PrintSequence(seqWeighted.Sequences[i], seqWeighted, context);
                            Console.Write(" ");
                            Console.Write(seqWeighted.Numbers[i]); // todo: format auf 2 nachkommastellen 
                            ffs = false;
                        }
                        Console.Write(")");
                        break;
                    }

                case SequenceType.SomeFromSet:
                    {
                        SequenceSomeFromSet seqSome = (SequenceSomeFromSet)seq;

                        if(context.cpPosCounter >= 0
                            && seqSome.Random)
                        {
                            PrintChoice(seqSome, context);
                            ++context.cpPosCounter;
                            Console.Write(seqSome.Choice ? "$%{<" : "${<");
                            bool first = true;
                            foreach(Sequence seqChild in seqSome.Children)
                            {
                                if(!first) Console.Write(", ");
                                int cpPosCounterBackup = context.cpPosCounter;
                                context.cpPosCounter = -1; // rules within some-from-set are not choicepointable
                                PrintSequence(seqChild, seqSome, context);
                                context.cpPosCounter = cpPosCounterBackup;
                                first = false;
                            }
                            Console.Write(")}");
                            break;
                        }

                        bool highlight = false;
                        foreach(Sequence seqChild in seqSome.Children)
                            if(seqChild == context.highlightSeq)
                                highlight = true;

                        if(highlight && context.choice)
                        {
                            context.workaround.PrintHighlighted("$%{<", HighlightingMode.Choicepoint);
                            bool first = true;
                            int numCurTotalMatch = 0;
                            foreach(Sequence seqChild in seqSome.Children)
                            {
                                if(!first) Console.Write(", ");
                                if(seqChild == context.highlightSeq)
                                    context.workaround.PrintHighlighted(">>", HighlightingMode.Choicepoint);
                                if(context.sequences != null)
                                {
                                    for(int i = 0; i < context.sequences.Count; ++i)
                                    {
                                        if(seqChild == context.sequences[i] && context.matches[i].Count > 0)
                                        {
                                            PrintListOfMatchesNumbers(context, ref numCurTotalMatch, context.matches[i].Count);
                                        }
                                    }
                                }

                                Sequence highlightSeqBackup = context.highlightSeq;
                                context.highlightSeq = null; // we already highlighted here
                                PrintSequence(seqChild, seqSome, context);
                                context.highlightSeq = highlightSeqBackup;

                                if(seqChild == context.highlightSeq)
                                    context.workaround.PrintHighlighted("<<", HighlightingMode.Choicepoint);
                                first = false;
                            }
                            context.workaround.PrintHighlighted(">}", HighlightingMode.Choicepoint);
                            break;
                        }

                        bool succesBackup = context.success;
                        if(highlight) context.success = true;
                        Console.Write(seqSome.Random ? (seqSome.Choice ? "$%{<" : "${<") : "{<");
                        PrintChildren(seqSome, context);
                        Console.Write(">}");
                        context.success = succesBackup;
                        break;
                    }

                // Breakpointable atoms
                case SequenceType.SequenceCall:
                case SequenceType.RuleCall:
                case SequenceType.RuleAllCall:
                case SequenceType.RuleCountAllCall:
                case SequenceType.BooleanComputation:
                    {
                        if(context.bpPosCounter >= 0)
                        {
                            PrintBreak((SequenceSpecial)seq, context);
                            Console.Write(seq.Symbol);
                            ++context.bpPosCounter;
                            break;
                        }

                        if(context.cpPosCounter >= 0 && seq is SequenceRandomChoice
                            && ((SequenceRandomChoice)seq).Random)
                        {
                            PrintChoice((SequenceRandomChoice)seq, context);
                            Console.Write(seq.Symbol);
                            ++context.cpPosCounter;
                            break;
                        }

                        HighlightingMode mode = HighlightingMode.None;
                        if(seq == context.highlightSeq)
                        {
                            if(context.choice) mode |= HighlightingMode.Choicepoint;
                            else if(context.success) mode |= HighlightingMode.FocusSucces;
                            else mode |= HighlightingMode.Focus;
                        }
                        if(seq.ExecutionState == SequenceExecutionState.Success) mode |= HighlightingMode.LastSuccess;
                        if(seq.ExecutionState == SequenceExecutionState.Fail) mode |= HighlightingMode.LastFail;
                        if(context.sequences != null && context.sequences.Contains(seq))
                        {
                            if(context.matches != null && context.matches[context.sequences.IndexOf(seq)].Count > 0)
                                mode |= HighlightingMode.FocusSucces;
                        }
                        context.workaround.PrintHighlighted(seq.Symbol, mode);
                        break;
                    }

                // Unary assignment
                case SequenceType.AssignSequenceResultToVar:
                case SequenceType.OrAssignSequenceResultToVar:
                case SequenceType.AndAssignSequenceResultToVar:
                    {
                        SequenceAssignSequenceResultToVar seqAss = (SequenceAssignSequenceResultToVar)seq;
                        Console.Write("(");
                        PrintSequence(seqAss.Seq, seq, context);
                        if(seq.SequenceType == SequenceType.OrAssignSequenceResultToVar)
                            Console.Write("|>");
                        else if(seq.SequenceType == SequenceType.AndAssignSequenceResultToVar)
                            Console.Write("&>");
                        else //if(seq.SequenceType==SequenceType.AssignSequenceResultToVar)
                            Console.Write("=>");
                        Console.Write(seqAss.DestVar.Name);
                        Console.Write(")");
                        break;
                    }

                // Choice highlightable user assignments
                case SequenceType.AssignUserInputToVar:
                case SequenceType.AssignRandomIntToVar:
                case SequenceType.AssignRandomDoubleToVar:
                    {
                        if(context.cpPosCounter >= 0 
                            && (seq is SequenceAssignRandomIntToVar || seq is SequenceAssignRandomDoubleToVar))
                        {
                            PrintChoice((SequenceRandomChoice)seq, context);
                            Console.Write(seq.Symbol);
                            ++context.cpPosCounter;
                            break;
                        }

                        if(seq == context.highlightSeq && context.choice)
                            context.workaround.PrintHighlighted(seq.Symbol, HighlightingMode.Choicepoint);
                        else
                            Console.Write(seq.Symbol);
                        break;
                    }

                case SequenceType.SequenceDefinitionInterpreted:
                    {
                        SequenceDefinitionInterpreted seqDef = (SequenceDefinitionInterpreted)seq;
                        HighlightingMode mode = HighlightingMode.None;
                        if(seqDef.ExecutionState == SequenceExecutionState.Success) mode = HighlightingMode.LastSuccess;
                        if(seqDef.ExecutionState == SequenceExecutionState.Fail) mode = HighlightingMode.LastFail;
                        context.workaround.PrintHighlighted(seqDef.Symbol + ": ", mode);
                        PrintSequence(seqDef.Seq, seqDef.Seq, context);
                        break;
                    }

                // Atoms (assignments)
                case SequenceType.AssignVarToVar:
                case SequenceType.AssignConstToVar:
                case SequenceType.AssignContainerConstructorToVar:
                case SequenceType.DeclareVariable:
                    {
                        Console.Write(seq.Symbol);
                        break;
                    }

                default:
                    {
                        Debug.Assert(false);
                        Console.Write("<UNKNOWN_SEQUENCE_TYPE>");
                        break;
                    }
            }

            // print parentheses, if neccessary
            if(parent != null && seq.Precedence < parent.Precedence) Console.Write(")");
        }
 private static void PrintSequenceIfThenElse(SequenceIfThenElse seqIf, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("if{");
     PrintSequence(seqIf.Condition, seqIf, context);
     Console.Write(";");
     PrintSequence(seqIf.TrueCase, seqIf, context);
     Console.Write(";");
     PrintSequence(seqIf.FalseCase, seqIf, context);
     Console.Write("}");
 }
Exemple #31
0
 static void PrintChoice(SequenceRandomChoice seq, PrintSequenceContext context)
 {
     if(seq.Choice)
         context.workaround.PrintHighlighted("-%" + context.cpPosCounter + "-:", HighlightingMode.Choicepoint);
     else
         context.workaround.PrintHighlighted("+%" + context.cpPosCounter + "+:", HighlightingMode.Choicepoint);
 }
 private static void PrintSequenceExecuteInSubgraph(SequenceExecuteInSubgraph seqExecInSub, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("in ");
     Console.Write(seqExecInSub.SubgraphVar.Name);
     if (seqExecInSub.AttributeName != null)
     {
         Console.Write("." + seqExecInSub.AttributeName);
     }
     Console.Write(" {");
     PrintSequence(seqExecInSub.Seq, seqExecInSub, context);
     Console.Write("}");
 }
Exemple #33
0
 static void PrintListOfMatchesNumbers(PrintSequenceContext context, ref int numCurTotalMatch, int numMatches)
 {
     context.workaround.PrintHighlighted("(", HighlightingMode.Choicepoint);
     bool first = true;
     for(int i = 0; i < numMatches; ++i)
     {
         if(!first) context.workaround.PrintHighlighted(",", HighlightingMode.Choicepoint);
         context.workaround.PrintHighlighted(numCurTotalMatch.ToString(), HighlightingMode.Choicepoint);
         ++numCurTotalMatch;
         first = false;
     }
     context.workaround.PrintHighlighted(")", HighlightingMode.Choicepoint);
 }
 private static void PrintSequenceForMatch(SequenceForMatch seqFor, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("for{");
     Console.Write(seqFor.Var.Name);
     Console.Write(" in [?");
     PrintSequence(seqFor.Rule, seqFor, context);
     Console.Write("]; ");
     PrintSequence(seqFor.Seq, seqFor, context);
     Console.Write("}");
 }
Exemple #35
0
        void HandleToggleBreakpoints()
        {
            Console.Write("Available breakpoint positions:\n  ");

            PrintSequenceContext contextBp = new PrintSequenceContext(grShellImpl.Workaround);
            contextBp.bpPosCounter = 0;
            PrintSequence(debugSequences.Peek(), contextBp, debugSequences.Count);
            Console.WriteLine();

            if(contextBp.bpPosCounter == 0)
            {
                Console.WriteLine("No breakpoint positions available!");
                return;
            }

            int pos = HandleTogglePoint("breakpoint", contextBp.bpPosCounter);
            if (pos == -1)
                return;

            TogglePointInAllInstances(pos, false);
        }
Exemple #36
0
        /// <summary>
        /// Initializes a new Debugger instance using the given layout and options.
        /// Any invalid options will be removed from layoutOptions.
        /// </summary>
        /// <param name="grShellImpl">An GrShellImpl instance.</param>
        /// <param name="debugLayout">The name of the layout to be used.</param>
        /// <param name="layoutOptions">An dictionary mapping layout option names to their values.
        /// It may be null, if no options are to be applied.</param>
        public Debugger(GrShellImpl grShellImpl, String debugLayout, Dictionary<String, String> layoutOptions)
        {
            this.grShellImpl = grShellImpl;
            this.shellProcEnv = grShellImpl.CurrentShellProcEnv;
            this.realizers = grShellImpl.realizers;

            this.context = new PrintSequenceContext(grShellImpl.Workaround);

            int ycompPort = GetFreeTCPPort();
            if(ycompPort < 0)
            {
                throw new Exception("Didn't find a free TCP port in the range 4242-4251!");
            }
            try
            {
                viewerProcess = Process.Start(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
                    + Path.DirectorySeparatorChar + "ycomp", "--nomaximize -p " + ycompPort);
            }
            catch(Exception e)
            {
                throw new Exception("Unable to start yComp: " + e.ToString());
            }

            try
            {
                ycompClient = new YCompClient(shellProcEnv.ProcEnv.NamedGraph, debugLayout, 20000, ycompPort, 
                    shellProcEnv.DumpInfo, realizers);
            }
            catch(Exception ex)
            {
                throw new Exception("Unable to connect to yComp at port " + ycompPort + ": " + ex.Message);
            }

            shellProcEnv.ProcEnv.NamedGraph.ReuseOptimization = false;
            NotifyOnConnectionLost = true;

            try
            {
                if(layoutOptions != null)
                {
                    List<String> illegalOptions = null;
                    foreach(KeyValuePair<String, String> option in layoutOptions)
                    {
                        if(!SetLayoutOption(option.Key, option.Value))
                        {
                            if(illegalOptions == null) illegalOptions = new List<String>();
                            illegalOptions.Add(option.Key);
                        }
                    }
                    if(illegalOptions != null)
                    {
                        foreach(String illegalOption in illegalOptions)
                            layoutOptions.Remove(illegalOption);
                    }
                }

                if(!ycompClient.dumpInfo.IsExcludedGraph())
                    UploadGraph(shellProcEnv.ProcEnv.NamedGraph);
            }
            catch(OperationCanceledException)
            {
                throw new Exception("Connection to yComp lost");
            }

            NotifyOnConnectionLost = false;
            RegisterLibGrEvents(shellProcEnv.ProcEnv.NamedGraph);
        }
 private static void PrintSequenceForFunction(SequenceForFunction seqFor, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("for{");
     Console.Write(seqFor.Var.Name);
     Console.Write(" in ");
     Console.Write(seqFor.FunctionSymbol + ";");
     PrintSequence(seqFor.Seq, seqFor, context);
     Console.Write("}");
 }
Exemple #38
0
 void HandleStackTrace()
 {
     Console.WriteLine("Current sequence call stack is:");
     PrintSequenceContext contextTrace = new PrintSequenceContext(grShellImpl.Workaround);
     Sequence[] callStack = debugSequences.ToArray();
     for(int i = callStack.Length - 1; i >= 0; --i)
     {
         contextTrace.highlightSeq = callStack[i].GetCurrentlyExecutedSequence();
         PrintSequence(callStack[i], contextTrace, callStack.Length - i);
         Console.WriteLine();
     }
     Console.WriteLine("continuing execution with:");
 }
 private static void PrintSequenceForIndexAccessOrdering(SequenceForIndexAccessOrdering seqFor, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("for{");
     Console.Write(seqFor.Var.Name);
     Console.Write(" in {");
     if (seqFor.Ascending)
     {
         Console.Write("ascending");
     }
     else
     {
         Console.Write("descending");
     }
     Console.Write("(");
     if (seqFor.From() != null && seqFor.To() != null)
     {
         Console.Write(seqFor.IndexName);
         Console.Write(seqFor.DirectionAsString(seqFor.Direction));
         Console.Write(seqFor.Expr.Symbol);
         Console.Write(",");
         Console.Write(seqFor.IndexName);
         Console.Write(seqFor.DirectionAsString(seqFor.Direction2));
         Console.Write(seqFor.Expr2.Symbol);
     }
     else if (seqFor.From() != null)
     {
         Console.Write(seqFor.IndexName);
         Console.Write(seqFor.DirectionAsString(seqFor.Direction));
         Console.Write(seqFor.Expr.Symbol);
     }
     else if (seqFor.To() != null)
     {
         Console.Write(seqFor.IndexName);
         Console.Write(seqFor.DirectionAsString(seqFor.Direction));
         Console.Write(seqFor.Expr.Symbol);
     }
     else
     {
         Console.Write(seqFor.IndexName);
     }
     Console.Write(")");
     Console.Write("}; ");
     PrintSequence(seqFor.Seq, seqFor, context);
     Console.Write("}");
 }
Exemple #40
0
 void HandleFullState()
 {
     Console.WriteLine("Current execution state is:");
     PrintVariables(null, null);
     PrintSequenceContext contextTrace = new PrintSequenceContext(grShellImpl.Workaround);
     Sequence[] callStack = debugSequences.ToArray();
     for(int i = callStack.Length - 1; i >= 0; --i)
     {
         Sequence currSeq = callStack[i].GetCurrentlyExecutedSequence();
         contextTrace.highlightSeq = currSeq;
         PrintSequence(callStack[i], contextTrace, callStack.Length - i);
         Console.WriteLine();
         PrintVariables(callStack[i], currSeq != null ? currSeq : callStack[i]);
     }
     PrintVisited();
     Console.WriteLine("continuing execution with:");
 }
 private static void PrintSequenceForContainer(SequenceForContainer seqFor, Sequence parent, PrintSequenceContext context)
 {
     Console.Write("for{");
     Console.Write(seqFor.Var.Name);
     if (seqFor.VarDst != null)
     {
         Console.Write("->" + seqFor.VarDst.Name);
     }
     Console.Write(" in " + seqFor.Container.Name);
     Console.Write("; ");
     PrintSequence(seqFor.Seq, seqFor, context);
     Console.Write("}");
 }
        private static void PrintSequenceMultiRuleAllCall(SequenceMultiRuleAllCall seqMulti, Sequence parent, PrintSequenceContext context)
        {
            bool highlight = false;

            foreach (Sequence seqChild in seqMulti.Children)
            {
                if (seqChild == context.highlightSeq)
                {
                    highlight = true;
                }
            }

            bool succesBackup = context.success;

            if (highlight)
            {
                context.success = true;
            }
            Console.Write("[[");
            PrintChildren(seqMulti, context);
            Console.Write("]]");
            Console.Write(seqMulti.FilterSymbol);
            context.success = succesBackup;
        }