⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mysqlparser.pas

📁 MYSQL 连接控件 MYSQL 连接控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  ErrorStr(Format(Ident, Args));
end;

{-----------------------------------------------------}

procedure TBasicParser.ErrorStr(const Message: string);
begin
  raise EBasicParserError.CreateResFmt(@SParseError, [Message, FSourceLine+1]);
end;

{-----------------------------------------------------}

function TBasicParser.NextToken(SkipAllBlanks: boolean): TTokenProps;
var
  I, J: Integer;
  P, S: PChar;
begin
  SkipBlanks(SkipAllBlanks);
  P := FSourcePtr;
  FTokenPtr := P;
  Result := FToken;

  if not (SkipAllBlanks) and (FSourcePtr^ in [#10, #13]) then begin
    FToken.TokenType := tsEOL;
    FToken.TokenPos := SourcePos;
    FToken.TokenStr := ' ';
    Inc(FSourcePtr);
    Inc(FTokenPtr);
    exit
  end;

  if (FSourcePtr^ in [';']) then begin
    FToken.TokenType := tsEOS;
    FToken.TokenPos := SourcePos;
    FToken.TokenStr := ';';
    Inc(FSourcePtr);
    Inc(FTokenPtr);
    exit
  end;

  if Length(FHexDelim) = 2 then begin
    if P^ = FHexDelim[1] then begin
      Inc(P);
      if P^ = FHexDelim[2] then begin
        Inc(P);
        while P^ in ['0'..'9', 'A'..'F', 'a'..'f'] do Inc(P);
        FSourcePtr := P;
        FToken.TokenType := tsHex;
        FToken.TokenPos := SourcePos;
        FToken.TokenStr := TokenString;
        exit
      end
      else Dec(P)
    end;
  end;

  if Length(FHexDelim) = 1 then begin
    if P^ = FHexDelim then begin
      Inc(P);
      while P^ in ['0'..'9', 'A'..'F', 'a'..'f'] do Inc(P);
      FSourcePtr := P;
      FToken.TokenType := tsHex;
      FToken.TokenPos := SourcePos;
      FToken.TokenStr := TokenString;
      exit
    end;
  end;

  for I := 0 to FOneLineComment.Count-1 do begin
    if StrLComp(P, PChar(FOneLineComment[I]), Length(FOneLineComment[I]))=0 then begin
      Inc(P, Length(FOneLineComment[I]));
      while not (P^ in [#0, #10, #13]) do Inc(P);
      FSourcePtr := P;
      FToken.TokenType := tsComment;
      FToken.TokenPos := SourcePos;
      FToken.TokenStr := TokenString;
      exit
    end
  end;

  for I := 0 to FCommentStart.Count-1 do begin
    if StrLComp(P, PChar(FCommentStart[I]), Length(FCommentStart[I]))=0 then begin
      Inc(P, Length(FCommentStart[I]));
      while (StrLComp(P, PChar(FCommentEnd[I]), Length(FCommentEnd[I]))<>0) and
            (P^ <> tsEOF) do Inc(P);
      if not (P^ = tsEOF) then
        Inc(P, Length(FCommentEnd[I]));
      FSourcePtr := P;
      FToken.TokenType := tsCommentML;
      FToken.TokenPos := SourcePos;
      FToken.TokenStr := TokenString;
      exit
    end
  end;

  for I := 0 to FCommentEnd.Count-1 do begin
    if (StrLComp(P, PChar(FCommentEnd[I]), Length(FCommentEnd[I]))=0) then begin
      Inc(P, Length(FCommentEnd[I]));
      FSourcePtr := P;
      FToken.TokenType := tsCommentMLEnd;
      FToken.TokenPos := SourcePos;
      FToken.TokenStr := TokenString;
      exit
    end
  end;

  for I := 0 to FMacroStart.Count-1 do begin
    if StrLComp(P, PChar(FMacroStart[I]), Length(FMacroStart[I]))=0 then begin
      Inc(P, Length(FMacroStart[I]));
      while (StrLComp(P, PChar(FMacroEnd[I]), Length(FMacroEnd[I]))<>0) and
            not(P^ in [tsEOF,#10,#13,' ']) do Inc(P);
      if not(P^ = tsEOF) then Inc(P, Length(FMacroEnd[I]));
      FSourcePtr := P;
      FToken.TokenType := tsMacro;
      FToken.TokenPos := SourcePos;
      FToken.TokenStr := TokenString;
      exit
    end
  end;

  for I := 0 to FMacroEnd.Count-1 do begin
    if (StrLComp(P, PChar(FMacroEnd[I]), Length(FMacroEnd[I]))=0) then begin
      Inc(P, Length(FMacroEnd[I]));
      FSourcePtr := P;
      FToken.TokenType := tsMacro;
      FToken.TokenPos := SourcePos;
      FToken.TokenStr := TokenString;
      exit
    end
  end;

  for I := 0 to FParamStart.Count-1 do begin
    if (StrLComp(P, PChar(FParamStart[I]), Length(FParamStart[I]))=0) then begin
      Inc(P, Length(FParamStart[I]));
      if not(P^ in ['A'..'Z','a'..'z','0'..'9','_']) then 
        Dec(P, Length(FParamStart[I]))
      else begin
        while (P^ in ['A'..'Z','a'..'z','0'..'9','_']) do Inc(P);
         //while not(P^ in [tsEOF,#10,#13,';',' ','(',')']) do Inc(P);
         FSourcePtr := P;
         FToken.TokenType := tsParam;
         FToken.TokenPos := SourcePos;
         FToken.TokenStr := TokenString;
         exit
      end;
    end
  end;

  for I := 0 to FOperators.Count-1 do begin
    if (StrLComp(P, PChar(FOperators[I]), Length(FOperators[I]))=0) then begin
      Inc(P, Length(FOperators[I]));
      FSourcePtr := P;
      FToken.TokenType := tsOperator;
      FToken.TokenPos := SourcePos;
      FToken.TokenStr := TokenString;
      exit
    end
  end;

  case P^ of
    'A'..'Z', 'a'..'z', '_', '|','$','&':
      begin
        Inc(P);
        while P^ in ['A'..'Z', 'a'..'z', '0'..'9', '_', '|','$','&'] do Inc(P);
        FToken.TokenType := tsSymbol;
      end;
    '''': //Added: '"' Author: Antonie Neethling Date: 2000/03/29  ????? -> '\\'
      begin
      	S := P;
      	Inc(P);
        while true do begin
          if P^ in [#0, #10, #13] then break;
          //BEGIN: Added Antonie
          if (P^='\') and (S^='\') then begin
            S := P;
          	Inc(P);
            if P^='''' then break
          end;
          //END: Added Antonie
          if (P^ in ['''']) and (S^ <> '\') then break;
          S := P;
          Inc(P)
        end;
        if (P^ in ['''']) then Inc(P);
        FStringPtr := P;
        FToken.TokenType := tsString;
      end;
    '"': //Added: '"' Author: Antonie Neethling Date: 2000/03/29
      begin
      	S := P;
      	Inc(P);
        while true do begin
          if P^ in [#0, #10, #13] then break;
          //BEGIN: Added Antonie
          if (P^='\') and (S^='\') then begin
            S := P;
          	Inc(P);
            if P^='"' then break
          end;
          //END: Added Antonie
          if (P^ in ['"']) and (S^ <> '\') then break;
          S := P;
          Inc(P)
        end;
        if (P^ in ['"']) then Inc(P);
        FStringPtr := P;
        FToken.TokenType := tsString;
      end;
    '`': //Added: '"' Author: Antonie Neethling Date: 2000/03/29
      begin
      	Inc(P);
        while true do begin
          if (P^ in ['`']) then break;
          Inc(P)
        end;
        if (P^ in ['`']) then Inc(P);
        FStringPtr := P;
        FToken.TokenType := tsSymbol;
      end;
    '0'..'9':
      begin
        J := 0;
        Inc(P);
        while P^ in ['0'..'9'] do Inc(P);
        FToken.TokenType := tsInteger;
        if P^ in ['.', 'e', 'E'] then begin
          while P^ in ['0'..'9', '.', 'e', 'E', '+', '-'] do begin
            if P^ in ['+','-'] then Inc(J);
            if J>=2 then break;
            Inc(P);
            FToken.TokenType := tsFloat;
          end;
          if (P^ in ['c', 'C', 'd', 'D', 's', 'S']) then begin
            FToken.TokenType := tsFloat;
            FFloatType := P^;
            Inc(P);
          end else
            FFloatType := #0;
        end;
      end
  else
    FToken.TokenType := P^;
    if FToken.TokenType <> tsEOF then Inc(P);
  end;

  FSourcePtr := P;
  FToken.TokenPos := SourcePos;
  FToken.TokenStr := TokenString;
end;

{-----------------------------------------------------}

procedure TBasicParser.SkipBlanks(SkipAllBlanks: boolean);
begin
  while True do
  begin
    case FSourcePtr^ of
      #0: exit;
      #10: begin
        if SkipAllBlanks then
          Inc(FSourceLine)
        else
          Exit;
      end;
      #33..#255:
        Exit;
    end;
    Inc(FSourcePtr);
  end;
end;

{-----------------------------------------------------}

procedure TBasicParser.TokenAtPosition(Position: longint);
var
  tp: TTokenPosition;
begin
  for tp := tpPrevious to tpNext do
    with RegionTokens[tp] do begin
      TokenPos := 0;
      TokenType := tsUndefined;
      TokenStr := '';
    end;

  while (Position >= SourcePos) do begin
    with RegionTokens[tpPrevious] do begin
      TokenPos := FToken.TokenPos;
      TokenType := FToken.TokenType;
      TokenStr := FToken.TokenStr;
    end;

    NextToken(true);

    with RegionTokens[tpCurrent] do begin
      TokenPos := FToken.TokenPos;
      TokenType := FToken.TokenType;
      TokenStr := FToken.TokenStr;
    end;

    if (Position = SourcePos) or
       ((Position > SourcePos) and (Position <= SourcePos + Length(TokenString))) then begin
      break;
    end;
    if FToken.TokenType = tsEOF then break;
  end;

  if FToken.TokenType <> tsEOF then begin
    NextToken(true);
    with RegionTokens[tpNext] do begin
      TokenPos := FToken.TokenPos;
      TokenType := FToken.TokenType;
      TokenStr := FToken.TokenStr;
    end;
  end;
end;

{-----------------------------------------------------}

function TBasicParser.SourcePos: Longint;
begin
  Result := FOrigin + (FTokenPtr - FBuffer);
end;

{-----------------------------------------------------}

function TBasicParser.TokenFloat: Extended;
begin
  if FFloatType <> #0 then Dec(FSourcePtr);
  Result := StrToFloat(TokenString);
  if FFloatType <> #0 then Inc(FSourcePtr);
end;

{-----------------------------------------------------}

function TBasicParser.TokenInt: Int64;
begin
  Result := StrToInt64(TokenString);
end;

{-----------------------------------------------------}

function TBasicParser.TokenString: string;
var
  L: Integer;
begin
  if FToken.TokenType = tsString then L := FStringPtr - FTokenPtr
  else L := FSourcePtr - FTokenPtr;
  SetString(Result, FTokenPtr, L);
end;

{-----------------------------------------------------}

function TBasicParser.TokenSymbolIs(const S: string): Boolean;
begin
  Result := (FToken.TokenType = tsSymbol) and SameText(S, TokenString);
end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -