Beispiel #1
0
        Pred BranchToPred(LNode expr, out BranchMode mode, Context ctx)
        {
            if (expr.Calls(_Default, 1) || expr.Calls(_Default2, 1))
            {
                expr = expr.Args[0];
                mode = BranchMode.Default;
            }
            else if (expr.Calls(_Error, 1) || expr.IsIdNamed(_DefaultError))
            {
                mode = (expr.AttrNamed(S.Continue) != null || expr.AttrNamed(GSymbol.Get("continue")) != null)
                                       ? BranchMode.ErrorContinue : BranchMode.ErrorExit;
                if (expr.Calls(_Error, 1))
                {
                    expr = expr.Args[0];
                }
                else
                {
                    return(DefaultErrorBranch.Value);
                }
            }
            else
            {
                mode = BranchMode.None;
            }

            return(NodeToPred(expr, ctx));
        }
Beispiel #2
0
 public BranchInformation(string name, string text, BranchMode mode, LuaFunction condition)
 {
     this.name      = name;
     this.text      = text;
     this.mode      = mode;
     this.condition = condition;
 }
Beispiel #3
0
        /// <summary>
        /// Add a branch to the current node.
        /// The type of the current node will be switched to Branching.
        /// This method is designed to be called externally by scripts.
        /// </summary>
        /// <param name="name">Internal name of the branch, unique in a node</param>
        /// <param name="destination">Name of the destination node</param>
        /// <param name="text">Text on the button to select this branch</param>
        /// <param name="imageInfo"></param>
        /// <param name="mode"></param>
        /// <param name="condition"></param>
        public void RegisterBranch(string name, string destination, string text, BranchImageInformation imageInfo,
                                   BranchMode mode, LuaFunction condition)
        {
            if (string.IsNullOrEmpty(destination))
            {
                throw new ArgumentException(
                          $"Nova: A branch must have a destination. Exception occurs at node: {currentNode.name}, text: {text}");
            }

            if (mode == BranchMode.Normal && condition != null)
            {
                throw new ArgumentException(
                          $"Nova: Branch mode is Normal but condition is not null. Exception occurs at node: {currentNode.name}, destination: {destination}");
            }

            if (mode == BranchMode.Jump && (text != null || imageInfo != null))
            {
                throw new ArgumentException(
                          $"Nova: Branch mode is Jump but text or imageInfo is not null. Exception occurs at node: {currentNode.name}, destination: {destination}");
            }

            if ((mode == BranchMode.Show || mode == BranchMode.Enable) && condition == null)
            {
                throw new ArgumentException(
                          $"Nova: Branch mode is Show or Enable but condition is null. Exception occurs at node: {currentNode.name}, destination: {destination}");
            }

            currentNode.type = FlowChartNodeType.Branching;
            lazyBindingLinks.Add(new LazyBindingEntry(currentNode, destination,
                                                      new BranchInformation(name, text, imageInfo, mode, condition)));
        }
Beispiel #4
0
 public BranchInformation(string name, string text, BranchImageInformation imageInfo, BranchMode mode,
                          LuaFunction condition)
 {
     this.name = name;
     _texts    = new Dictionary <SystemLanguage, string> {
         [I18n.DefaultLocale] = text
     };
     this.imageInfo = imageInfo;
     this.mode      = mode;
     this.condition = condition;
 }
Beispiel #5
0
        public static Symbol ReadBranch(LispReader stream, bool hasTest, BranchMode mode, ref Vector branch)
        {
            var haveFeatures = false;

            if (hasTest)
            {
                var test = stream.Read();
                switch (mode)
                {
                case BranchMode.False:
                {
                    haveFeatures = false;
                    break;
                }

                case BranchMode.True:
                {
                    haveFeatures = true;
                    break;
                }

                case BranchMode.Eval:
                default:
                {
                    haveFeatures = EvalFeatureExpr(test);
                    break;
                }
                }
            }
            else
            {
                haveFeatures = mode == BranchMode.True;
            }

            if (haveFeatures)
            {
                branch = new Vector();
            }

            while (true)
            {
                var obj = haveFeatures ? stream.Read() : stream.ReadSuppressed();

                if (obj == Symbols.HashElif || obj == Symbols.HashElse || obj == Symbols.HashEndif)
                {
                    return((Symbol)obj);
                }
                else if (haveFeatures)
                {
                    branch.Add(obj);
                }
            }
        }
Beispiel #6
0
        public static Pred Or(Pred a, Pred b, bool slashJoined, LNode basis, BranchMode aMode = BranchMode.None, BranchMode bMode = BranchMode.None, IMessageSink sink = null)
        {
            TerminalPred a_ = a as TerminalPred, b_ = b as TerminalPred;

            if (a_ != null && b_ != null && aMode == BranchMode.None && bMode == BranchMode.None)
            {
                return(new TerminalPred(a_.Basis, a_.Set.Union(b_.Set), true));
            }
            else
            {
                return(Alts.Merge(basis, a, b, slashJoined, aMode, bMode, sink));
            }
        }
Beispiel #7
0
        public static Alts Merge(LNode basis, Pred a, Pred b, bool slashJoined, BranchMode aMode, BranchMode bMode, IMessageSink warnings)
        {
            Alts aAlts = a as Alts, bAlts = b as Alts;

            if (aAlts != null && aMode == BranchMode.None)
            {
                return(aAlts.Insert(basis, slashJoined, true, b, bMode, warnings));
            }
            else if (bAlts != null && bMode == BranchMode.None)
            {
                return(bAlts.Insert(basis, slashJoined, false, a, aMode, warnings));
            }
            else
            {
                return(TwoArms(basis, a, b, slashJoined, aMode, bMode, warnings));
            }
        }
