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

📄 uwparser.pas

📁 Delphi脚本控件
💻 PAS
📖 第 1 页 / 共 4 页
字号:
begin
  case ch of
    '0'..'9'  : ProcessChar    // if a number is read process the char
  else          EAState := 6;  // else the state is switched to final state 6
  end;
end;

// process a char if the state machine has the state 7
// in this state string enclosed in ' is read
procedure TWParser.EASwitch7( ch: Char );
begin
  case ch of
    #0, #10,                    // if a #0 (eof) or a linefeed char is read there is an
    #13     : EAState := 98;    // error because the string is not finished
    ''''    : begin             // if the final ' is read
                EAState := 8;   // switch to final state 8 and read the next char
                ReadCh( ch );
              end;
  else        ProcessChar;      // else the char is a member of the string
  end;
end;

// process a char if the state machine has the state 9
// in this state string enclosed in " is read
procedure TWParser.EASwitch9( ch: Char );
begin
  case ch of
    #0, #10,                    // if a #0 (eof) or a linefeed char is read there is an
    #13     : EAState := 98;    // error because the string is not finished
    '"'  : begin                // if the final " is read
             EAState := 8;      // switch to final state 8 and read the next char
             ReadCh( ch );
           end;
  else     ProcessChar;         // else the char is a member of the string
  end;
end;

// process a char if the state machine has the state 11
// in this state the state machines reads a comment line.
// a comment begins with the introducing user defined comment string. this
// introducing string is already by the state 0. every linefeed or carridge
// return will end the comment line
procedure TWParser.EASwitch11( ch: Char );
begin
  // is the introducing string read complete
  case ch of                     // every linefeed finishes the comment
     #10, #13 : begin
                  EAState := 12; // switch to final state 12
                  ReadCh( ch );  // read the next char
                  // delete every leading blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[1] = ' ') do begin
                    System.Delete( EAText, 1, 1);
                  end;
                  // delete every last blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[Length(EAText)] = ' ') do begin
                    System.Delete( EAText, Length(EAText), 1);
                  end;
                end;
  else     ProcessChar;  // if no linefeed is read add the char to the uncomplete comment line
  end;
end;

// process a char if the state machine has the state 13
// in this state a zero is already read and it is possible that it is
// an integer, a real or a hex number
procedure TWParser.EASwitch13( ch: Char );
begin
  case ch of
    'x', 'X': begin           // if a 'x' is read a hexnumer is found
               EAState := 14; // switch to state 14 to read rest of the hex number
               ProcessChar;
               EAText := '';  // clear the input text '0x' because this is not a part of the hex number
             end;
   '0'..'9': begin            // if another number is read it is an integer or
               EAState := 3;  // real number will follow
               ProcessChar;
             end;
   '.', ',': begin            // if a '.' or a ',' is read the char is processed
               ProcessChar;   // and the state is switched to state 5 in order
               EAState := 5;  // to read a floating point number
             end;
  else       EAState := 4;  // the state is switched to final state 4 ( single '0' read)
  end;
end;

// process a char if the state machine has the state 14
// in this state a hex number is read
procedure TWParser.EASwitch14( ch: Char );
begin
  case ch of
    'a'..'f',
    'A'..'F',
    '0'..'9' : ProcessChar;
  else         if '$' in FCharacters then begin // if $ is defined as a special char
                 SourceX := SourceX - Length(EAText); // correct the saved column
                 EAState := 10;                 // switch to state final 10, do not read next char!!
                 EAText := '$';                 // correct the read input text
                 SourceStream.Position := EAPosition + 1;  // nice try, but the there was no hex number
               end else begin
                 //ProcessChar;   // another char without whitespace
                 EAState := 15; // the state is switched to final state 15, hex number is complete
               end;
  end;
end;

// process a char if the state machine has the state 14
// in this state a hex number is read
procedure TWParser.EASwitch16( ch: Char );
begin
  case ch of
    'a'..'f',                    // is an allowed hex char is read
    'A'..'F',
    '0'..'9' : begin
                 EAState := 14;  // switch to state 14 and read the complete hex number
                 EAText := '';   // clear the formerly read '$'
                 ProcessChar;
               end;
  else         begin
                 if '$' in FCharacters then begin // if $ is defined as a special char
                   EAState := 10;                 // switch to state final 10, do not read next char!!
                 end else begin
                   ProcessChar;     // if $ is not the first char of a hex number
                   EAState := 98;   // and no special char there is an error
                 end;
               end;
  end;
end;

// process a char if the state machine has the state 18
// in this state the state machines reads a comment block
// a comment begins with the introducing user defined comment block begin. this
// introducing string is already by the state 0. only the correspondign comment
// block end string will end the comment phase
procedure TWParser.EASwitch18( ch: Char );
begin
  // is the introducing string read complete
  // from now to the comment block end the scanner is in a comment block read phase
  CommentBlock1Phase := true;
  case ch of                     // every linefeed finishes the comment
     #10, #13 : begin
                  EAState := 12; // switch to final state 12
                  ReadCh( ch );  // read the next char
                  // delete every leading blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[1] = ' ') do begin
                    System.Delete( EAText, 1, 1);
                    Inc( EAColumn, 1 );
                  end;
                  // delete every last blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[Length(EAText)] = ' ') do begin
                    System.Delete( EAText, Length(EAText), 1);
                  end;
                end;
  else          // if a blockcomment ending is defined and if the next chars correspond to
                // the defined block comment ending
                if (Length(FComment1End) <> 0) and
                   (EqualStr(LookAHeadStr(Length(FComment1End)),  FComment1End)) then begin
                  EAState := 12;                     // switch to final state 11
                  SkipChars( Length(FComment1End ) ); // skip the comment block begin
                  CommentBlock1Phase := false;        // coment block phase has ended
                  while (Length(EAText)<> 0) and (EAText[1] = ' ') do begin
                    System.Delete( EAText, 1, 1);     // delete a leading blank
                    Inc( EAColumn, 1 );               // correct the column counter
                  end;
                  // delete every last blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[Length(EAText)] = ' ') do begin
                    System.Delete( EAText, Length(EAText), 1);
                  end;
                end else begin
                  ProcessChar;  // if no linefeed is read add the char to the uncomplete comment line
                end;
  end;
end;

// process a char if the state machine has the state 18
// in this state the state machines reads a comment block
// a comment begins with the introducing user defined comment block begin. this
// introducing string is already by the state 0. only the correspondign comment
// block end string will end the comment phase
procedure TWParser.EASwitch19( ch: Char );
begin
  // is the introducing string read complete
  // from now to the comment block end the scanner is in a comment block read phase
  CommentBlock2Phase := true;
  case ch of                     // every linefeed finishes the comment
     #10, #13 : begin
                  EAState := 12; // switch to final state 12
                  ReadCh( ch );  // read the next char
                  // delete every leading blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[1] = ' ') do begin
                    System.Delete( EAText, 1, 1);
                    Inc( EAColumn, 1 );
                  end;
                  // delete every last blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[Length(EAText)] = ' ') do begin
                    System.Delete( EAText, Length(EAText), 1);
                  end;
                end;
  else          // if a blockcomment ending is defined and if the next chars correspond to
                // the defined block comment ending
                if (Length(FComment2End) <> 0) and
                   (EqualStr(LookAHeadStr(Length(FComment2End)),  FComment2End)) then begin
                  EAState := 12;                     // switch to final state 12
                  SkipChars( Length(FComment2End ) ); // skip the comment block begin
                  CommentBlock2Phase := false;        // coment block phase has ended
                  while (Length(EAText)<> 0) and (EAText[1] = ' ') do begin
                    System.Delete( EAText, 1, 1);     // delete a leading blank
                    Inc( EAColumn, 1 );               // correct the column counter
                  end;
                  // delete every last blank from the comment line
                  while (Length(EAText)<> 0) and (EAText[Length(EAText)] = ' ') do begin
                    System.Delete( EAText, Length(EAText), 1);
                  end;
                end else begin
                  ProcessChar;  // if no linefeed is read add the char to the uncomplete comment line
                end;
  end;
end;

function TWParser.FindToken(aTokenName: String; aTokenType: TTokenType;
  aStartIndex: integer): Integer;
var
  i : integer;
begin
  Result := -1;
  if (Count > 0) and (aStartIndex < (Count - 1)) then
    for i := aStartIndex to Count - 1 do
      if (Token[i].Token = aTokenType) and
         ((aTokenName = '') or (CompareText(Token[i].Text, aTokenName) = 0))
      then begin
        Result := i;
        Break;
      end;
end;

function TWParser.IsToken(aIndex: Integer; aTokenType: TTokenType;
  aText: String): boolean;
begin
  Result := (aIndex >= 0) and (aIndex < Count) and
            (Token[aIndex].Token = aTokenType) and
            (CompareText(Token[aIndex].Text, aText) = 0);
end;

function TWParser.IsToken(aToken: TToken; aTokenType: TTokenType;
  aText: String): boolean;
begin
  Result := Assigned(aToken) and
            (aToken.Token = aTokenType) and
            (CompareText(aToken.Text, aText) = 0);
end;

function TWParser.GetSourceString(aStartIndex, aEndIndex: Integer): String;
var
  Buff : Pointer;
  Size : Integer;
begin
  Result := '';
  if (aStartIndex >= aEndIndex) or (aStartIndex >= Count) or (aEndIndex >= Count) then Exit;
  Size := Token[aEndIndex].Position - Token[aStartIndex].Position + Length(Token[aEndIndex].Text);
  try
    GetMem(Buff, Size + 4);
    FillChar(Buff^, Size, #0);
    SourceStream.Position := Token[aStartIndex].Position;
    SourceStream.Read(Buff^, Size);
    Result := Copy(StrPas(Buff), 1, Size);
  finally
    FreeMem(Buff);
  end;
end;

end.

⌨️ 快捷键说明

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