コード例 #1
0
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Test == null)
            {
                return(Completion.Exception("Test can not be null", this));
            }
            var t = Test.Execute(enviroment);

            if (t.ReturnValue is bool)
            {
                if ((bool)t.ReturnValue)
                {
                    if (Consequent == null)
                    {
                        return(Completion.Exception("Consequent can not be null", this));
                    }
                    return(Consequent.Execute(enviroment));
                }
                else
                {
                    if (Alternate == null)
                    {
                        return(Completion.Exception("Alternate can not be null", this));
                    }
                    return(Alternate.Execute(enviroment));
                }
            }
            else
            {
                return(new Completion("Test return not boolean value", CompletionType.Exception, this));
            }
        }
コード例 #2
0
ファイル: IfStatement.cs プロジェクト: nmezhangxi/WPF-Blocky
        public Completion Execute(ExecutionEnvironment enviroment)
        {
            if (Test == null)
            {
                return(Completion.Void);
            }
            var t = Test.Execute(enviroment);

            if (t.ReturnValue is bool)
            {
                if ((bool)t.ReturnValue)
                {
                    if (Consequent == null)
                    {
                        return(Completion.Void);
                    }
                    ExecutionEnvironment current = new ExecutionEnvironment(enviroment);
                    return(Consequent.Execute(current));
                }
                else
                {
                    if (Alternate == null)
                    {
                        return(Completion.Void);
                    }
                    ExecutionEnvironment current = new ExecutionEnvironment(enviroment);
                    return(Alternate.Execute(current));
                }
            }
            else
            {
                return(new Completion("Test return not boolean value", CompletionType.Exception));
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)
                if (Input != null)
                {
                    hashCode = hashCode * 59 + Input.GetHashCode();
                }

                hashCode = hashCode * 59 + Header.GetHashCode();
                if (Alternate != null)
                {
                    hashCode = hashCode * 59 + Alternate.GetHashCode();
                }
                if (Attributes != null)
                {
                    hashCode = hashCode * 59 + Attributes.GetHashCode();
                }
                if (Omit != null)
                {
                    hashCode = hashCode * 59 + Omit.GetHashCode();
                }
                if (Order != null)
                {
                    hashCode = hashCode * 59 + Order.GetHashCode();
                }
                return(hashCode);
            }
        }
コード例 #4
0
        protected override Completion ExecuteImpl(ExecutionEnvironment enviroment)
        {
            if (Test == null)
            {
                return(Completion.Exception(Properties.Language.TestNullException, this));
            }
            var t = Test.Execute(enviroment);

            if (t.ReturnValue is bool)
            {
                if ((bool)t.ReturnValue)
                {
                    if (Consequent == null)
                    {
                        return(Completion.Exception(Properties.Language.NullException, this));
                    }
                    return(Consequent.Execute(enviroment));
                }
                else
                {
                    if (Alternate == null)
                    {
                        return(Completion.Exception(Properties.Language.NullException, this));
                    }
                    return(Alternate.Execute(enviroment));
                }
            }
            else
            {
                return(Completion.Exception(Properties.Language.NotBoolean, Test));
            }
        }
コード例 #5
0
ファイル: SceneHeader.cs プロジェクト: Ecksters/OcaLib
        /// <summary>
        /// Creates an in-memory model of the scene header
        /// </summary>
        /// <param name="br">Binary reader containing the scene or room file</param>
        /// <param name="seek">offset to the start of the scene header</param>
        public void Load(BinaryReader br, long seek)
        {
            bool KeepReading = true;
            long seekBackTop;

            Offset = seek;

            seekBackTop            = br.BaseStream.Position;
            br.BaseStream.Position = seek;

            while (KeepReading)
            {
                SceneWord command = new SceneWord();
                br.Read(command, 0, 8);

                SetCommand(command, br.BaseStream.Position - 8);
                if ((HeaderCommands)command.Code == HeaderCommands.End)
                {
                    KeepReading = false;
                }
            }
            br.BaseStream.Position = seekBackTop;

            if (HasAlternateHeaders())
            {
                Alternate.HeaderListEndAddress = AltHeaderEnd();
                Alternate.Initialize(br);
            }
        }
コード例 #6
0
ファイル: SceneHeader.cs プロジェクト: Ecksters/OcaLib
        //HACK
        public void SpiritHackSetAlternateHeaders(long cs0, long cs1)
        {
            AlternateHeadersCommand cmd = new AlternateHeadersCommand(Game.OcarinaOfTime);

            cmd.SetCommand(new byte[] { 0x18, 0, 0, 0, /**/ 2, 0, 0, 0 });
            cmds.Add(cmd);

            Alternate.SpiritHack(cs0, cs1);
        }
コード例 #7
0
        public static void test_lazyalternate()
        {
            var context = new Context("aaaaa");
            var chara   = new Character('a');
            var list2a  = new List(new IMatch[] { chara, chara });
            var alt     = new Alternate(new IMatch[] { chara, list2a });
            var lazy    = new Lazy(alt, 1, 2);

            // (a|aa){1,2}?
            ExecTest(context, lazy);
        }
コード例 #8
0
 private void Initial()
 {
     _sequence.Clear();
     _tokenBuffer.Clear();
     _tokens.Clear();
     _exps.Clear();
     _lexer.Reset();
     _group       = new Capture(null, _lexer.AnonymousCapCount);
     _alternate   = new Alternate(_group);
     _concatenate = new Concatenate(_alternate);
 }
コード例 #9
0
        public static void test_repeat()
        {
            var context = new Context("aaaa");
            var chara   = new Character('a');
            var list2a  = new List(new IMatch[] { chara, chara });
            var alt     = new Alternate(new IMatch[] { chara, list2a });
            var rep     = new Repeat(alt, 2);

            // (a|aa){2}
            ExecTest(context, rep);
        }
コード例 #10
0
 public void AppendAlternate(Instruction instruction)
 {
     if (Alternate == null)
     {
         Alternate = instruction;
     }
     else
     {
         Alternate.AppendAlternate(instruction);
     }
 }
コード例 #11
0
 private void PushGroup()
 {
     if (_unit.Type == NodeType.Comment || _unit.Type == NodeType.Field)
     {
         return;
     }
     _group       = _unit as NodeGroup;
     _alternate   = new Alternate(_group);
     _concatenate = new Concatenate(_alternate);
     _unit        = null;
 }
コード例 #12
0
        public static void test_alternate()
        {
            var context = new Context("aaa");
            var chara   = new Character('a');
            var list2a  = new List(new IMatch[] { chara, chara });
            var list3a  = new List(new IMatch[] { chara, chara, chara });
            var alt     = new Alternate(new IMatch[] { chara, list2a, list3a });

            // (a|aa|aaa)
            ExecTest(context, alt);
        }
コード例 #13
0
        public override void Execute(ExecutionContext ctx)
        {
            bool result = new ExpressionEngine().EvaluateConditional(ctx, Content);

            if (result)
            {
                base.Execute(ctx);
            }
            else if (Alternate != null)
            {
                Alternate.Execute(ctx);
            }
        }
コード例 #14
0
        public static void test_atomic()
        {
            var context = new Context("aaaab");
            var chara   = new Character('a');
            var charb   = new Character('b');
            var greedya = new Greedy(chara, 2);
            var atomic  = new Atomic(greedya);
            var alt     = new Alternate(new IMatch[] { chara, charb });
            var list    = new List(new IMatch[] { new CaptureGroup(atomic, 1), alt });

            // (((?>a{2,}))(?:a|b))
            ExecTest(context, list);
        }
コード例 #15
0
        public static void test_greedyaltcapture()
        {
            var context = new Context("aaaaa");
            var chara   = new Character('a');
            var list2a  = new List(new IMatch[] { chara, chara });

            var grp1   = new CaptureGroup(chara, 1);
            var grp2   = new CaptureGroup(list2a, 2);
            var alt    = new Alternate(new IMatch[] { grp1, grp2 });
            var greedy = new Greedy(alt, 1, 2);

            // ((a)|(aa)){1,2}
            ExecTest(context, greedy);
        }
