Beispiel #1
0
 public ElifBlock()
 {
     Type           = BlockType.ELIF;
     Begin          = new string[] { "elif " };
     End            = new string[] { };
     AllowedContent = new BlockType[] {
         BlockType.THEN,
         BlockType.COMMAND,
     };
     ConstraintsContent.Add(ContentConstraint.OneOfEachType());
 }
Beispiel #2
0
        public virtual void Eat(ref string script)
        {
            // eat beginning
            foreach (string begin in Begin)
            {
                if (script.StartsWith(begin))
                {
                    script = script.Substring(begin.Length);
                    break;
                }
            }

            // eat content
            bool full = false;

            while (script.Length > 0)
            {
                int previousLength = script.Length;

                if (EndsWith(script: ref script))
                {
                    break;
                }

                if (ConstraintsContent.Any(constraint => constraint(this)))
                {
                    // content is full!
                    full = true;
                    break;
                }

                foreach (BlockType blockType in AllowedContent)
                {
                    Block block = Blocks.CreateBlock(blockType);
                    if (block.StartsWith(script: ref script))
                    {
                        if (ConstraintsAddContent.Any(constraint => constraint(this, blockType)))
                        {
                            // content is full!
                            full = true;
                            break;
                        }

                        block.Eat(script: ref script);
                        if (block.IsValid)
                        {
                            Content.Add(block);
                        }
                        break;
                    }
                }

                if (!full && previousLength == script.Length)
                {
                    Log.Warning("Stuck at: ");
                    Log.Indent++;
                    Log.Warning(script);
                    Log.Indent--;
                    break;
                }
            }

            // trim script start
            Blocks.TrimStart(script: ref script);
        }