Ejemplo n.º 1
0
        public void ProcessChar(char input, ParserStateMachine sm)
        {
            if (char.IsDigit(input))
            {
                sm.NextState = new OLState();
                return;
            }

            switch (input)
            {
                case '#':
                    sm.NextState = new Header1State();
                    break;
                case '`':
                    sm.NextState = new CodeState();
                    break;
                //case '*':
                //case '+':
                //case '-':
                //    sm.NextState = new ULState();
                //    break;
                case ' ':
                case '\n':
                case '\r':
                    break;
                default:
                    sm.NextState = new ParagraphState();
                    sm.NextState.ProcessChar(input, sm);
                    break;
            }
        }
Ejemplo n.º 2
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     if (!ShouldIgnoreChar(input))
     {
         this.OnHeaderComplete(input, sm);
         this.header.Append(input);
     }
 }
Ejemplo n.º 3
0
 private void ChangeState(char input, ParserStateMachine sm)
 {
     var newListItemDetected = input.Equals('@');
     if (!this.orderedList.SubElements.Any() || newListItemDetected)
     {
         sm.NextState = new ListItemState(this);
     }
 }
Ejemplo n.º 4
0
 protected void OnHeaderComplete(char input, ParserStateMachine sm)
 {
     if (input.Equals('\n'))
     {
         this.AddHeader(sm);
         sm.NextState = new EntryState();
     }
 }
Ejemplo n.º 5
0
 private void OnListCompleted(char input, ParserStateMachine sm)
 {
     var isListCompleted = input.Equals('&');
     if (isListCompleted)
     {
         sm.MdDoc.AddOrderedList(this.orderedList);
         sm.NextState = new EntryState();
     }
 }
Ejemplo n.º 6
0
 private void OnCodeCompleted(char input, ParserStateMachine sm)
 {
     if (this.IsElemCompleted(input))
     {
         this.AddLineTerminators(input);
         sm.MdDoc.AddCode(
             new Code(this.code.ToString()));
         sm.NextState = new EntryState();
     }
 }
Ejemplo n.º 7
0
        public void ProcessChar(char input, ParserStateMachine sm)
        {
            this.OnLinkIdCompleted(input);
            this.OnLinkCompleted(input, sm);

            if (ShouldAddChar(input))
            {
                this.builder.Append(input);
            }
        }
Ejemplo n.º 8
0
 private void OnLinkCompleted(char input, ParserStateMachine sm)
 {
     if (input.Equals('>') || input.Equals(')'))
     {
         sm.NextState = this.initialState;
         this.initialState.OnSubElementCompleted(
             new LinkItem(
                 this.link.Length > 0 ? this.link.ToString() : this.id.ToString(),
                 this.id.ToString()));
     }
 }
Ejemplo n.º 9
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     if (this.ShouldChangeState(input))
     {
         sm.NextState = new Header4State();
     }
     else if (!ShouldIgnoreChar(input))
     {
         this.OnHeaderComplete(input, sm);
         this.header.Append(input);
     }
 }
Ejemplo n.º 10
0
        public void ProcessChar(char input, ParserStateMachine sm)
        {
            if (this.initialState == null)
            {
                this.OnCodeCompleted(input, sm);
            }
            else
            {
                this.OnSubElemCompleted(input, sm);
            }

            this.AppendChar(input);
        }
Ejemplo n.º 11
0
        private void OnTextElemCompleted(char input, ParserStateMachine sm)
        {
            var isLinkItem = input.Equals('[') || input.Equals('<');
            var isTextCompleted = input.Equals('\n') || input.Equals('\r');
            var isCodeItem = input.Equals('`');
            this.AddLineTerminators(isTextCompleted);

            if (isTextCompleted || isLinkItem || isCodeItem)
            {
                sm.NextState = initialState;
                this.initialState.OnSubElementCompleted(
                    new TextItem(this.textBuilder.ToString()));
                sm.NextState.ProcessChar(input, sm);
            }
        }
Ejemplo n.º 12
0
 private void OnParagraphCompleted(char input, ParserStateMachine sm)
 {
     //we assume that a new line followed by a carriage return means end on list
     if (isEndPending)
     {
         if (input.Equals('\r'))
         {
             sm.MdDoc.AddParagraph(this.paragraph);
             sm.NextState = new EntryState();
         }
         else
         {
             isEndPending = false;
         }
     }
 }
Ejemplo n.º 13
0
        public void ProcessChar(char input, ParserStateMachine sm)
        {
            this.OnListItemCompleted(input, sm);
            if (ShouldParseChar(input))
            {
                switch (input)
                {
                    case '`':
                        sm.NextState = new CodeState(this);
                        break;
                    case '[':
                    case '<':
                        sm.NextState = new LinkState(this);
                        break;
                    default:
                        sm.NextState = new TextState(this);
                        sm.NextState.ProcessChar(input, sm);
                        break;
                }
            }

            isEndPending = input.Equals('\n') || this.isListItemEndPending;
        }
Ejemplo n.º 14
0
 private void OnListItemCompleted(char input, ParserStateMachine sm)
 {
     //we assume that a digit on a new line means new list item
     //we also assume that a new line followed by a carriage return means end on list
     var isListEndPending = input.Equals('\r');
     if (this.isEndPending)
     {
         if (isListItemEndPending)
         {
             if (input.Equals('.'))
             {
                 sm.NextState = this.initialState;
                 this.initialState.OnSubElementCompleted(this.listItem);
                 sm.NextState.ProcessChar(newListItemChar, sm);
             }
             else
             {
                 this.isListItemEndPending = false;
                 this.isEndPending = false;
             }
         }
         else if (isListEndPending && !this.isListItemEndPending)
         {
             sm.NextState = this.initialState;
             this.initialState.OnSubElementCompleted(this.listItem);
             sm.NextState.ProcessChar(endListChar, sm);
         }
         else if (char.IsDigit(input))
         {
             this.isListItemEndPending = true;
         }
         else
         {
             this.isEndPending = false;
         }
     }
 }
Ejemplo n.º 15
0
 protected override void AddHeader(ParserStateMachine sm)
 {
     sm.MdDoc.AddHeader(
         new Header3(this.header.ToString()));
 }
Ejemplo n.º 16
0
 private void OnSubElemCompleted(char input, ParserStateMachine sm)
 {
     if (IsElemCompleted(input))
     {
         this.AddLineTerminators(input);
         sm.NextState = this.initialState;
         this.initialState.OnSubElementCompleted(
             new Code(this.code.ToString()));
         this.initialState.ProcessChar(input, sm);
     }
 }
Ejemplo n.º 17
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     this.OnListCompleted(input, sm);
     this.ChangeState(input, sm);
 }
Ejemplo n.º 18
0
 protected abstract void AddHeader(ParserStateMachine sm);
Ejemplo n.º 19
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 20
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     this.OnTextElemCompleted(input, sm);
     this.textBuilder.Append(input);
 }