コード例 #16
0
 public override bool IsComplex()
 {
     if (group == null)
     {
         return(Alternate.IsComplex());
     }
     if (TrueExpression != null && TrueExpression.IsComplex())
     {
         return(true);
     }
     if (FalseExpression != null && FalseExpression.IsComplex())
     {
         return(true);
     }
     return(GetFixedWidth() <= 0);
 }
コード例 #17
0
        public static void test_negative_lookbehind()
        {
            var context = new Context("abaab");
            var chara   = new Character('a');
            var charb   = new Character('b');
            var alt     = new Alternate(new IMatch[] { chara, charb });
            var lazy    = new Lazy(alt, 1);

            var backa  = new Character('a', false);
            var back2a = new List(new IMatch[] { backa, backa }, false);
            var assert = new Lookaround(back2a, false);
            var list   = new List(new IMatch[] { lazy, assert });

            // ((?:a|b)+?(?<!aa))
            ExecTest(context, list);
        }
コード例 #18
0
 private void PopGroup()
 {
     _unit = _group;
     // Test Node's exp condition
     if (_unit.Parent.Type == NodeType.Test)
     {
         _group       = _unit.Parent as NodeGroup;
         _alternate   = new Alternate(_group);
         _concatenate = new Concatenate(_alternate);
     }
     else
     {
         _concatenate = _unit.Parent as Concatenate;
         _alternate   = _concatenate.Parent as Alternate;
         _group       = _alternate.Parent as NodeGroup;
     }
 }
コード例 #19
0
        /// <summary>
        /// Returns true if InputJsonConversionHTML instances are equal
        /// </summary>
        /// <param name="other">Instance of InputJsonConversionHTML to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(InputJsonConversionHTML other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Input == other.Input ||
                     Input != null &&
                     Input.Equals(other.Input)
                     ) &&
                 (
                     Header == other.Header ||

                     Header.Equals(other.Header)
                 ) &&
                 (
                     Alternate == other.Alternate ||
                     Alternate != null &&
                     Alternate.Equals(other.Alternate)
                 ) &&
                 (
                     Attributes == other.Attributes ||
                     Attributes != null &&
                     Attributes.Equals(other.Attributes)
                 ) &&
                 (
                     Omit == other.Omit ||
                     Omit != null &&
                     Omit.Equals(other.Omit)
                 ) &&
                 (
                     Order == other.Order ||
                     Order != null &&
                     Order.Equals(other.Order)
                 ));
        }
コード例 #20
0
        public override void Accept(IExecutableObject obj)
        {
            var alt = obj as AlternativeUnit;

            // Assert that obj == null || !InAlternate
            if (alt != null)
            {
                InAlternateState = true;
                Alternate        = alt;
            }
            else
            {
                if (InAlternateState)
                {
                    Alternate.Accept(obj);
                }
                else
                {
                    base.Accept(obj);
                }
            }
        }
コード例 #21
0
        public override void Compile(ICompiler cmp, bool reverse)
        {
            if (group == null)
            {
                Alternate.Compile(cmp, reverse);
                return;
            }

            int     gid  = group.Number;
            LinkRef tail = cmp.NewLink();

            if (FalseExpression == null)
            {
                //    IfDefined :1
                //      <yes_exp>
                // 1: <tail>

                cmp.EmitIfDefined(gid, tail);
                TrueExpression.Compile(cmp, reverse);
            }
            else
            {
                //    IfDefined :1
                //      <yes_expr>
                //      Jump :2
                // 1:   <no_expr>
                // 2: <tail>

                LinkRef false_expr = cmp.NewLink();
                cmp.EmitIfDefined(gid, false_expr);
                TrueExpression.Compile(cmp, reverse);
                cmp.EmitJump(tail);
                cmp.ResolveLink(false_expr);
                FalseExpression.Compile(cmp, reverse);
            }

            cmp.ResolveLink(tail);
        }
