Exemple #1
0
 /// <summary>
 /// Attempt to go up one level in the Context stack. There must always be one Context active, so
 /// this method does nothing if there is only one element on the stack.
 /// </summary>
 public void PopContext()
 {
     if (ContextStack.Count > 1)
     {
         ContextStack.Pop();
     }
 }
Exemple #2
0
        static void Main(string[] args)
        {
            //<Snippet2>
            // Create a ContextStack.
            ContextStack stack = new ContextStack();

            //</Snippet2>

            //<Snippet3>
            // Push ten items on to the stack and output the value of each.
            for (int number = 0; number < 10; number++)
            {
                Console.WriteLine("Value pushed to stack: " + number.ToString());
                stack.Push(number);
            }
            //</Snippet3>

            //<Snippet4>
            // Pop each item off the stack.
            object item = null;

            while ((item = stack.Pop()) != null)
            {
                Console.WriteLine("Value popped from stack: " + item.ToString());
            }
            //</Snippet4>
        }
 public IResultWriter EndContext(Globals.ResultWriterDestination dest = Globals.ResultWriterDestination.stdOut)
 {
     if (ContextStack.Count > 0)
     {
         CurrentContext = ContextStack.Pop();
     }
     return(this);
 }
Exemple #4
0
 public IResultWriter EndContext(Globals.ResultWriterDestination dest = Globals.ResultWriterDestination.stdOut)
 {
     if (ContextStack.Count > 0)
     {
         CurrentContext = ContextStack.Pop();
     }
     colNames = new List <string>();
     return(this);
 }
 public IResultWriter EndContext(Globals.ResultWriterDestination dest = Globals.ResultWriterDestination.stdOut)
 {
     stdOut.Flush();
     VerboseOut.Flush();
     if (ContextStack.Count > 0)
     {
         CurrentContext = ContextStack.Pop();
     }
     return(this.DecreaseIndent());
 }
 public void PopContext()
 {
     if (ContextStack.Count > 0)
     {
         CurrentContext.Dispose();
         CurrentContext = ContextStack.Pop();
         NotifyMessage("コンテキストを変更しました。");
         ShowCommandsAsUsers();
     }
 }
Exemple #7
0
        [Test]         // Item (Int32)
        public void Indexer1()
        {
            ContextStack stack = new ContextStack();
            string       one   = "one";
            string       two   = "two";

            stack.Push(one);
            stack.Push(two);

            Assert.AreSame(two, stack [0], "#1");
            Assert.AreSame(one, stack [1], "#2");
            Assert.IsNull(stack [2], "#3");
            Assert.AreSame(two, stack.Pop(), "#4");
            Assert.AreSame(one, stack [0], "#5");
            Assert.IsNull(stack [1], "#6");
            Assert.AreSame(one, stack.Pop(), "#7");
            Assert.IsNull(stack [0], "#8");
            Assert.IsNull(stack [1], "#9");
        }
Exemple #8
0
        [Fact] // Item (Int32)
        public void Indexer1()
        {
            ContextStack stack = new ContextStack();
            string       one   = "one";
            string       two   = "two";

            stack.Push(one);
            stack.Push(two);

            Assert.Same(two, stack[0]);
            Assert.Same(one, stack[1]);
            Assert.Null(stack[2]);
            Assert.Same(two, stack.Pop());
            Assert.Same(one, stack[0]);
            Assert.Null(stack[1]);
            Assert.Same(one, stack.Pop());
            Assert.Null(stack[0]);
            Assert.Null(stack[1]);
        }
Exemple #9
0
 public IResultWriter EndContext(Globals.ResultWriterDestination dest = Globals.ResultWriterDestination.stdOut)
 {
     Write("}", dest);
     stdOut.Flush();
     VerboseOut.Flush();
     if (ContextStack.Count > 0)
     {
         CurrentContext = ContextStack.Pop();
     }
     return(this);
 }
Exemple #10
0
 static void incrementCursor(ref int cursor)
 {
     while (context.index <= cursor)
     {
         contextEnd(contextStack.Pop());
     }
     while (enclosure.end <= cursor)
     {
         enclosureEnd(enclosureStack.Pop());
     }
     cursor += 1;
 }
Exemple #11
0
        public void IntegrityTest()
        {
            ContextStack stack = new ContextStack();

            string one = "one";
            string two = "two";

            stack.Push(two);
            stack.Push(one);
            Assert.AreSame(one, stack [typeof(string)], "#1");
            Assert.AreSame(one, stack [0], "#2");
            Assert.AreSame(one, stack.Current, "#3");

            Assert.AreSame(one, stack.Pop(), "#4");

            Assert.AreSame(two, stack [typeof(string)], "#5");
            Assert.AreSame(two, stack [0], "#6");
            Assert.AreSame(two, stack.Current, "#7");

#if NET_2_0
            string three = "three";
            stack.Append(three);

            Assert.AreSame(two, stack[typeof(string)], "#8");
            Assert.AreSame(two, stack[0], "#9");
            Assert.AreSame(two, stack.Current, "#10");

            Assert.AreSame(two, stack.Pop(), "#11");

            Assert.AreSame(three, stack[typeof(string)], "#12");
            Assert.AreSame(three, stack[0], "#13");
            Assert.AreSame(three, stack.Current, "#14");
            Assert.AreSame(three, stack.Pop(), "#15");
#else
            Assert.AreSame(two, stack.Pop(), "#15");
#endif

            Assert.IsNull(stack.Pop(), "#16");
            Assert.IsNull(stack.Current, "#17");
        }
Exemple #12
0
        public void IntegrityTest()
        {
            ContextStack stack = new ContextStack();

            string one = "one";
            string two = "two";

            stack.Push(two);
            stack.Push(one);
            Assert.Same(one, stack[typeof(string)]);
            Assert.Same(one, stack[0]);
            Assert.Same(one, stack.Current);

            Assert.Same(one, stack.Pop());

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            string three = "three";

            stack.Append(three);

            Assert.Same(two, stack[typeof(string)]);
            Assert.Same(two, stack[0]);
            Assert.Same(two, stack.Current);

            Assert.Same(two, stack.Pop());

            Assert.Same(three, stack[typeof(string)]);
            Assert.Same(three, stack[0]);
            Assert.Same(three, stack.Current);
            Assert.Same(three, stack.Pop());

            Assert.Null(stack.Pop());
            Assert.Null(stack.Current);
        }
