예제 #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;
            }
        }
예제 #2
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     if (!ShouldIgnoreChar(input))
     {
         this.OnHeaderComplete(input, sm);
         this.header.Append(input);
     }
 }
예제 #3
0
 private void ChangeState(char input, ParserStateMachine sm)
 {
     var newListItemDetected = input.Equals('@');
     if (!this.orderedList.SubElements.Any() || newListItemDetected)
     {
         sm.NextState = new ListItemState(this);
     }
 }
예제 #4
0
 protected void OnHeaderComplete(char input, ParserStateMachine sm)
 {
     if (input.Equals('\n'))
     {
         this.AddHeader(sm);
         sm.NextState = new EntryState();
     }
 }
예제 #5
0
 private void OnListCompleted(char input, ParserStateMachine sm)
 {
     var isListCompleted = input.Equals('&');
     if (isListCompleted)
     {
         sm.MdDoc.AddOrderedList(this.orderedList);
         sm.NextState = new EntryState();
     }
 }
예제 #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();
     }
 }
예제 #7
0
        public void ProcessChar(char input, ParserStateMachine sm)
        {
            this.OnLinkIdCompleted(input);
            this.OnLinkCompleted(input, sm);

            if (ShouldAddChar(input))
            {
                this.builder.Append(input);
            }
        }
예제 #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()));
     }
 }
예제 #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);
     }
 }
예제 #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);
        }
예제 #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);
            }
        }
예제 #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;
         }
     }
 }
예제 #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;
        }
예제 #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;
         }
     }
 }
예제 #15
0
 protected override void AddHeader(ParserStateMachine sm)
 {
     sm.MdDoc.AddHeader(
         new Header3(this.header.ToString()));
 }
예제 #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);
     }
 }
예제 #17
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     this.OnListCompleted(input, sm);
     this.ChangeState(input, sm);
 }
예제 #18
0
 protected abstract void AddHeader(ParserStateMachine sm);
예제 #19
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     throw new NotImplementedException();
 }
예제 #20
0
 public void ProcessChar(char input, ParserStateMachine sm)
 {
     this.OnTextElemCompleted(input, sm);
     this.textBuilder.Append(input);
 }