コード例 #22
0
ファイル: LoadLevel.cs プロジェクト: FukyVer2/Hero-Cowboy
    public void LoadAllLevelFromFile(string filePath)
    {
        TextAsset[] textAsset = Resources.LoadAll<TextAsset>(filePath);

        if (textAsset != null)
        {
            for (int i = 0; i < textAsset.Length; i++)
            {
                string[] temp = textAsset[i].text.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
                for(int j = 1 ; j < temp.Length ; j++)
                {
                    string[] context = temp[j].Split(new char[] { ';' }, System.StringSplitOptions.RemoveEmptyEntries);
                    Alternate lr = new Alternate(context[1], context[2]);
                    listLevel[i].luot.Add(lr);

                }
            }
        }
        else
        {
            Debug.Log("Chua load dc file : " + filePath);
        }
    }
コード例 #23
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_repeat()
        {
            var context = new Context("aaaa");
            var chara = new Character('a');
            var list2a = new List(new IMatch[] { chara, chara });
            var alt = new Alternate(new IMatch[] { chara, list2a });
            var rep = new Repeat(alt, 2);

            // (a|aa){2}
            ExecTest(context, rep);
        }
コード例 #24
0
        private IElement GenerateElement(Node node, GenerateContext context)
        {
            if (!(node is NodeParent) && node.Type != NodeType.Field)
            {
                Element e = null;
                switch (node.Type)
                {
                case NodeType.Anchor:
                    e = new Element(node as Anchor);
                    break;

                case NodeType.Multi:
                    e = new Element(node as Multi);
                    break;

                case NodeType.One:
                    e = new Element(node as One);
                    break;

                case NodeType.Options:
                    e = new Element(node as Options);
                    break;

                case NodeType.Set:
                    e = new Element(node as Set);
                    break;

                case NodeType.Reference:
                    if ((node as Reference).CapName.Source.Anonymous)
                    {
                        int capnum = context.FindCaptureIndex((node as Reference).CapName.Source);
                        e = new Element(node as Reference, capnum);
                    }
                    else
                    {
                        e = new Element(node as Reference);
                    }
                    break;

                case NodeType.Comment:
                    e = null;
                    break;
                }
                return(e);
            }
            else
            {
                if (node.Type == NodeType.CharClass)
                {
                    return(new Element(node as CharClass));
                }
                else if (node.Type == NodeType.Concatenate)
                {
                    Concatenate conca = node as Concatenate;
                    if (conca.Count == 0)
                    {
                        return(null);
                    }
                    if (conca.Count == 1)
                    {
                        return(GenerateElement(conca[0], context));
                    }

                    ElementParent group = new ElementParent();
                    foreach (Node child in (node as Concatenate).Children)
                    {
                        if (child == null)
                        {
                            continue;
                        }
                        IElement ve = GenerateElement(child, context);
                        group.AddElement(ve);
                    }
                    return(group);
                }
                else if (node.Type == NodeType.Test)
                {
                    ElementGroup group = new ElementGroup(node as NodeGroup);
                    foreach (Node child in (node as Test).Children)
                    {
                        if (child == null)
                        {
                            continue;
                        }
                        IElement ve = GenerateElement(child, context);
                        group.AddElement(ve);
                    }
                    return(group);
                }
                else if (node is NodeGroup)
                {
                    ElementGroup group = new ElementGroup(node as NodeGroup);
                    if (node.Type == NodeType.Capture)
                    {
                        Capture capture = node as Capture;
                        if (capture.Anonymous)
                        {
                            int capnum;
                            if (capture.CapName.Number != 0)
                            {
                                capnum = context.FindCaptureIndex(capture);
                                group.SetAddition("Anony:" + capnum.ToString());
                                (group.AdditionBorder.Background as SolidColorBrush).Color = Color.FromRgb(0xd5, 0xb7, 0xff);
                                (group.Addition.Foreground as SolidColorBrush).Color       = Color.FromRgb(0x80, 0x22, 0xff);
                            }
                            else
                            {
                                if (context.DeepLevel == 1)
                                {
                                    group.OutLayout.Margin = new Thickness();
                                }
                                group.SetExpression(context.Current);
                            }
                        }
                        else
                        {
                            if (capture.CapName.IsName)
                            {
                                group.SetAddition("Name:" + capture.CapName.Name);
                            }
                            else
                            {
                                group.SetAddition("Number:" + capture.CapName.Number);
                            }
                        }
                    }
                    Alternate alter = (node as NodeGroup).Child as Alternate;

                    foreach (Node child in alter.Children)
                    {
                        if (child == null)
                        {
                            continue;
                        }
                        IElement ve = GenerateElement(child, context);
                        group.AddElement(ve);
                    }
                    return(group);
                }
                else if (node.Type == NodeType.Field)
                {
                    context.TraceIn((node as Field).Expression);
                    IElement ve = GenerateElement((node as Field).Expression.SyntaxTree.Root, context);
                    context.TraceOut();
                    return(ve);
                }
                // unfinished : field comment
                else
                {
                    throw new Exception("Internal Node Type Error.");
                }
            }
        }