Exemple #13
0
        [Fact] // Item (Type)
        public void Indexer2()
        {
            ContextStack stack = new ContextStack();

            Foo    foo    = new Foo();
            FooBar foobar = new FooBar();

            stack.Push(foobar);
            stack.Push(foo);
            Assert.Same(foo, stack[typeof(Foo)]);
            Assert.Same(foo, stack[typeof(IFoo)]);
            Assert.Same(foo, stack.Pop());
            Assert.Same(foobar, stack[typeof(Foo)]);
            Assert.Same(foobar, stack[typeof(FooBar)]);
            Assert.Same(foobar, stack[typeof(IFoo)]);
            Assert.Null(stack[typeof(string)]);
        }
Exemple #14
0
        [Test]         // Item (Type)
        public void Indexer2()
        {
            ContextStack stack = new ContextStack();

            Foo    foo    = new Foo();
            FooBar foobar = new FooBar();

            stack.Push(foobar);
            stack.Push(foo);
            Assert.AreSame(foo, stack [typeof(Foo)], "#1");
            Assert.AreSame(foo, stack [typeof(IFoo)], "#2");
            Assert.AreSame(foo, stack.Pop(), "#3");
            Assert.AreSame(foobar, stack [typeof(Foo)], "#4");
            Assert.AreSame(foobar, stack [typeof(FooBar)], "#5");
            Assert.AreSame(foobar, stack [typeof(IFoo)], "#6");
            Assert.IsNull(stack [typeof(string)], "#7");
        }
        /// <summary>Releases unmanaged and - optionally - managed resources.</summary>
        /// <param name="b">
        ///   <see language="1"/> to release both managed and unmanaged resources; <see language="false"/> to release only unmanaged resources.</param>
        /// <exception cref="ContextStackException">Empty stack - expected at least one element
        /// or</exception>
        /// <autogeneratedoc />
        /// TODO Edit XML Comment Template for Dispose
        protected virtual void Dispose(bool b)
        {
            if (!b)
            {
                return;
            }

            if (!_contextStack.Any( ))
            {
                throw new ContextStackException("Empty stack - expected at least one element");
            }

            //Assert.NotEmpty ( contextStack ) ;
            if (!_contextStack.Peek( ).Equals(_infoContext))
            {
                throw new ContextStackException("");
            }

            //Assert.True ( ReferenceEquals ( _infoContext , contextStack.First ( ) ) ) ;
            _contextStack.Pop( );
        }
            void PopStack(SyntaxContext currentContext, SyntaxMatch curMatch)
            {
                if (ContextStack.Count() == 1)
                {
                    MatchStack = MatchStack.Clear();
                    ScopeStack = new ScopeStack(highlighting.definition.Scope);
                    return;
                }
                ContextStack = ContextStack.Pop();
                if (!MatchStack.IsEmpty)
                {
                    PopScopeStack(MatchStack.Peek()?.Scope);
                    MatchStack = MatchStack.Pop();
                }
                PopScopeStack(currentContext.MetaScope);

                if (curMatch.Scope.Count > 0 && !ScopeStack.IsEmpty)
                {
                    for (int i = 0; i < curMatch.Scope.Count; i++)
                    {
                        ScopeStack = ScopeStack.Pop();
                    }
                }
            }
Exemple #17
0
        public override object Execute(List <string> args)
        {
            if (args.Count < 1)
            {
                return(false);
            }

            var fieldName      = args[0];
            var fieldNameLow   = fieldName.ToLower();
            var fieldNameSnake = fieldName.ToSnakeCase();

            var previousContext   = ContextStack.Context;
            var previousOwner     = Owner;
            var previousStructure = Structure;

            var blockName = "";

            if (fieldName.Contains("."))
            {
                var lastIndex = fieldName.LastIndexOf('.');
                blockName      = fieldName.Substring(0, lastIndex);
                fieldName      = fieldName.Substring(lastIndex + 1, (fieldName.Length - lastIndex) - 1);
                fieldNameLow   = fieldName.ToLower();
                fieldNameSnake = fieldName.ToSnakeCase();

                var command = new EditBlockCommand(ContextStack, Cache, Tag, Owner);

                if (command.Execute(new List <string> {
                    blockName
                }).Equals(false))
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }

                command = (ContextStack.Context.GetCommand("EditBlock") as EditBlockCommand);

                Owner     = command.Owner;
                Structure = command.Structure;

                if (Owner == null)
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }
            }

            var field = TagStructure.GetTagFieldEnumerable(Structure)
                        .Find(f =>
                              f.Name == fieldName ||
                              f.Name.ToLower() == fieldNameLow ||
                              f.Name.ToSnakeCase() == fieldNameSnake);

            var ownerType = Owner.GetType();

            if (field == null)
            {
                Console.WriteLine("{0} does not contain a block named \"{1}\"", ownerType.Name, fieldName);
                return(false);
            }

            IList fieldValue = null;

            if (field.FieldType.GetInterface("IList") == null || (fieldValue = (IList)field.GetValue(Owner)) == null)
            {
                Console.WriteLine("{0} does not contain a block named \"{1}\"", ownerType.Name, fieldName);
                return(false);
            }

            string fromName = null;
            int?   from     = null;

            string toName = null;
            int?   to     = null;

            while (args.Count > 1)
            {
                var found = false;

                switch (args[1].ToLower())
                {
                case "from:":
                    if (char.IsNumber(args[2][0]))
                    {
                        from = int.Parse(args[2]);
                    }
                    else
                    {
                        fromName = args[2];
                        from     = FindLabelIndex(fieldValue, fromName);
                    }
                    args.RemoveRange(1, 2);
                    found = true;
                    break;

                case "to:":
                    if (char.IsNumber(args[2][0]))
                    {
                        to = int.Parse(args[2]);
                    }
                    else
                    {
                        toName = args[2];
                        to     = FindLabelIndex(fieldValue, toName);
                    }
                    args.RemoveRange(1, 2);
                    found = true;
                    break;
                }

                if (!found)
                {
                    break;
                }
            }

            blockName = args[0];
            args.RemoveRange(0, 1);

            var commandsToExecute = new List <List <string> >();

            // if no command is given, keep reading commands from stdin until an empty line encountered
            if (args.Count < 1)
            {
                string line;
                while (!string.IsNullOrWhiteSpace(line = Console.ReadLine()))
                {
                    var commandsArgs = ArgumentParser.ParseCommand(line, out string redirectFile);
                    commandsToExecute.Add(commandsArgs);
                }
            }
            else
            {
                commandsToExecute.Add(args);
            }

            for (var i = (from ?? 0);
                 i < (to.HasValue ? to.Value + 1 : fieldValue.Count);
                 i++)
            {
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }

                Owner     = previousOwner;
                Structure = previousStructure;

                if (blockName != "" && new EditBlockCommand(ContextStack, Cache, Tag, Owner)
                    .Execute(new List <string> {
                    $"{blockName}[{i}]"
                })
                    .Equals(false))
                {
                    return(false);
                }

                var label = GetLabel(fieldValue, i);

                Console.Write(label == null ? $"[{i}] " : $"[{label} ({i})] ");
                foreach (var command in commandsToExecute)
                {
                    ContextStack.Context.GetCommand(command[0]).Execute(command.Skip(1).ToList());
                }
            }

            while (ContextStack.Context != previousContext)
            {
                ContextStack.Pop();
            }

            Owner     = previousOwner;
            Structure = previousStructure;

            return(true);
        }
        public override object Execute(List <string> args)
        {
            if (args.Count < 2)
            {
                return(false);
            }

            var fieldName      = args[0];
            var fieldNameLow   = fieldName.ToLower();
            var fieldNameSnake = fieldName.ToSnakeCase();

            var previousContext   = ContextStack.Context;
            var previousOwner     = Owner;
            var previousStructure = Structure;

            if (fieldName.Contains("."))
            {
                var lastIndex = fieldName.LastIndexOf('.');
                var blockName = fieldName.Substring(0, lastIndex);
                fieldName      = fieldName.Substring(lastIndex + 1, (fieldName.Length - lastIndex) - 1);
                fieldNameLow   = fieldName.ToLower();
                fieldNameSnake = fieldName.ToSnakeCase();

                var command = new EditBlockCommand(ContextStack, CacheContext, Tag, Owner);

                if (command.Execute(new List <string> {
                    blockName
                }).Equals(false))
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }

                command = (ContextStack.Context.GetCommand("EditBlock") as EditBlockCommand);

                Owner     = command.Owner;
                Structure = command.Structure;

                if (Owner == null)
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }
            }

            var field = TagStructure.GetTagFieldEnumerable(Structure)
                        .Find(f =>
                              f.Name == fieldName ||
                              f.Name.ToLower() == fieldNameLow ||
                              f.Name.ToSnakeCase() == fieldNameSnake);

            if (field == null)
            {
                Console.WriteLine("ERROR: {0} does not contain a field named \"{1}\".", Structure.Types[0].Name, fieldName);
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }
                Owner     = previousOwner;
                Structure = previousStructure;
                return(false);
            }

            var fieldType  = field.FieldType;
            var fieldAttrs = field.GetCustomAttributes(typeof(TagFieldAttribute), false);
            var fieldAttr  = fieldAttrs?.Length < 1 ? new TagFieldAttribute() : (TagFieldAttribute)fieldAttrs[0];
            var fieldInfo  = new TagFieldInfo(field, fieldAttr, uint.MaxValue, uint.MaxValue);
            var fieldValue = ParseArgs(field.FieldType, fieldInfo, args.Skip(1).ToList());

            if (fieldValue != null && fieldValue.Equals(false))
            {
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }
                Owner     = previousOwner;
                Structure = previousStructure;
                return(false);
            }

            if (field.FieldType == typeof(PageableResource))
            {
                var ownerValue = field.GetValue(Owner);

                if (fieldValue == null)
                {
                    field.SetValue(Owner, null);
                }
                else if (ownerValue is PageableResource pageable)
                {
                    var newLocation = ResourceLocation.None;

                    FileInfo resourceFile = null;

                    switch (fieldValue)
                    {
                    case FileInfo file:
                        if (!pageable.GetLocation(out newLocation))
                        {
                            newLocation = ResourceLocation.ResourcesB;
                        }
                        resourceFile = file;
                        break;

                    case ValueTuple <ResourceLocation, FileInfo> tuple:
                        newLocation  = tuple.Item1;
                        resourceFile = tuple.Item2;
                        break;

                    default:
                        throw new FormatException(fieldValue.ToString());
                    }

                    ResourceCache oldCache = null;

                    if (pageable.GetLocation(out var oldLocation))
                    {
                        oldCache = CacheContext.GetResourceCache(oldLocation);
                    }

                    var newCache = CacheContext.GetResourceCache(newLocation);

                    var data = File.ReadAllBytes(resourceFile.FullName);

                    pageable.Page.UncompressedBlockSize = (uint)data.Length;

                    if (oldLocation == newLocation && pageable.Page.Index != -1)
                    {
                        using (var stream = CacheContext.OpenResourceCacheReadWrite(oldLocation))
                        {
                            pageable.Page.CompressedBlockSize = oldCache.Compress(stream, pageable.Page.Index, data);
                        }
                    }
                    else
                    {
                        using (var destStream = CacheContext.OpenResourceCacheReadWrite(newLocation))
                        {
                            pageable.Page.Index = newCache.Add(destStream, data, out pageable.Page.CompressedBlockSize);
                        }

                        pageable.ChangeLocation(newLocation);
                    }

                    pageable.DisableChecksum();

                    field.SetValue(Owner, fieldValue = pageable);
                }
            }
            else
            {
                field.SetValue(Owner, fieldValue);
            }

            var typeString =
                fieldType.IsGenericType ?
                $"{fieldType.Name}<{fieldType.GenericTypeArguments[0].Name}>" :
                fieldType.Name;

            string valueString;

#if !DEBUG
            try
            {
#endif
            if (fieldValue == null)
            {
                valueString = "null";
            }
            else if (fieldType == typeof(StringId))
            {
                valueString = CacheContext.GetString((StringId)fieldValue);
            }
            else if (fieldType == typeof(CachedTagInstance))
            {
                var instance = (CachedTagInstance)fieldValue;

                var tagName = instance?.Name ?? $"0x{instance.Index:X4}";

                valueString = $"[0x{instance.Index:X4}] {tagName}.{CacheContext.GetString(instance.Group.Name)}";
            }
            else if (fieldType == typeof(TagFunction))
            {
                var function = (TagFunction)fieldValue;
                valueString = "";
                foreach (var datum in function.Data)
                {
                    valueString += datum.ToString("X2");
                }
            }
            else if (fieldType == typeof(PageableResource))
            {
                var pageable = (PageableResource)fieldValue;
                pageable.GetLocation(out var location);
                valueString = pageable == null ? "null" : $"{{ Location: {location}, Index: 0x{pageable.Page.Index:X4}, CompressedSize: 0x{pageable.Page.CompressedBlockSize:X8} }}";
            }
            else if (fieldInfo.FieldType.IsArray && fieldInfo.Attribute.Length != 0)
            {
                valueString = fieldValue == null ? "null" : $"[{fieldInfo.Attribute.Length}] {{ ";
                var valueArray = (Array)fieldValue;

                if (fieldValue != null)
                {
                    for (var i = 0; i < fieldInfo.Attribute.Length; i++)
                    {
                        valueString += $"{valueArray.GetValue(i)}{((i + 1) < fieldInfo.Attribute.Length ? "," : "")} ";
                    }

                    valueString += "}";
                }
            }
            else if (fieldType.GetInterface(typeof(IList).Name) != null)
            {
                valueString =
                    ((IList)fieldValue).Count != 0 ?
                    $"{{...}}[{((IList)fieldValue).Count}]" :
                    "null";
            }
            else
            {
                valueString = fieldValue.ToString();
            }
#if !DEBUG
        }

        catch (Exception e)
        {
            valueString = $"<ERROR MESSAGE=\"{e.Message}\" />";
        }
#endif

            var fieldFullName     = $"{field.DeclaringType.FullName}.{field.Name}".Replace("+", ".");
            var documentationNode = EditTagContextFactory.Documentation.SelectSingleNode($"//member[starts-with(@name, 'F:{fieldFullName}')]");

            Console.WriteLine("{0}: {1} = {2} {3}", field.Name, typeString, valueString,
                              documentationNode != null ?
                              $":: {documentationNode.FirstChild.InnerText.Replace("\r\n", "").TrimStart().TrimEnd()}" :
                              "");

            while (ContextStack.Context != previousContext)
            {
                ContextStack.Pop();
            }
            Owner     = previousOwner;
            Structure = previousStructure;

            return(true);
        }
Exemple #19
0
        public override object Execute(List <string> args)
        {
            if (args.Count < 1)
            {
                return(false);
            }

            var isConst = false;

            if (args[0].ToLower() == "const")
            {
                args.RemoveAt(0);
                isConst = true;
            }

            if (args.Count < 1)
            {
                return(false);
            }

            if (!Cache.TryParseGroupTag(args[0], out var groupTag))
            {
                Console.WriteLine($"Invalid tag group: {args[0]}");
                return(true);
            }

            args.RemoveAt(0);

            var startFilter = "";
            var endFilter   = "";
            var filter      = "";
            var filename    = "";

            string pattern = null;

            while (args.Count > 0 && args[0].EndsWith(":"))
            {
                switch (args[0].ToLower())
                {
                case "in_file:":
                    filename = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "regex:":
                    if (args.Count < 3)
                    {
                        return(false);
                    }
                    pattern = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "starts:":
                case "startswith:":
                case "starts_with:":
                case "starting:":
                case "startingwith:":
                case "starting_with:":
                case "start_filter:":
                case "starting_filter:":
                    startFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "ends:":
                case "ending:":
                case "endingwith:":
                case "ending_with:":
                case "endswith:":
                case "ends_with:":
                case "end_filter:":
                case "ending_filter:":
                    endFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "named:":
                case "filter:":
                case "contains:":
                case "containing:":
                    filter = args[1];
                    args.RemoveRange(0, 2);
                    break;
                }
            }

            var commandsToExecute = new List <List <string> >();

            // if no command is given, keep reading commands from stdin until an empty line encountered
            if (args.Count < 1)
            {
                string line;
                while (!string.IsNullOrWhiteSpace(line = Console.ReadLine()))
                {
                    var commandsArgs = ArgumentParser.ParseCommand(line, out string redirectFile);
                    commandsToExecute.Add(commandsArgs);
                }
            }
            else
            {
                commandsToExecute.Add(args);
            }

            List <CachedTag> tags = null;

            // if a file is given use that as the source for tags
            if (!string.IsNullOrWhiteSpace(filename))
            {
                var tagsList = new List <CachedTag>();
                foreach (var line in File.ReadAllLines(filename))
                {
                    tags.Add(Cache.GetTag(line));
                }

                tags = tagsList;
            }
            else
            {
                tags = Cache.TagCache.NonNull().ToList();
            }

            var rootContext = ContextStack.Context;


            foreach (var instance in tags)
            {
                if (instance == null || (groupTag != Tag.Null && !instance.IsInGroup(groupTag)))
                {
                    continue;
                }

                var tagName = instance.Name ?? $"0x{instance.Index:X4}";

                try
                {
                    if (pattern != null && !Regex.IsMatch(tagName, pattern, RegexOptions.IgnoreCase))
                    {
                        continue;
                    }
                }
                catch
                {
                    continue;
                }

                if (!tagName.StartsWith(startFilter) || !tagName.Contains(filter) || !tagName.EndsWith(endFilter))
                {
                    continue;
                }

                object definition = null;
                using (var stream = Cache.OpenCacheRead())
                    definition = Cache.Deserialize(stream, instance);


                ContextStack.Push(EditTagContextFactory.Create(ContextStack, Cache, instance, definition));

                Console.WriteLine();
                Console.WriteLine($"{tagName}.{Cache.StringTable.GetString(instance.Group.Name)}:");
                ContextStack.Context.GetCommand(args[0]).Execute(args.Skip(1).ToList());

                while (ContextStack.Context != rootContext)
                {
                    ContextStack.Pop();
                }

                if (!isConst)
                {
                    using (var stream = Cache.OpenCacheReadWrite())
                        Cache.Serialize(stream, instance, definition);
                }
            }

            Console.WriteLine();
            return(true);
        }
