protected virtual void Parse()

in EFCore/src/Query/Internal/MySQLCommandParser.cs [103:285]


    protected virtual void Parse()
    {
      var state = '\0';
      var lastChar = '\0';
      var secondTolastChar = '\0';

      for (var i = 0; i < SqlFragment.Length; i++)
      {
        var c = SqlFragment[i];
        var skipProcessing = false;

        if (state == '\'')
        {
          if (c == '\'')
          {
            if (lastChar == '\'')
              lastChar = '\0';
            else
              lastChar = '\'';
          }
          else if (lastChar == '\'')
          {
            state = '\0';
            lastChar = '\0';
            States[i - 1] = state;
          }
        }

        if (state == '"')
        {
          if (c == '"')
          {
            if (lastChar == '"')
              lastChar = '\0';
            else
              lastChar = '"';
          }
          else if (lastChar == '"')
          {
            state = '\0';
            lastChar = '\0';
            States[i - 1] = state;
          }
        }

        if (state == '`')
        {
          if (c == '`')
          {
            if (lastChar == '`')
              lastChar = '\0';
            else
              lastChar = '`';
          }
          else if (lastChar == '`')
          {
            state = '\0';
            lastChar = '\0';
            States[i - 1] = state;
          }
        }

        if (state == '/')
        {
          if (lastChar == '/')
          {
            Debug.Assert(c == '*');
            lastChar = '\0';
          }
          else if (lastChar == '*')
          {
            if (c == '/')
            {
              lastChar = '\0';
              state = '\0';
              skipProcessing = true;
            }
            else
              lastChar = '\0';
          }
          else if (c == '*')
          {
            Debug.Assert(lastChar == '\0');
            lastChar = '*';
          }
          else
            lastChar = '\0';
        }

        if (state == '-')
        {
          if (lastChar == '-')
          {
            if (c == '-' && secondTolastChar == '\0')
              secondTolastChar = '-';
            else if (secondTolastChar == '-' && (c == ' ' || c == '\t'))
            {
              lastChar = '\0';
              secondTolastChar = '\0';
            }
            else
            {
              state = '\0';
              lastChar = '\0';
              States[i - 1] = state;

              if (secondTolastChar == '-')
              {
                secondTolastChar = '\0';
                States[i - 2] = state;
              }
            }
          }
          else
          {
            Debug.Assert(lastChar == '\0');
            Debug.Assert(secondTolastChar == '\0');

            if (c == '\r' || c == '\n')
            {
              state = '\0';
              skipProcessing = true;
            }
          }
        }

        if (state == '#')
        {
          if (c == '\r' || c == '\n')
          {
            state = '\0';
            skipProcessing = true;
          }
        }

        if (state == '\0' && !skipProcessing)
        {
          if (c == '"')
            state = '"';
          else if (c == '\'')
            state = '\'';
          else if (c == '`')
            state = '`';
          else if (c == '/')
          {
            state = '/';
            lastChar = '/';
          }
          else if (c == '-')
          {
            state = '-';
            lastChar = '-';
          }
          else if (c == '#')
            state = '#';
          else if (c == '@')
            state = '@';
          else if (c == ';')
            States[i] = ';';
        }
        else if (state == '@')
        {
          if (c == '@')
            States[i - 1] = '$';

          state = '\0';
        }

        if (state != '\0')
          States[i] = state;
      }

      if (state == '\'' && lastChar == '\'' ||
          state == '"' && lastChar == '"' ||
          state == '`' && lastChar == '`' ||
          state == '/' && lastChar == '/' ||
          state == '-' && lastChar == '-')
      {
        state = '\0';
        lastChar = '\0';
        States[States.Length - 1] = state;
      }
    }