From: <dav...@us...> - 2010-04-18 05:35:46
|
Revision: 897 http://instantobjects.svn.sourceforge.net/instantobjects/revision/?rev=897&view=rev Author: davidvtaylor Date: 2010-04-18 05:35:40 +0000 (Sun, 18 Apr 2010) Log Message: ----------- * Revised Model Explorer code parser to support compound unit names in the uses clause of model units Modified Paths: -------------- trunk/Source/Core/InstantCode.pas trunk/Source/Core/InstantTextFiler.pas Modified: trunk/Source/Core/InstantCode.pas =================================================================== --- trunk/Source/Core/InstantCode.pas 2010-02-02 23:06:30 UTC (rev 896) +++ trunk/Source/Core/InstantCode.pas 2010-04-18 05:35:40 UTC (rev 897) @@ -5701,38 +5701,32 @@ procedure TInstantCodeUsesClause.InternalRead(Reader: TInstantCodeReader); var Token: string; - GotName: Boolean; + Ident: string; BeginPos: TInstantCodePos; + UsedUnit: TInstantCodeUses; begin inherited; - GotName := False; while not Reader.Finished and not Reader.ReadEndOfStatement do begin Reader.SkipSpace; BeginPos := Reader.Position; + Ident := Reader.ReadIdent(True); + if (Ident = '') then + Reader.ErrorExpected('unit name', False); + UsedUnit := Add; + UsedUnit.Name := Ident; + UsedUnit.EndPos := Reader.Position; + UsedUnit.StartPos := BeginPos; Token := Reader.ReadToken; - if Token = ';' then - Break; - if Token = ',' then + if SameText(Token, 'in') then begin - if not GotName then - Reader.ErrorExpected('unit name', False); - GotName := False; - end else if GotName then - Reader.ErrorExpected(',') - else begin - with Add do - begin - StartPos := BeginPos; - Name := Token; - EndPos := Reader.Position; - if SameText(Reader.ReadToken, 'in') then - Reader.ReadString - else - Reader.Position := EndPos; - end; - GotName := True; + Reader.ReadString; + Token := Reader.ReadToken; end; + if Token = ';' then + Break; + if Token <> ',' then + Reader.ErrorExpected(', or ; ' + Token); end; end; Modified: trunk/Source/Core/InstantTextFiler.pas =================================================================== --- trunk/Source/Core/InstantTextFiler.pas 2010-02-02 23:06:30 UTC (rev 896) +++ trunk/Source/Core/InstantTextFiler.pas 2010-04-18 05:35:40 UTC (rev 897) @@ -39,7 +39,8 @@ interface uses - Classes, InstantClasses; + Classes, InstantClasses + {$IFDEF D12+}, Character{$ENDIF}; type PInstantTextPos = ^TInstantTextPos; @@ -92,6 +93,8 @@ function GetBof: Boolean; override; function GetEof: Boolean; override; procedure Initialize; override; + function IsIdentPrefix(Ch: Char): Boolean; + function IsIdentChar(Ch: Char; AllowDots: boolean): Boolean; function IsNumericPrefix(Ch: Char): Boolean; function IsStringDelimiter(Ch: Char): Boolean; public @@ -106,6 +109,7 @@ function ReadNext(const Str: string; StopBefore: Boolean = False): string; function ReadNumeric: string; virtual; function ReadString: string; virtual; + function ReadIdent(AllowDots: boolean): string; function ReadToken: string; function SkipSpace: Boolean; procedure UnreadToken; @@ -317,6 +321,27 @@ ConstAware := True; end; +function TInstantTextReader.IsIdentPrefix(Ch: Char): Boolean; +begin +{$IFDEF D12+} + Result := TCharacter.IsLetter(Ch) or (Ch = '_'); +{$ELSE} + Result := Ch in ['A'..'Z','a'..'z','_']; +{$ENDIF} +end; + +function TInstantTextReader.IsIdentChar(Ch: Char; AllowDots: boolean): Boolean; +begin +{$IFDEF D12+} + Result := TCharacter.IsLetterOrDigit(Ch) or (Ch = '_') or (AllowDots and (Ch = '.')) +{$ELSE} + if (AllowDots) then + Result := Ch in ['A'..'Z','a'..'z','_','.'] + else + Result := Ch in ['A'..'Z','a'..'z','_']; +{$ENDIF} +end; + function TInstantTextReader.IsNumericPrefix(Ch: Char): Boolean; begin Result := ConstAware and @@ -457,6 +482,38 @@ Position := SavePos; end; +function TInstantTextReader.ReadIdent(AllowDots: boolean): string; +var + Ch: Char; + SavePos: TInstantTextPos; +begin + Result := ''; + if Eof then + Exit; + FTokenPos := Position; + Ch := ReadChar; + while IsSpace(Ch) do + begin + FTokenPos := Position; + if Eof then + Exit; + Ch := ReadChar; + end; + if (not IsIdentPrefix(Ch)) then + begin + Position := FTokenPos; + Exit; + end; + repeat + Result := Result + Ch; + if Eof then + Exit; + SavePos := Position; + Ch := ReadChar; + until not IsIdentChar(Ch,AllowDots); + Position := SavePos; +end; + function TInstantTextReader.ReadToken: string; var Ch: Char; |