Exemple #20
0
        public override object Execute(List <string> args)
        {
            if (args.Count < 2)
            {
                return(false);
            }

            var isConst = false;

            if (args[0].ToLower() == "const")
            {
                args.RemoveAt(0);
                isConst = true;
            }

            if (args.Count < 2)
            {
                return(false);
            }

            if (!CacheContext.TryParseGroupTag(args[0], out var groupTag))
            {
                Console.WriteLine($"Invalid tag group: {args[0]}");
                return(true);
            }

            args.RemoveAt(0);

            var startFilter = "";
            var endFilter   = "";
            var filter      = "";

            string pattern = null;

            while (args[0].EndsWith(":"))
            {
                switch (args[0].ToLower())
                {
                case "regex:":
                    if (args.Count < 3)
                    {
                        return(false);
                    }
                    pattern = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "starts:":
                case "startswith:":
                case "starts_with:":
                case "starting:":
                case "startingwith:":
                case "starting_with:":
                case "start_filter:":
                case "starting_filter:":
                    startFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "ends:":
                case "ending:":
                case "endingwith:":
                case "ending_with:":
                case "endswith:":
                case "ends_with:":
                case "end_filter:":
                case "ending_filter:":
                    endFilter = args[1];
                    args.RemoveRange(0, 2);
                    break;

                case "named:":
                case "filter:":
                case "contains:":
                case "containing:":
                    filter = args[1];
                    args.RemoveRange(0, 2);
                    break;
                }
            }

            var rootContext = ContextStack.Context;

            using (var stream = CacheContext.OpenTagCacheReadWrite())
            {
                foreach (var instance in CacheContext.TagCache.Index)
                {
                    if (instance == null || (groupTag != Tag.Null && !instance.IsInGroup(groupTag)))
                    {
                        continue;
                    }

                    var tagName = instance.Name ?? $"0x{instance.Index:X4}";

                    try
                    {
                        if (pattern != null && !Regex.IsMatch(tagName, pattern, RegexOptions.IgnoreCase))
                        {
                            continue;
                        }
                    }
                    catch
                    {
                        continue;
                    }

                    if (!tagName.StartsWith(startFilter) || !tagName.Contains(filter) || !tagName.EndsWith(endFilter))
                    {
                        continue;
                    }

                    var definition = CacheContext.Deserialize(stream, instance);
                    ContextStack.Push(EditTagContextFactory.Create(ContextStack, CacheContext, instance, definition));

                    Console.WriteLine();
                    Console.WriteLine($"{tagName}.{CacheContext.GetString(instance.Group.Name)}:");
                    ContextStack.Context.GetCommand(args[0]).Execute(args.Skip(1).ToList());

                    while (ContextStack.Context != rootContext)
                    {
                        ContextStack.Pop();
                    }

                    if (!isConst)
                    {
                        CacheContext.Serialize(stream, instance, definition);
                    }
                }

                Console.WriteLine();
            }

            return(true);
        }
