Example #1
0
 private IEnumerable StringMode(Itr itr)
 {
     if (currentItem.Length == 0)
     {
         currentItem.Append('"');
     }
     currentItem.Append(itr.Current());
     if (SwitchMode(itr.Mode))
     {
         yield return(PopString(currentItem));
     }
     else
     {
         if (itr.IsFinalIndex())
         {
             currentItem.Append('"');
             yield return(PopString(currentItem));
         }
         else if ('\\'.Equals(itr.Current()))
         {
             currentItem.Append(itr.Peek(1));
             itr.MoveNext(); //don't check next character since already added
         }
     }
 }
Example #2
0
 private static string TrimWhiteSpace(string input, Itr itr)
 {
     if (input == null)
     {
         throw new NullReferenceException("input cannot be null");
     }
     return(input.TrimStart());
 }
Example #3
0
 private static bool MatchDoubleSymbolDelimiter(Delimiter[] delimiters, Itr itr)
 {
     foreach (Delimiter del in delimiters)
     {
         if (itr == del.toMatch)
         {
             return(true);
         }
     }
     return(false);
 }
Example #4
0
 private IEnumerable <string> NormalMode(Itr itr)
 {
     if (!SwitchMode(itr.Mode))
     {
         if (' '.Equals(itr.Current()))
         {
             if (currentItem.Length > 0)
             {
                 yield return(PopString(currentItem));
             }
         }
         else if (SplitOnDot(itr))
         {
             if (currentItem.Length > 0)
             {
                 yield return(PopString(currentItem));
             }
             yield return(itr.Current().ToString());
         }
         else if (MatchDoubleSymbolDelimiter(__multi_symbol_delimiters__, itr))
         {
             if (currentItem.Length > 0)
             {
                 yield return(PopString(currentItem));
             }
             currentItem.Append(itr.Current());
             currentItem.Append(itr.Peek(1));
             itr.MoveNext();
         }
         else if (MatchDelimiter(__Updated_Delimiters__, itr))
         {
             if (currentItem.Length > 0)
             {
                 yield return(PopString(currentItem));
             }
             yield return(itr.Current().ToString());
         }
         else
         {
             currentItem.Append(itr.Current());
         }
         if (itr.IsFinalIndex() && currentItem.Length > 0)
         {
             yield return(PopString(currentItem));
         }
     }
     else if (itr.Current() != ' ' && currentItem.Length > 0)
     {
         yield return(PopString(currentItem));
     }
 }
Example #5
0
        private static bool SplitOnDot(Itr itr)
        {
            if (itr == ".")
            {
                if (itr.IsFirstIndex() || itr.Peek(-1) == ' ')              //dot is first index or white space
                {
                    if (!itr.IsFinalIndex())                                //not final index
                    {
                        if (Regex.IsMatch(itr.Peek(1).ToString(), @"[\d]")) //digit
                        {
                            return(false);
                        }
                    }
                }

                if (itr.IsFirstIndex() || itr.Peek(-1) == '.')
                {
                    return(true);
                }

                if (Regex.IsMatch(itr.Peek(-1).ToString(), @"[\d]")) //if it's got a digit before
                {
                    int i = -2;
                    while (true)
                    {
                        if (Regex.IsMatch(itr.Peek(i).ToString(), @"[\D]"))     //not a digit
                        {
                            if (Regex.IsMatch(itr.Peek(i).ToString(), @"[\w]")) //is a word character
                            {
                                return(true);
                            }
                        }

                        if (itr.Index + --i < 0)
                        {
                            break;
                        }
                    }
                }
            }
            return(false);
        }
Example #6
0
        private static bool MatchDelimiter(Delimiter[] delimiters, Itr itr)
        {
            foreach (Delimiter del in delimiters)
            {
                if (itr != del.toMatch)
                {
                    continue;
                }

                if (del.RegexPostMatch != null)
                {
                    if (itr.IsFinalIndex())
                    {
                        return(false);
                    }
                    if (!Regex.IsMatch(itr.Peek(1).ToString(), del.RegexPostMatch))
                    {
                        continue;
                    }
                }
                else if (del.PostMatch != null)
                {
                    var match = false;
                    foreach (string str in del.PostMatch)
                    {
                        if (itr.PeekAndEquals(del.toMatch.Length, str))
                        {
                            match = true;
                            break;
                        }
                    }
                    if (!match)
                    {
                        continue;
                    }
                }

                if (del.RegexPreMatch != null)
                {
                    if (itr.IsFirstIndex())
                    {
                        return(false);
                    }
                    if (!Regex.IsMatch(itr.Peek(-1).ToString(), del.RegexPreMatch))
                    {
                        continue;
                    }
                }
                else if (del.PreMatch != null)
                {
                    var match = false;
                    foreach (string str in del.PreMatch)
                    {
                        if (itr.PeekAndEquals(-str.Length, str))
                        {
                            match = true;
                            break;
                        }
                    }
                    if (!match)
                    {
                        continue;
                    }
                }

                return(true);
            }
            return(false);
        }
Example #7
0
 private void CommentMode(Itr itr)
 {
     SwitchMode(itr.Mode);
 }