Beispiel #8
0
        static Alts OneArm(Pred a, BranchMode aMode)
        {
            var alts = new Alts(a.Basis, LoopMode.None);

            if (aMode == BranchMode.ErrorExit || aMode == BranchMode.ErrorContinue)
            {
                alts.ErrorBranch = a;
                alts.ExitOnError = aMode == BranchMode.ErrorExit;
            }
            else
            {
                alts.Arms.Add(a);
                if (aMode == BranchMode.Default)
                {
                    alts.DefaultArm = 0;
                }
            }
            return(alts);
        }
Beispiel #9
0
 private void InsertSingle(ref int atIndex, Pred b, BranchMode bMode, IMessageSink warnings)
 {
     if (bMode == BranchMode.ErrorExit || bMode == BranchMode.ErrorContinue)
     {
         if (ErrorBranch != null)
         {
             warnings.Error(b, "There is already an error branch.");
         }
         else
         {
             ErrorBranch = b;
             ExitOnError = bMode == BranchMode.ErrorExit;
             if (atIndex < Arms.Count)
             {
                 Warning_ErrorBranchNotLast(ErrorBranch, warnings);
             }
         }
     }
     else
     {
         if (atIndex == Arms.Count && ErrorBranch != null)
         {
             Warning_ErrorBranchNotLast(ErrorBranch, warnings);
         }
         Arms.Insert(atIndex, b);
         if (bMode == BranchMode.Default)
         {
             if (DefaultArm != null)
             {
                 int a = DefaultArm.Value;
                 warnings.Error(b, "There is already a default branch");
             }
             else
             {
                 DefaultArm = atIndex;
             }
         }
         atIndex++;
     }
 }
Beispiel #10
0
 Alts Insert(LNode newBasis, bool slashJoined, bool append, Pred b, BranchMode bMode, IMessageSink warnings)
 {
     if (Mode == LoopMode.None)
     {
         this.Basis = newBasis ?? this.Basis;
         Alts bAlts = b as Alts;
         int  insertAt = append ? this.Arms.Count : 0, boundary = insertAt;
         if (bAlts != null && bMode == BranchMode.None && bAlts.Mode == LoopMode.None)
         {
             for (int i = 0; i < bAlts.Arms.Count; i++)
             {
                 this.InsertSingle(ref insertAt, bAlts.Arms[i], bAlts.DefaultArm == i ? BranchMode.Default : BranchMode.None, warnings);
             }
             if (bAlts.ErrorBranch != null)
             {
                 this.InsertSingle(ref insertAt, bAlts.ErrorBranch, bAlts.ExitOnError ? BranchMode.ErrorExit : BranchMode.ErrorContinue, warnings);
             }
             Debug.Assert(bAlts.DefaultArm != -1);                     // bAlts has no exit branch
         }
         else
         {
             bAlts = null;
             this.InsertSingle(ref insertAt, b, bMode, warnings);
         }
         if (!append)
         {
             boundary = insertAt;
         }
         UpdateSlashDivs(slashJoined, boundary, append, bAlts);
         return(this);
     }
     else
     {
         var copy = OneArm(this, BranchMode.None);
         copy.Insert(newBasis, slashJoined, append, b, bMode, warnings);
         return(copy);
     }
 }
Beispiel #11
0
        static Alts TwoArms(LNode basis, Pred a, Pred b, bool slashJoined, BranchMode aMode, BranchMode bMode, IMessageSink warnings)
        {
            var alts = OneArm(a, aMode);

            return(alts.Insert(basis, slashJoined, true, b, bMode, warnings));
        }
        public static Symbol ReadBranch(LispReader stream, bool hasTest, BranchMode mode, ref Vector branch)
        {
            var haveFeatures = false;

            if (hasTest)
            {
                var test = stream.Read();
                switch (mode)
                {
                    case BranchMode.False:
                        {
                            haveFeatures = false;
                            break;
                        }
                    case BranchMode.True:
                        {
                            haveFeatures = true;
                            break;
                        }
                    case BranchMode.Eval:
                    default:
                        {
                            haveFeatures = EvalFeatureExpr(test);
                            break;
                        }
                }
            }
            else
            {
                haveFeatures = mode == BranchMode.True;
            }

            if (haveFeatures)
            {
                branch = new Vector();
            }

            while (true)
            {
                var obj = haveFeatures ? stream.Read() : stream.ReadSuppressed();

                if (obj == Symbols.HashElif || obj == Symbols.HashElse || obj == Symbols.HashEndif)
                {
                    return (Symbol)obj;
                }
                else if (haveFeatures)
                {
                    branch.Add(obj);
                }
            }
        }
Beispiel #13
0
		Pred BranchToPred(LNode expr, out BranchMode mode, Context ctx)
		{
			if (expr.Calls(_Default, 1) || expr.Calls(_Default2, 1)) {
				expr = expr.Args[0];
				mode = BranchMode.Default;
			} else if (expr.Calls(_Error, 1) || expr.IsIdNamed(_DefaultError)) {
				mode = (expr.AttrNamed(S.Continue) != null || expr.AttrNamed(GSymbol.Get("continue")) != null) 
				       ? BranchMode.ErrorContinue : BranchMode.ErrorExit;
				if (expr.Calls(_Error, 1))
					expr = expr.Args[0];
				else
					return DefaultErrorBranch.Value;
			} else
				mode = BranchMode.None;

			return NodeToPred(expr, ctx);
		}