Exemple #21
0
        public override object Execute(List <string> args)
        {
            if (args.Count > 4)
            {
                return(false);
            }


            if (args.Count < 1 || args.Count > 3)
            {
                return(false);
            }

            var fieldName    = args[0];
            var fieldNameLow = fieldName.ToLower();

            var previousContext   = ContextStack.Context;
            var previousOwner     = Owner;
            var previousStructure = Structure;

            if (fieldName.Contains("."))
            {
                var lastIndex = fieldName.LastIndexOf('.');
                var blockName = fieldName.Substring(0, lastIndex);
                fieldName    = fieldName.Substring(lastIndex + 1, (fieldName.Length - lastIndex) - 1);
                fieldNameLow = fieldName.ToLower();

                var command = new EditBlockCommand(ContextStack, CacheContext, Tag, Owner);

                if (command.Execute(new List <string> {
                    blockName
                }).Equals(false))
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }

                command = (ContextStack.Context.GetCommand("EditBlock") as EditBlockCommand);

                Owner     = command.Owner;
                Structure = command.Structure;

                if (Owner == null)
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }
            }

            var index = 0;

            if (args.Count > 1 && args[1] != "*")
            {
                if (!int.TryParse(args[1], out index) || index < 0)
                {
                    Console.WriteLine($"Invalid index specified: {args[1]}");
                    return(false);
                }
            }

            var count = -1;

            if (args.Count > 2)
            {
                if (args[2] != "*" && (!int.TryParse(args[2], out count) || count < 1))
                {
                    Console.WriteLine($"Invalid count specified: {args[2]}");
                    return(false);
                }
            }

            var field = TagStructure.GetTagFieldEnumerable(Structure)
                        .Find(f => f.Name == fieldName || f.Name.ToLower() == fieldNameLow);

            var fieldType = field.FieldType;

            if ((field == null) ||
                (!fieldType.IsGenericType) ||
                (fieldType.GetInterface("IList") == null))
            {
                Console.WriteLine("ERROR: {0} does not contain a tag block named \"{1}\".", Structure.Types[0].Name, args[0]);
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }
                Owner     = previousOwner;
                Structure = previousStructure;
                return(false);
            }

            var blockValue = field.GetValue(Owner) as IList;

            if (blockValue == null)
            {
                Console.WriteLine($"Invalid index specified: {args[0]}");
                return(false);
            }

            if (count < 0)
            {
                count = blockValue.Count;
            }

            if ((index + count) < 0 || (index + count) > blockValue.Count)
            {
                Console.WriteLine($"Invalid index: {index}, and count: {count}");
                return(false);
            }

            ElementType = field.FieldType.GenericTypeArguments[0];
            Elements    = new List <object>();

            for (var i = index; i < (index + count); i++)
            {
                Elements.Add(blockValue[i]);
            }

            var itemString = index < 2 ? "element" : "elements";

            Console.WriteLine($"Successfully copied {count} {itemString}.");

            while (ContextStack.Context != previousContext)
            {
                ContextStack.Pop();
            }
            Owner     = previousOwner;
            Structure = previousStructure;

            return(true);
        }
 public void PopParameter()
 {
     _types.Pop();
     _parameters.Pop();
 }
        public override object Execute(List <string> args)
        {
            if (args.Count < 2)
            {
                return(false);
            }

            var fieldName = args[0];
            var file      = new FileInfo(args[1]);

            var fieldNameLow   = fieldName.ToLower();
            var fieldNameSnake = fieldName.ToSnakeCase();

            var previousContext   = ContextStack.Context;
            var previousOwner     = Owner;
            var previousStructure = Structure;

            if (fieldName.Contains("."))
            {
                var lastIndex = fieldName.LastIndexOf('.');
                var blockName = fieldName.Substring(0, lastIndex);
                fieldName      = fieldName.Substring(lastIndex + 1, (fieldName.Length - lastIndex) - 1);
                fieldNameLow   = fieldName.ToLower();
                fieldNameSnake = fieldName.ToSnakeCase();

                var command = new EditBlockCommand(ContextStack, CacheContext, Tag, Owner);

                if (command.Execute(new List <string> {
                    blockName
                }).Equals(false))
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }

                command = (ContextStack.Context.GetCommand("EditBlock") as EditBlockCommand);

                Owner     = command.Owner;
                Structure = command.Structure;

                if (Owner == null)
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }
            }

            var field = TagStructure.GetTagFieldEnumerable(Structure)
                        .Find(f =>
                              f.Name == fieldName ||
                              f.Name.ToLower() == fieldNameLow ||
                              f.Name.ToSnakeCase() == fieldNameSnake);

            if (field == null)
            {
                Console.WriteLine($"ERROR: {Structure.Types[0].Name} does not contain a field named \"{fieldName}\".");
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }
                Owner     = previousOwner;
                Structure = previousStructure;
                return(false);
            }
            else if (field.FieldType != typeof(PageableResource))
            {
                Console.WriteLine($"ERROR: {Structure.Types[0].Name}.{field.Name} is not of type {nameof(PageableResource)}.");
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }
                Owner     = previousOwner;
                Structure = previousStructure;
                return(false);
            }

            var fieldType  = field.FieldType;
            var fieldAttrs = field.GetCustomAttributes(typeof(TagFieldAttribute), false);
            var fieldAttr  = fieldAttrs?.Length < 1 ? new TagFieldAttribute() : (TagFieldAttribute)fieldAttrs[0];
            var fieldInfo  = new TagFieldInfo(field, fieldAttr, uint.MaxValue, uint.MaxValue);
            var fieldValue = field.GetValue(Owner) as PageableResource;

            if (!file.Directory.Exists)
            {
                file.Directory.Create();
            }

            File.WriteAllBytes(file.FullName, CacheContext.ExtractRawResource(fieldValue));
            Console.WriteLine($"Wrote 0x{fieldValue.Page.CompressedBlockSize:X} bytes to \"{file.FullName}\".");

            while (ContextStack.Context != previousContext)
            {
                ContextStack.Pop();
            }
            Owner     = previousOwner;
            Structure = previousStructure;

            return(true);
        }
Exemple #24
0
        public override object Execute(List <string> args)
        {
            if (args.Count < 1)
            {
                return(false);
            }

            var fieldName      = args[0];
            var fieldNameLow   = fieldName.ToLower();
            var fieldNameSnake = fieldName.ToSnakeCase();

            var previousContext   = ContextStack.Context;
            var previousOwner     = Owner;
            var previousStructure = Structure;

            var blockName = "";

            if (fieldName.Contains("."))
            {
                var lastIndex = fieldName.LastIndexOf('.');
                blockName      = fieldName.Substring(0, lastIndex);
                fieldName      = fieldName.Substring(lastIndex + 1, (fieldName.Length - lastIndex) - 1);
                fieldNameLow   = fieldName.ToLower();
                fieldNameSnake = fieldName.ToSnakeCase();

                var command = new EditBlockCommand(ContextStack, CacheContext, Tag, Owner);

                if (command.Execute(new List <string> {
                    blockName
                }).Equals(false))
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }

                command = (ContextStack.Context.GetCommand("EditBlock") as EditBlockCommand);

                Owner     = command.Owner;
                Structure = command.Structure;

                if (Owner == null)
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }
            }

            var field = TagStructure.GetTagFieldEnumerable(Structure)
                        .Find(f =>
                              f.Name == fieldName ||
                              f.Name.ToLower() == fieldNameLow ||
                              f.Name.ToSnakeCase() == fieldNameSnake);

            var ownerType = Owner.GetType();

            if (field == null)
            {
                Console.WriteLine("{0} does not contain a block named \"{1}\"", ownerType.Name, fieldName);
                return(false);
            }

            IList fieldValue = null;

            if (field.FieldType.GetInterface("IList") == null || (fieldValue = (IList)field.GetValue(Owner)) == null)
            {
                Console.WriteLine("{0} does not contain a block named \"{1}\"", ownerType.Name, fieldName);
                return(false);
            }

            blockName = args[0];
            args      = args.Skip(1).ToList();

            for (var i = 0; i < fieldValue.Count; i++)
            {
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }

                Owner     = previousOwner;
                Structure = previousStructure;

                if (blockName != "" && new EditBlockCommand(ContextStack, CacheContext, Tag, Owner)
                    .Execute(new List <string> {
                    $"{blockName}[{i}]"
                })
                    .Equals(false))
                {
                    return(false);
                }

                Console.Write($"[{i}] ");
                ContextStack.Context.GetCommand(args[0]).Execute(args.Skip(1).ToList());
            }

            while (ContextStack.Context != previousContext)
            {
                ContextStack.Pop();
            }

            Owner     = previousOwner;
            Structure = previousStructure;

            return(true);
        }
        public override object Execute(List <string> args)
        {
            if (args.Count < 1 || args.Count > 3)
            {
                return(false);
            }

            var fieldName    = args[0];
            var fieldNameLow = fieldName.ToLower();

            var previousContext   = ContextStack.Context;
            var previousOwner     = Owner;
            var previousStructure = Structure;

            if (fieldName.Contains("."))
            {
                var lastIndex = fieldName.LastIndexOf('.');
                var blockName = fieldName.Substring(0, lastIndex);
                fieldName    = fieldName.Substring(lastIndex + 1, (fieldName.Length - lastIndex) - 1);
                fieldNameLow = fieldName.ToLower();

                var command = new EditBlockCommand(ContextStack, CacheContext, Tag, Owner);

                if (command.Execute(new List <string> {
                    blockName
                }).Equals(false))
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }

                command = (ContextStack.Context.GetCommand("EditBlock") as EditBlockCommand);

                Owner     = command.Owner;
                Structure = command.Structure;

                if (Owner == null)
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }
            }

            var field = TagStructure.GetTagFieldEnumerable(Structure)
                        .Find(f => f.Name == fieldName || f.Name.ToLower() == fieldNameLow);



            var fieldType = field.FieldType;

            if ((field == null) ||
                (!fieldType.IsGenericType) ||
                (fieldType.GetInterface("IList") == null))
            {
                Console.WriteLine("ERROR: {0} does not contain a tag block named \"{1}\".", Structure.Types[0].Name, args[0]);
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }
                Owner     = previousOwner;
                Structure = previousStructure;
                return(false);
            }

            var blockValue = field.GetValue(Owner) as IList;

            if (blockValue == null)
            {
                blockValue = Activator.CreateInstance(field.FieldType) as IList;
                field.SetValue(Owner, blockValue);
            }

            var elementType = field.FieldType.GenericTypeArguments[0];

            var index = blockValue.Count - 1;
            var count = 1;

            var genericIndex = false;
            var genericCount = false;

            if (args.Count == 1)
            {
                count = 1;
            }
            else
            {
                if (args.Count >= 2)
                {
                    if (args[1] == "*")
                    {
                        genericIndex = true;
                        index        = blockValue.Count;
                    }
                    else if (!int.TryParse(args[1], out index) || index < 0 || index >= blockValue.Count)
                    {
                        Console.WriteLine($"Invalid index specified: {args[1]}");
                        return(false);
                    }
                }

                if (args.Count == 3)
                {
                    if (args[2] == "*")
                    {
                        genericCount = true;
                        count        = blockValue.Count - index;
                    }
                    else if (!int.TryParse(args[2], out count) || count < 1)
                    {
                        Console.WriteLine($"Invalid number specified: {args[2]}");
                        return(false);
                    }
                }
            }

            if (genericIndex && genericCount)
            {
                index = 0;
                count = blockValue.Count;
            }
            else if (genericIndex)
            {
                index -= count;

                if (index < 0)
                {
                    index = 0;
                }
            }

            if (index + count > blockValue.Count)
            {
                Console.WriteLine($"ERROR: Too many block elements specified to be removed: {count}. Maximum at index {index} can be {blockValue.Count - index}");
                return(false);
            }

            for (var i = 0; i < count; i++)
            {
                blockValue.RemoveAt(index);
            }

            field.SetValue(Owner, blockValue);

            var typeString =
                fieldType.IsGenericType ?
                $"{fieldType.Name}<{fieldType.GenericTypeArguments[0].Name}>" :
                fieldType.Name;

            var itemString = count < 2 ? "element" : "elements";

            var valueString =
                ((IList)blockValue).Count != 0 ?
                $"{{...}}[{((IList)blockValue).Count}]" :
                "null";

            Console.WriteLine($"Successfully removed {count} {itemString} from {field.Name} at index {index}: {typeString}");
            Console.WriteLine(valueString);

            while (ContextStack.Context != previousContext)
            {
                ContextStack.Pop();
            }
            Owner     = previousOwner;
            Structure = previousStructure;

            return(true);
        }
 // ReSharper disable once UnusedParameter.Global
 public void After([NotNull] MethodInfo methodUnderTest)
 {
     // Assert.NotEmpty( _stack );
     // Assert.True( Object.ReferenceEquals( _stack.First(), _context ) );
     _stack.Pop( );
 }
        public override object Execute(List <string> args)
        {
            if (args.Count < 1 || args.Count > 2)
            {
                return(false);
            }

            if (CopyBlockElementsCommand.Elements == null)
            {
                Console.WriteLine("ERROR: No elements are available in the clipboard.");
                return(false);
            }

            var fieldName    = args[0];
            var fieldNameLow = fieldName.ToLower();

            var previousContext   = ContextStack.Context;
            var previousOwner     = Owner;
            var previousStructure = Structure;

            if (fieldName.Contains("."))
            {
                var lastIndex = fieldName.LastIndexOf('.');
                var blockName = fieldName.Substring(0, lastIndex);
                fieldName    = fieldName.Substring(lastIndex + 1, (fieldName.Length - lastIndex) - 1);
                fieldNameLow = fieldName.ToLower();

                var command = new EditBlockCommand(ContextStack, Cache, Tag, Owner);

                if (command.Execute(new List <string> {
                    blockName
                }).Equals(false))
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }

                command = (ContextStack.Context.GetCommand("EditBlock") as EditBlockCommand);

                Owner     = command.Owner;
                Structure = command.Structure;

                if (Owner == null)
                {
                    while (ContextStack.Context != previousContext)
                    {
                        ContextStack.Pop();
                    }
                    Owner     = previousOwner;
                    Structure = previousStructure;
                    return(false);
                }
            }

            var index = -1;

            if (args.Count > 1)
            {
                if (args[1] != "*" && (!int.TryParse(args[1], out index) || index < 0))
                {
                    Console.WriteLine($"Invalid index specified: {args[1]}");
                    return(false);
                }
            }

            var field = TagStructure.GetTagFieldEnumerable(Structure)
                        .Find(f => f.Name == fieldName || f.Name.ToLower() == fieldNameLow);

            var fieldType = field.FieldType;

            if ((field == null) ||
                (!fieldType.IsGenericType) ||
                (fieldType.GetInterface("IList") == null))
            {
                Console.WriteLine("ERROR: {0} does not contain a tag block named \"{1}\".", Structure.Types[0].Name, args[0]);
                while (ContextStack.Context != previousContext)
                {
                    ContextStack.Pop();
                }
                Owner     = previousOwner;
                Structure = previousStructure;
                return(false);
            }

            var elementType = field.FieldType.GenericTypeArguments[0];

            if (elementType != CopyBlockElementsCommand.ElementType)
            {
                Console.WriteLine("Invalid block element type!");
                return(false);
            }

            var blockValue = field.GetValue(Owner) as IList;

            if (blockValue == null)
            {
                blockValue = Activator.CreateInstance(field.FieldType) as IList;
                field.SetValue(Owner, blockValue);
            }

            if (index > blockValue.Count)
            {
                Console.WriteLine($"Invalid index specified: {index}");
                return(false);
            }

            for (var i = 0; i < CopyBlockElementsCommand.Elements.Count; i++)
            {
                var element = CopyBlockElementsCommand.Elements[i];

                if (index == -1)
                {
                    blockValue.Add(element);
                }
                else
                {
                    blockValue.Insert(index + i, element);
                }
            }

            field.SetValue(Owner, blockValue);

            var typeString =
                fieldType.IsGenericType ?
                $"{fieldType.Name}<{fieldType.GenericTypeArguments[0].Name}>" :
                fieldType.Name;

            var itemString = CopyBlockElementsCommand.Elements.Count < 2 ? "element" : "elements";

            var valueString =
                ((IList)blockValue).Count != 0 ?
                $"{{...}}[{((IList)blockValue).Count}]" :
                "null";

            Console.WriteLine($"Successfully pasted {CopyBlockElementsCommand.Elements.Count} {itemString} to {field.Name}: {typeString}");
            Console.WriteLine(valueString);

            while (ContextStack.Context != previousContext)
            {
                ContextStack.Pop();
            }
            Owner     = previousOwner;
            Structure = previousStructure;

            return(true);
        }
