Ejemplo n.º 1
0
 static DocEntity CopyAndReset(ref DocEntity entity)
 {
     DocEntity result = new DocEntity
     {
         Type = entity.Type,
         State = entity.State,
         Argument = entity.Argument,
     };
     entity = CreateEmptyTextEntity();
     return result;
 }
Ejemplo n.º 2
0
        static DocEntity CopyAndReset(ref DocEntity entity)
        {
            DocEntity result = new DocEntity
            {
                Type     = entity.Type,
                State    = entity.State,
                Argument = entity.Argument,
            };

            entity = CreateEmptyTextEntity();
            return(result);
        }
Ejemplo n.º 3
0
        static IEnumerable <DocEntity> ParseLine(string line)
        {
            if (line.StartsWith("/codebegin:"))
            {
                yield return(new DocEntity
                {
                    Type = DocEntityType.Code,
                    State = DocEntityState.Close,
                    Argument = line.Substring("/codebegin:".Length),
                });
            }
            else if (line == "/codeend")
            {
                yield return(new DocEntity
                {
                    Type = DocEntityType.Code,
                    State = DocEntityState.Close,
                    Argument = "",
                });
            }
            else
            {
                ParseState state  = ParseState.Text;
                DocEntity  entity = CreateEmptyTextEntity();
                foreach (char c in line)
                {
                    switch (state)
                    {
                    case ParseState.Text:
                    {
                        if (c == '/')
                        {
                            if (entity.Argument != "")
                            {
                                yield return(CopyAndReset(ref entity));
                            }
                            state = ParseState.Slash;
                        }
                        else
                        {
                            entity.Argument += c;
                        }
                    }
                    break;

                    case ParseState.Slash:
                    {
                        switch (c)
                        {
                        case '+':
                            entity.State = DocEntityState.Open;
                            state        = ParseState.SlashName;
                            break;

                        case '-':
                            entity.State = DocEntityState.Close;
                            state        = ParseState.SlashName;
                            break;

                        default:
                            entity.Argument += c;
                            state            = ParseState.SlashName;
                            break;
                        }
                    }
                    break;

                    case ParseState.SlashName:
                    {
                        switch (c)
                        {
                        case '/':
                            entity.Type     = GetType(entity.Argument);
                            entity.Argument = "";
                            yield return(CopyAndReset(ref entity));

                            state = ParseState.Text;
                            break;

                        case ':':
                            entity.Type     = GetType(entity.Argument);
                            entity.Argument = "";
                            state           = ParseState.WaitingForParam;
                            break;

                        default:
                            entity.Argument += c;
                            break;
                        }
                    }
                    break;

                    case ParseState.WaitingForParam:
                    {
                        switch (c)
                        {
                        case '/':
                            yield return(CopyAndReset(ref entity));

                            state = ParseState.Text;
                            break;

                        case '"':
                            state = ParseState.InParamQuot;
                            break;

                        default:
                            entity.Argument += c;
                            state            = ParseState.InParam;
                            break;
                        }
                    }
                    break;

                    case ParseState.InParamQuot:
                    {
                        switch (c)
                        {
                        case '"':
                            state = ParseState.OutParamQuot;
                            break;

                        default:
                            entity.Argument += c;
                            break;
                        }
                    }
                    break;

                    case ParseState.OutParamQuot:
                    {
                        switch (c)
                        {
                        case '/':
                            yield return(CopyAndReset(ref entity));

                            state = ParseState.Text;
                            break;

                        default:
                            throw new ArgumentException("'/' expected after quot argument。");
                        }
                    }
                    break;

                    case ParseState.InParam:
                    {
                        switch (c)
                        {
                        case '/':
                            yield return(CopyAndReset(ref entity));

                            state = ParseState.Text;
                            break;

                        default:
                            entity.Argument += c;
                            break;
                        }
                    }
                    break;
                    }
                }
                if (entity.Type == DocEntityType.Text && entity.Argument != "")
                {
                    yield return(entity);
                }
            }
        }