private void BuildInstructionsForOneToken(IList <FormattedSentence.IInstructionQueueMember> instructionQueue, FormattedSentence.Token token)
        {
            FormattedSentence.Sentence    sentence    = token as FormattedSentence.Sentence;
            FormattedSentence.SimpleToken simpleToken = token as FormattedSentence.SimpleToken;
            if (sentence != null)
            {
                this.BuildInstructionQueue(instructionQueue, sentence);
                return;
            }
            if (simpleToken == null)
            {
                return;
            }
            switch (simpleToken.Flavor)
            {
            case FormattedSentence.SimpleToken.TokenFlavor.None:
                instructionQueue.Add(new FormattedSentence.StringConstant(simpleToken.Value));
                return;

            case FormattedSentence.SimpleToken.TokenFlavor.InCurlyBraces:
                instructionQueue.Add(new FormattedSentence.ResolvePlaceholder(simpleToken.Value));
                return;

            default:
                throw new NotSupportedException("Token flavor is not supported");
            }
        }
        protected void BuildInstructionQueue(IList <FormattedSentence.IInstructionQueueMember> instructionQueue, FormattedSentence.Sentence sentence)
        {
            if (sentence.Tokens.Count == 0)
            {
                instructionQueue.Add(FormattedSentence.StringConstant.EmptySpacer);
                return;
            }
            if (sentence.Tokens.Count == 1)
            {
                this.BuildInstructionsForOneToken(instructionQueue, sentence.Tokens[0]);
                return;
            }
            bool flag = false;
            int  num  = 0;

            for (int i = 0; i < sentence.Tokens.Count; i++)
            {
                FormattedSentence.SimpleToken simpleToken = sentence.Tokens[i] as FormattedSentence.SimpleToken;
                bool flag2 = simpleToken != null && simpleToken.Flavor == FormattedSentence.SimpleToken.TokenFlavor.None;
                if (i == 0 && flag2)
                {
                    instructionQueue.Add(FormattedSentence.StringConstant.Null);
                    num++;
                }
                if (i > 0 && !flag && !flag2)
                {
                    instructionQueue.Add(FormattedSentence.StringConstant.EmptySpacer);
                    num++;
                }
                this.BuildInstructionsForOneToken(instructionQueue, sentence.Tokens[i]);
                num++;
                flag = flag2;
            }
            if (flag)
            {
                instructionQueue.Add(FormattedSentence.StringConstant.Null);
                num++;
            }
            int num2 = (num - 1) / 2;

            for (int j = 0; j < num2; j++)
            {
                instructionQueue.Add(new FormattedSentence.ConditionalDelimiter());
            }
        }
            private static int Parse(string input, int startAt, out FormattedSentence.Sentence sentence)
            {
                FormattedSentence.SimpleToken.Builder builder = new FormattedSentence.SimpleToken.Builder(null, FormattedSentence.SimpleToken.TokenFlavor.None, -1);
                List <FormattedSentence.Token>        list    = new List <FormattedSentence.Token>();
                int  num  = startAt - 1;
                bool flag = false;

                while (!flag)
                {
                    num++;
                    if (num > input.Length)
                    {
                        throw new FormatException("Unexpected end of escape sequence. If '' was intended for output, replace it with '\\'");
                    }
                    if (num == input.Length)
                    {
                        break;
                    }
                    char c  = input[num];
                    char c2 = c;
                    switch (c2)
                    {
                    case '<':
                    {
                        FormattedSentence.Sentence.AddTokenFlavorNone(list, num - 1, ref builder);
                        FormattedSentence.Sentence item;
                        num = FormattedSentence.Sentence.Parse(input, num + 1, out item);
                        if (num >= input.Length || input[num] != '>')
                        {
                            throw new FormatException("'<' is mismatched or not properly escaped");
                        }
                        list.Add(item);
                        continue;
                    }

                    case '=':
                        break;

                    case '>':
                        flag = true;
                        continue;

                    default:
                        switch (c2)
                        {
                        case '{':
                            FormattedSentence.Sentence.AddTokenFlavorNone(list, num - 1, ref builder);
                            builder = new FormattedSentence.SimpleToken.Builder(input, FormattedSentence.SimpleToken.TokenFlavor.InCurlyBraces, num + 1);
                            continue;

                        case '}':
                            if (!builder.IsValid || builder.Flavor != FormattedSentence.SimpleToken.TokenFlavor.InCurlyBraces)
                            {
                                throw new FormatException("'}' is mismatched or not escaped");
                            }
                            FormattedSentence.Sentence.AddToken(list, num - 1, ref builder);
                            continue;
                        }
                        break;
                    }
                    if (!builder.IsValid)
                    {
                        builder = new FormattedSentence.SimpleToken.Builder(input, FormattedSentence.SimpleToken.TokenFlavor.None, num);
                    }
                    if (c == '\\')
                    {
                        num++;
                    }
                }
                FormattedSentence.Sentence.AddTokenFlavorNone(list, num - 1, ref builder);
                sentence = new FormattedSentence.Sentence(list);
                return(num);
            }