Exemple #28
0
        private bool ParseOther(TemplateStream stream, TokenList tokens, ContextStack context, ScopeStack scope, BraceStack brace)
        {
            switch (stream.Current)
            {
            case '[':
                brace.Push(tokens.Add(new Token(stream.Position, 1, stream.Line, TokenType.OpenBrace, context.Current)), scope.Changed);
                stream.Advance();
                return(true);

            case ']':
                var openBrace = brace.Pop(TokenType.OpenBrace);
                var token     = tokens.Add(new Token(stream.Position, 1, stream.Line, TokenType.CloseBrace, context.Current, null, openBrace.Token));
                if (openBrace.Token != null)
                {
                    openBrace.Token.MatchingToken = token;
                }
                stream.Advance();

                if (openBrace.ScopeChanged)
                {
                    var current = scope.Pop();
                    if (current == Scope.Template)
                    {
                        context.Pop(stream.Position);
                        if (stream.Current == '[')
                        {
                            scope.Push(Scope.Separator);
                        }
                    }
                    else if (current == Scope.True)
                    {
                        context.Pop(stream.Position);
                        if (stream.Current == '[')
                        {
                            scope.Push(Scope.False);
                        }
                    }
                }
                return(true);

            case '{':
                //tokens.Add(new Token(stream.Position - 1, 2, TokenType.OpenBlock, context.Current));
                brace.Push(tokens.Add(new Token(stream.Position, 1, stream.Line, TokenType.OpenCurlyBrace, context.Current)), scope.Changed);
                stream.Advance();
                return(true);

            case '}':
                var openCurlyBrace = brace.Pop(TokenType.OpenCurlyBrace);
                token = tokens.Add(new Token(stream.Position, 1, stream.Line, TokenType.CloseCurlyBrace, context.Current, null, openCurlyBrace.Token));
                if (openCurlyBrace.Token != null)
                {
                    openCurlyBrace.Token.MatchingToken = token;
                }
                //tokens.Add(new Token(stream.Position, 1, TokenType.CloseBlock, context.Current));
                stream.Advance();

                if (openCurlyBrace.ScopeChanged)
                {
                    scope.Pop();
                }
                return(true);

            case '(':
                brace.Push(tokens.Add(new Token(stream.Position, 1, stream.Line, TokenType.OpenFunctionBrace, context.Current)), scope.Changed);
                stream.Advance();
                return(true);

            case ')':
                var openFunctionBrace = brace.Pop(TokenType.OpenFunctionBrace);
                token = tokens.Add(new Token(stream.Position, 1, stream.Line, TokenType.CloseFunctionBrace, context.Current, null, openFunctionBrace.Token));
                if (openFunctionBrace.Token != null)
                {
                    openFunctionBrace.Token.MatchingToken = token;
                }
                stream.Advance();

                if (openFunctionBrace.ScopeChanged)
                {
                    scope.Pop();
                }
                return(true);
            }

            if (scope.Current == Scope.Block)
            {
                return(false);
            }

            var name = stream.PeekWord();

            if (name == null)
            {
                return(false);
            }

            if (keywords.Contains(name))
            {
                tokens.Add(new Token(stream.Position, name.Length, stream.Line, TokenType.Keyword, context.Current));
            }

            stream.Advance(name.Length);
            return(true);
        }