コード例 #25
0
 /// <inheritdoc />
 public override uint RefreshCrc(out bool changed)
 {
     return(Alternate.RefreshCrc(out changed));
 }
コード例 #26
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_atomic()
        {
            var context = new Context("aaaab");
            var chara = new Character('a');
            var charb = new Character('b');
            var greedya = new Greedy(chara, 2);
            var atomic = new Atomic(greedya);
            var alt = new Alternate(new IMatch[] { chara, charb });
            var list = new List(new IMatch[] { new CaptureGroup(atomic, 1), alt });

            // (((?>a{2,}))(?:a|b))
            ExecTest(context, list);
        }
コード例 #27
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_negative_lookbehind()
        {
            var context = new Context("abaab");
            var chara = new Character('a');
            var charb = new Character('b');
            var alt = new Alternate(new IMatch[] { chara, charb });
            var lazy = new Lazy(alt, 1);

            var backa = new Character('a', false);
            var back2a = new List(new IMatch[] { backa, backa }, false);
            var assert = new Lookaround(back2a, false);
            var list = new List(new IMatch[] { lazy, assert });

            // ((?:a|b)+?(?<!aa))
            ExecTest(context, list);
        }
コード例 #28
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_greedyaltcapture()
        {
            var context = new Context("aaaaa");
            var chara = new Character('a');
            var list2a = new List(new IMatch[] { chara, chara });

            var grp1 = new CaptureGroup(chara, 1);
            var grp2 = new CaptureGroup(list2a, 2);
            var alt = new Alternate(new IMatch[] { grp1, grp2 });
            var greedy = new Greedy(alt, 1, 2);

            // ((a)|(aa)){1,2}
            ExecTest(context, greedy);
        }
コード例 #29
0
 public void TestAlternate()
 {
     // https://www.hackerrank.com/challenges/two-characters/problem
     Assert.AreEqual(5, Alternate.alternate("beabeefeab"));
 }
コード例 #30
0
 /// <inheritdoc />
 public override bool Validate()
 {
     return(Alternate.Validate());
 }
コード例 #31
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_alternatelist()
        {
            var context = new Context("aaaa");
            var chara = new Character('a');
            var list2a = new List(new IMatch[] { chara, chara });
            var list3a = new List(new IMatch[] { chara, chara, chara });
            var alt = new Alternate(new IMatch[] { chara, list2a, list3a });
            var list = new List(new IMatch[] { alt, alt });

            // (a|aa|aaa)(a|aa|aaa)
            ExecTest(context, list);
        }
コード例 #32
0
ファイル: RegexTests.cs プロジェクト: TheFellow/RegexLib
        public static void test_lazyalternate()
        {
            var context = new Context("aaaaa");
            var chara = new Character('a');
            var list2a = new List(new IMatch[] { chara, chara });
            var alt = new Alternate(new IMatch[] { chara, list2a });
            var lazy = new Lazy(alt, 1, 2);

            // (a|aa){1,2}?
            ExecTest(context, lazy);
        }