mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 14:36:09 +02:00
added tokens for comments and compiler directives
git-svn-id: trunk@7109 -
This commit is contained in:
parent
2bfef4ae8e
commit
cca55bdadb
@ -71,7 +71,8 @@ type
|
|||||||
TWordPolicy = (wpNone, wpLowerCase, wpUpperCase, wpLowerCaseFirstLetterUp);
|
TWordPolicy = (wpNone, wpLowerCase, wpUpperCase, wpLowerCaseFirstLetterUp);
|
||||||
TAtomType = (atNone, atKeyword, atIdentifier, atColon, atSemicolon, atComma,
|
TAtomType = (atNone, atKeyword, atIdentifier, atColon, atSemicolon, atComma,
|
||||||
atPoint, atAt, atNumber, atStringConstant, atNewLine,
|
atPoint, atAt, atNumber, atStringConstant, atNewLine,
|
||||||
atSpace, atSymbol);
|
atSpace, atCommentStart, atDirectiveStart, atCommentEnd,
|
||||||
|
atSymbol);
|
||||||
TAtomTypes = set of TAtomType;
|
TAtomTypes = set of TAtomType;
|
||||||
|
|
||||||
TBeautifyCodeFlag = (
|
TBeautifyCodeFlag = (
|
||||||
@ -228,7 +229,9 @@ type
|
|||||||
const
|
const
|
||||||
AtomTypeNames: array[TAtomType] of shortstring = (
|
AtomTypeNames: array[TAtomType] of shortstring = (
|
||||||
'None', 'Keyword', 'Identifier', 'Colon', 'Semicolon', 'Comma', 'Point',
|
'None', 'Keyword', 'Identifier', 'Colon', 'Semicolon', 'Comma', 'Point',
|
||||||
'At', 'Number', 'StringConstant', 'NewLine', 'Space', 'Symbol'
|
'At', 'Number', 'StringConstant', 'NewLine', 'Space',
|
||||||
|
'CommentStart', 'DirectiveStart', 'CommentEnd',
|
||||||
|
'Symbol'
|
||||||
);
|
);
|
||||||
|
|
||||||
WordPolicyNames: array[TWordPolicy] of shortstring = (
|
WordPolicyNames: array[TWordPolicy] of shortstring = (
|
||||||
@ -1028,7 +1031,7 @@ begin
|
|||||||
if AtomStart<=SrcLen then begin
|
if AtomStart<=SrcLen then begin
|
||||||
c1:=UpperSrc[CurPos];
|
c1:=UpperSrc[CurPos];
|
||||||
case c1 of
|
case c1 of
|
||||||
'A'..'Z','_':
|
'A'..'Z','_': // identifier
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atIdentifier;
|
CurAtomType:=atIdentifier;
|
||||||
repeat
|
repeat
|
||||||
@ -1038,7 +1041,7 @@ begin
|
|||||||
then
|
then
|
||||||
CurAtomType:=atKeyword;
|
CurAtomType:=atKeyword;
|
||||||
end;
|
end;
|
||||||
#10,#13:
|
#10,#13: // line break
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atNewLine;
|
CurAtomType:=atNewLine;
|
||||||
inc(CurPos);
|
inc(CurPos);
|
||||||
@ -1046,14 +1049,14 @@ begin
|
|||||||
and (Src[CurPos]<>c1) then
|
and (Src[CurPos]<>c1) then
|
||||||
inc(CurPos);
|
inc(CurPos);
|
||||||
end;
|
end;
|
||||||
#0..#9,#11..#12,#14..#32:
|
#0..#9,#11..#12,#14..#32: // special char
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atSpace;
|
CurAtomType:=atSpace;
|
||||||
repeat
|
repeat
|
||||||
inc(CurPos);
|
inc(CurPos);
|
||||||
until (CurPos>SrcLen) or (not IsSpaceChar[Src[CurPos]]);
|
until (CurPos>SrcLen) or (not IsSpaceChar[Src[CurPos]]);
|
||||||
end;
|
end;
|
||||||
'0'..'9':
|
'0'..'9': // decimal number
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atNumber;
|
CurAtomType:=atNumber;
|
||||||
repeat
|
repeat
|
||||||
@ -1079,7 +1082,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
'''','#':
|
'''','#': // string constant
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atStringConstant;
|
CurAtomType:=atStringConstant;
|
||||||
while (CurPos<=SrcLen) do begin
|
while (CurPos<=SrcLen) do begin
|
||||||
@ -1104,20 +1107,75 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
'%':
|
'%': // binary number
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atNumber;
|
CurAtomType:=atNumber;
|
||||||
repeat
|
repeat
|
||||||
inc(CurPos);
|
inc(CurPos);
|
||||||
until (CurPos>SrcLen) or (not (Src[CurPos] in ['0','1']));
|
until (CurPos>SrcLen) or (not (Src[CurPos] in ['0','1']));
|
||||||
end;
|
end;
|
||||||
'$':
|
'$': // hex number
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atNumber;
|
CurAtomType:=atNumber;
|
||||||
repeat
|
repeat
|
||||||
inc(CurPos);
|
inc(CurPos);
|
||||||
until (CurPos>SrcLen) or (not IsHexNumberChar[Src[CurPos]]);
|
until (CurPos>SrcLen) or (not IsHexNumberChar[Src[CurPos]]);
|
||||||
end;
|
end;
|
||||||
|
'{': // curly bracket comment or directive
|
||||||
|
begin
|
||||||
|
inc(CurPos);
|
||||||
|
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
|
||||||
|
inc(CurPos);
|
||||||
|
CurAtomType:=atDirectiveStart;
|
||||||
|
end else begin
|
||||||
|
CurAtomType:=atCommentStart;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
'}': // curly bracket comment end
|
||||||
|
begin
|
||||||
|
inc(CurPos);
|
||||||
|
CurAtomType:=atCommentEnd;
|
||||||
|
end;
|
||||||
|
'(': // (* comment or directive
|
||||||
|
begin
|
||||||
|
inc(CurPos);
|
||||||
|
if (CurPos<=SrcLen) and (Src[CurPos]='*') then begin
|
||||||
|
inc(CurPos);
|
||||||
|
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
|
||||||
|
inc(CurPos);
|
||||||
|
CurAtomType:=atDirectiveStart;
|
||||||
|
end else begin
|
||||||
|
CurAtomType:=atCommentStart;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
CurAtomType:=atSymbol;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
'*': // *) comment end
|
||||||
|
begin
|
||||||
|
inc(CurPos);
|
||||||
|
if (CurPos<=SrcLen) and (Src[CurPos]=')') then begin
|
||||||
|
inc(CurPos);
|
||||||
|
CurAtomType:=atCommentEnd;
|
||||||
|
end else begin
|
||||||
|
CurAtomType:=atSymbol;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
'/': // line comment or directive
|
||||||
|
begin
|
||||||
|
inc(CurPos);
|
||||||
|
if (CurPos<=SrcLen) and (Src[CurPos]='/') then begin
|
||||||
|
inc(CurPos);
|
||||||
|
if (CurPos<=SrcLen) and (Src[CurPos]='$') then begin
|
||||||
|
inc(CurPos);
|
||||||
|
CurAtomType:=atDirectiveStart;
|
||||||
|
end else begin
|
||||||
|
CurAtomType:=atCommentStart;
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
CurAtomType:=atSymbol;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
CurAtomType:=atSymbol;
|
CurAtomType:=atSymbol;
|
||||||
@ -1131,9 +1189,6 @@ begin
|
|||||||
or ((c1='>') and (c2='<'))
|
or ((c1='>') and (c2='<'))
|
||||||
or ((c1='.') and (c2='.'))
|
or ((c1='.') and (c2='.'))
|
||||||
or ((c1='*') and (c2='*'))
|
or ((c1='*') and (c2='*'))
|
||||||
or ((c1='/') and (c2='/'))
|
|
||||||
or ((c1='(') and (c2='*'))
|
|
||||||
or ((c1='*') and (c2=')'))
|
|
||||||
then
|
then
|
||||||
inc(CurPos);
|
inc(CurPos);
|
||||||
end;
|
end;
|
||||||
@ -1208,7 +1263,8 @@ begin
|
|||||||
until false;
|
until false;
|
||||||
if ((Result='') or (Result[length(Result)]<>' '))
|
if ((Result='') or (Result[length(Result)]<>' '))
|
||||||
and ((CurAtomType in DoInsertSpaceInFront)
|
and ((CurAtomType in DoInsertSpaceInFront)
|
||||||
or (LastAtomType in DoInsertSpaceAfter)) then
|
or (LastAtomType in DoInsertSpaceAfter))
|
||||||
|
and (CurAtom<>'$') then
|
||||||
AddAtom(Result,' ');
|
AddAtom(Result,' ');
|
||||||
if (not (CurAtomType in DoNotSplitLineInFront))
|
if (not (CurAtomType in DoNotSplitLineInFront))
|
||||||
and (not (LastAtomType in DoNotSplitLineAfter)) then
|
and (not (LastAtomType in DoNotSplitLineAfter)) then
|
||||||
|
@ -254,7 +254,9 @@ const
|
|||||||
|
|
||||||
AtomTypeDescriptions: array[TAtomType] of shortstring = (
|
AtomTypeDescriptions: array[TAtomType] of shortstring = (
|
||||||
'None', 'Keyword', 'Identifier', 'Colon', 'Semicolon', 'Comma', 'Point',
|
'None', 'Keyword', 'Identifier', 'Colon', 'Semicolon', 'Comma', 'Point',
|
||||||
'At', 'Number', 'String constant', 'Newline', 'Space', 'Symbol'
|
'At', 'Number', 'String constant', 'Newline', 'Space',
|
||||||
|
'Comment start', 'Compiler directive start', 'Comment end',
|
||||||
|
'Symbol'
|
||||||
);
|
);
|
||||||
DoNotSplitAtoms = [atKeyword, atIdentifier, atColon, atSemicolon, atComma,
|
DoNotSplitAtoms = [atKeyword, atIdentifier, atColon, atSemicolon, atComma,
|
||||||
atPoint, atAt, atNumber, atStringConstant, atSpace, atSymbol];
|
atPoint, atAt, atNumber, atStringConstant, atSpace, atSymbol];
|
||||||
@ -271,6 +273,7 @@ const
|
|||||||
+'const i=1+2+3;'#13
|
+'const i=1+2+3;'#13
|
||||||
+'begin'#13
|
+'begin'#13
|
||||||
+' A:=@B.C;D:=3;'#13
|
+' A:=@B.C;D:=3;'#13
|
||||||
|
+' {$I unit1.lrs}'#13
|
||||||
+'end;';
|
+'end;';
|
||||||
|
|
||||||
function AtomTypeDescriptionToType(const s: string): TAtomType;
|
function AtomTypeDescriptionToType(const s: string): TAtomType;
|
||||||
|
Loading…
Reference in New Issue
Block a user