mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-16 15:49:18 +02:00
* Fixes for literal strings and for automatic semicolon insertion. Fixed objects with empty members (,, or ,})
git-svn-id: trunk@15966 -
This commit is contained in:
parent
fd70748267
commit
7ba956d121
@ -55,6 +55,7 @@ Type
|
|||||||
FIsLHS: Boolean;
|
FIsLHS: Boolean;
|
||||||
FNoIn: Boolean;
|
FNoIn: Boolean;
|
||||||
FScanner : TJSScanner;
|
FScanner : TJSScanner;
|
||||||
|
FPrevious,
|
||||||
FCurrent : TJSToken;
|
FCurrent : TJSToken;
|
||||||
FCurrentString : String;
|
FCurrentString : String;
|
||||||
FNextNewLine : Boolean;
|
FNextNewLine : Boolean;
|
||||||
@ -66,9 +67,10 @@ Type
|
|||||||
FLabelSets,
|
FLabelSets,
|
||||||
FCurrentLabelSet:TJSLabelSet;
|
FCurrentLabelSet:TJSLabelSet;
|
||||||
FLabels : TJSLabel;
|
FLabels : TJSLabel;
|
||||||
|
function CheckSemiColonInsert(aToken: TJSToken; Consume: Boolean): Boolean;
|
||||||
function EnterLabel(ALabelName: String): TJSLabel;
|
function EnterLabel(ALabelName: String): TJSLabel;
|
||||||
procedure Expect(aToken: TJSToken);
|
procedure Expect(aToken: TJSToken);
|
||||||
procedure Consume(aToken: TJSToken);
|
procedure Consume(aToken: TJSToken; AllowSemicolonInsert : Boolean = False);
|
||||||
procedure FreeCurrentLabelSet;
|
procedure FreeCurrentLabelSet;
|
||||||
procedure LeaveLabel;
|
procedure LeaveLabel;
|
||||||
function LookupLabel(ALabelName: String; Kind: TJSToken): TJSLabel;
|
function LookupLabel(ALabelName: String; Kind: TJSToken): TJSLabel;
|
||||||
@ -193,6 +195,7 @@ end;
|
|||||||
|
|
||||||
function TJSParser.GetNextToken: TJSToken;
|
function TJSParser.GetNextToken: TJSToken;
|
||||||
begin
|
begin
|
||||||
|
FPrevious:=FCurrent;
|
||||||
If (FPeekToken<>tjsunknown) then
|
If (FPeekToken<>tjsunknown) then
|
||||||
begin
|
begin
|
||||||
FCurrent:=FPeekToken;
|
FCurrent:=FPeekToken;
|
||||||
@ -205,7 +208,7 @@ begin
|
|||||||
FCurrent:=FScanner.FetchToken;
|
FCurrent:=FScanner.FetchToken;
|
||||||
FCurrentString:=FScanner.CurTokenString;
|
FCurrentString:=FScanner.CurTokenString;
|
||||||
end;
|
end;
|
||||||
{$ifdef debugparser}Writeln('GetNextToken : ',GetEnumName(TypeInfo(TJSToken),Ord(FCurrent)), ' As string: ',FCurrentString);{$endif debugparser}
|
{$ifdef debugparser}Writeln('GetNextToken (',FScanner.CurLine,',',FScanner.CurColumn,'): ',GetEnumName(TypeInfo(TJSToken),Ord(FCurrent)), ' As string: ',FCurrentString);{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSParser.PeekNextToken: TJSToken;
|
function TJSParser.PeekNextToken: TJSToken;
|
||||||
@ -386,14 +389,29 @@ Procedure TJSParser.Expect(aToken : TJSToken);
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
{$ifdef debugparser} Writeln('Expecting : ',GetEnumName(TypeInfo(TJSToken),Ord(AToken)), ' As string: ',TokenInfos[AToken]);{$endif debugparser}
|
{$ifdef debugparser} Writeln('Expecting : ',GetEnumName(TypeInfo(TJSToken),Ord(AToken)), ' As string: ',TokenInfos[AToken]);{$endif debugparser}
|
||||||
If (CurrentToken<>aToken) then
|
If Not CheckSemiColonInsert(AToken,False) then
|
||||||
Error(SerrTokenMismatch,[CurrenttokenString,TokenInfos[aToken]]);
|
if (CurrentToken<>aToken) then
|
||||||
|
Error(SerrTokenMismatch,[CurrenttokenString,TokenInfos[aToken]]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJSParser.Consume(aToken: TJSToken);
|
function TJSParser.CheckSemiColonInsert(aToken : TJSToken; Consume : Boolean) : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
Result:=(AToken=tjsSemiColon);
|
||||||
|
If Result then
|
||||||
|
begin
|
||||||
|
Result:=(CurrentToken=tjsCurlyBraceClose) or (FScanner.WasEndOfLine) or (CurrentToken=tjsEOF);
|
||||||
|
If Result and Consume then
|
||||||
|
FPrevious:=tjsSemiColon;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TJSParser.Consume(aToken: TJSToken; AllowSemiColonInsert : Boolean = False);
|
||||||
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('Consuming : ',GetEnumName(TypeInfo(TJSToken),Ord(AToken)), ' As string: ',TokenInfos[AToken]);{$endif debugparser}
|
||||||
Expect(aToken);
|
Expect(aToken);
|
||||||
GetNextToken;
|
If not (AllowSemiColonInsert and CheckSemiColonInsert(aToken,True)) then
|
||||||
|
GetNextToken;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSParser.ParseIdentifier : String;
|
function TJSParser.ParseIdentifier : String;
|
||||||
@ -495,7 +513,7 @@ begin
|
|||||||
SL:=TJSSTatementList(CreateElement(TJSStatementList));
|
SL:=TJSSTatementList(CreateElement(TJSStatementList));
|
||||||
try
|
try
|
||||||
SL.A:=E;
|
SL.A:=E;
|
||||||
SL.B:=ParseStatementlist;
|
SL.B:=ParseStatementlist();
|
||||||
Result:=SL;
|
Result:=SL;
|
||||||
except
|
except
|
||||||
FreeAndNil(SL);
|
FreeAndNil(SL);
|
||||||
@ -545,7 +563,7 @@ begin
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
E:=N.Elements.AddElement;
|
E:=N.Elements.AddElement;
|
||||||
E.Index:=I;
|
E.ElementIndex:=I;
|
||||||
Inc(I);
|
Inc(I);
|
||||||
E.Expr:=ParseAssignmentExpression;
|
E.Expr:=ParseAssignmentExpression;
|
||||||
If Not (CurrentToken in [tjsComma,tjsSquaredBraceClose]) then
|
If Not (CurrentToken in [tjsComma,tjsSquaredBraceClose]) then
|
||||||
@ -573,6 +591,8 @@ begin
|
|||||||
try
|
try
|
||||||
While (CurrentToken<>tjsCurlyBraceClose) do
|
While (CurrentToken<>tjsCurlyBraceClose) do
|
||||||
begin
|
begin
|
||||||
|
While CurrentToken=tjsComma do
|
||||||
|
GetNextToken;
|
||||||
If (CurrentToken in [tjsIdentifier,jsscanner.tjsString,tjsnumber]) then
|
If (CurrentToken in [tjsIdentifier,jsscanner.tjsString,tjsnumber]) then
|
||||||
begin
|
begin
|
||||||
E:=N.Elements.AddElement;
|
E:=N.Elements.AddElement;
|
||||||
@ -583,8 +603,10 @@ begin
|
|||||||
Error(SErrObjectElement,[CurrentTokenString]);
|
Error(SErrObjectElement,[CurrentTokenString]);
|
||||||
Consume(tjsColon);
|
Consume(tjsColon);
|
||||||
E.Expr:=ParseAssignmentExpression;
|
E.Expr:=ParseAssignmentExpression;
|
||||||
If Not (CurrentToken in [tjsComma,tjsCurlyBraceClose]) then
|
While CurrentToken=tjsComma do
|
||||||
Error(SErrObjectEnd,[CurrentTokenString])
|
GetNextToken;
|
||||||
|
{ If Not (CurrentToken in [tjsComma,tjsCurlyBraceClose]) then
|
||||||
|
Error(SErrObjectEnd,[CurrentTokenString])}
|
||||||
end;
|
end;
|
||||||
Consume(tjsCurlyBraceClose);
|
Consume(tjsCurlyBraceClose);
|
||||||
except
|
except
|
||||||
@ -708,6 +730,7 @@ Var
|
|||||||
R : TJSPrimaryExpressionIdent;
|
R : TJSPrimaryExpressionIdent;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParsePrimaryExpression');{$endif debugparser}
|
||||||
Result:=Nil;
|
Result:=Nil;
|
||||||
try
|
try
|
||||||
Case CurrentToken of
|
Case CurrentToken of
|
||||||
@ -731,6 +754,7 @@ begin
|
|||||||
Consume(tjsBraceOpen);
|
Consume(tjsBraceOpen);
|
||||||
Result:=ParseExpression;
|
Result:=ParseExpression;
|
||||||
Consume(tjsBraceClose);
|
Consume(tjsBraceClose);
|
||||||
|
Writeln('Closed brace !!');
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
Result:=ParseLiteral;
|
Result:=ParseLiteral;
|
||||||
@ -739,6 +763,7 @@ begin
|
|||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParsePrimaryExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -751,11 +776,15 @@ Var
|
|||||||
Done : Boolean;
|
Done : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseMemberExpression');{$endif debugparser}
|
||||||
Case CurrentToken of
|
Case CurrentToken of
|
||||||
tjsFunction : Result:=ParseFunctionExpression;
|
tjsFunction : Result:=ParseFunctionExpression();
|
||||||
tjsNew : Result:=ParseMemberExpression;
|
tjsNew : begin
|
||||||
|
GetNextToken;
|
||||||
|
Result:=ParseMemberExpression();
|
||||||
|
end;
|
||||||
else
|
else
|
||||||
Result:=ParsePrimaryExpression
|
Result:=ParsePrimaryExpression()
|
||||||
end;
|
end;
|
||||||
try
|
try
|
||||||
Done:=False;
|
Done:=False;
|
||||||
@ -777,7 +806,7 @@ begin
|
|||||||
B.MExpr:=Result;
|
B.MExpr:=Result;
|
||||||
Result:=B;
|
Result:=B;
|
||||||
GetNextToken;
|
GetNextToken;
|
||||||
B.Name:=ParseExpression;
|
B.Name:=ParseExpression();
|
||||||
Consume(tjsSquaredBraceClose);
|
Consume(tjsSquaredBraceClose);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
@ -789,6 +818,7 @@ begin
|
|||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseMemberExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseArguments : TJSarguments;
|
Function TJSParser.ParseArguments : TJSarguments;
|
||||||
@ -826,6 +856,7 @@ Var
|
|||||||
Done : Boolean;
|
Done : Boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseLeftHandSideExpression');{$endif debugparser}
|
||||||
Case CurrentToken of
|
Case CurrentToken of
|
||||||
tjsFunction : Result:=ParseFunctionExpression;
|
tjsFunction : Result:=ParseFunctionExpression;
|
||||||
tjsNew : Result:=ParseMemberExpression;
|
tjsNew : Result:=ParseMemberExpression;
|
||||||
@ -873,6 +904,7 @@ begin
|
|||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseLeftHandSideExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParsePostFixExpression : TJSElement;
|
Function TJSParser.ParsePostFixExpression : TJSElement;
|
||||||
@ -898,6 +930,7 @@ begin
|
|||||||
freeAndNil(Result);
|
freeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParsePostfixExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseUnaryExpression : TJSElement;
|
Function TJSParser.ParseUnaryExpression : TJSElement;
|
||||||
@ -930,13 +963,14 @@ begin
|
|||||||
R:=TJSUnaryExpression(CreateElement(C));
|
R:=TJSUnaryExpression(CreateElement(C));
|
||||||
Result:=R;
|
Result:=R;
|
||||||
GetNextToken;
|
GetNextToken;
|
||||||
R.A:=Self.ParseUnaryExpression;
|
R.A:=ParseUnaryExpression();
|
||||||
isLHS:=False;
|
isLHS:=False;
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseUnaryExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseMultiplicativeExpression : TJSElement;
|
Function TJSParser.ParseMultiplicativeExpression : TJSElement;
|
||||||
@ -968,6 +1002,7 @@ begin
|
|||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseMultiplicativeExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseAdditiveExpression : TJSElement;
|
Function TJSParser.ParseAdditiveExpression : TJSElement;
|
||||||
@ -997,6 +1032,7 @@ begin
|
|||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseAdditiveExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseShiftExpression : TJSElement;
|
Function TJSParser.ParseShiftExpression : TJSElement;
|
||||||
@ -1027,6 +1063,7 @@ begin
|
|||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseShiftExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseRelationalExpression: TJSElement;
|
Function TJSParser.ParseRelationalExpression: TJSElement;
|
||||||
@ -1037,6 +1074,7 @@ Var
|
|||||||
R : TJSRelationalExpression;
|
R : TJSRelationalExpression;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseRelationalExpression');{$endif debugparser}
|
||||||
Result:=ParseShiftExpression;
|
Result:=ParseShiftExpression;
|
||||||
try
|
try
|
||||||
S:=[tjsLT,tjsGT,tjsLE,tjsGE,tjsInstanceOf];
|
S:=[tjsLT,tjsGT,tjsLE,tjsGE,tjsInstanceOf];
|
||||||
@ -1056,13 +1094,14 @@ begin
|
|||||||
R.A:=Result;
|
R.A:=Result;
|
||||||
Result:=R;
|
Result:=R;
|
||||||
GetNextToken;
|
GetNextToken;
|
||||||
R.B:=ParseRelationalExpression;
|
R.B:=ParseRelationalExpression();
|
||||||
IsLHS:=False;
|
IsLHS:=False;
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseRelationalExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseEqualityExpression: TJSElement;
|
Function TJSParser.ParseEqualityExpression: TJSElement;
|
||||||
@ -1072,6 +1111,7 @@ Var
|
|||||||
E : TJSEqualityExpression;
|
E : TJSEqualityExpression;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseEqualityExpression');{$endif debugparser}
|
||||||
Result:=ParseRelationalExpression;
|
Result:=ParseRelationalExpression;
|
||||||
try
|
try
|
||||||
While (CurrentToken in [tjsEq,tjsNE,tjsSEQ,tjsSNE]) do
|
While (CurrentToken in [tjsEq,tjsNE,tjsSEQ,tjsSNE]) do
|
||||||
@ -1086,7 +1126,7 @@ begin
|
|||||||
E:=TJSEqualityExpression(CreateElement(C));
|
E:=TJSEqualityExpression(CreateElement(C));
|
||||||
Result:=E;
|
Result:=E;
|
||||||
E.A:=Result;
|
E.A:=Result;
|
||||||
E.B:=ParseEqualityExpression;
|
E.B:=ParseEqualityExpression();
|
||||||
E:=Nil;
|
E:=Nil;
|
||||||
IsLHS:=False;
|
IsLHS:=False;
|
||||||
end;
|
end;
|
||||||
@ -1094,6 +1134,7 @@ begin
|
|||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseEqualityExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseBitwiseAndExpression : TJSElement;
|
Function TJSParser.ParseBitwiseAndExpression : TJSElement;
|
||||||
@ -1102,6 +1143,7 @@ Var
|
|||||||
L : TJSBitwiseAndExpression;
|
L : TJSBitwiseAndExpression;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseBitwiseAndExpression');{$endif debugparser}
|
||||||
Result:=ParseEqualityExpression;
|
Result:=ParseEqualityExpression;
|
||||||
try
|
try
|
||||||
If (CurrentToken<>tjsAnd) then
|
If (CurrentToken<>tjsAnd) then
|
||||||
@ -1110,12 +1152,13 @@ begin
|
|||||||
L:=TJSBitwiseAndExpression(CreateElement(TJSBitwiseAndExpression));
|
L:=TJSBitwiseAndExpression(CreateElement(TJSBitwiseAndExpression));
|
||||||
L.A:=Result;
|
L.A:=Result;
|
||||||
Result:=L;
|
Result:=L;
|
||||||
L.B:=ParseBitwiseAndExpression;
|
L.B:=ParseBitwiseAndExpression();
|
||||||
IsLHS:=False;
|
IsLHS:=False;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseBitwiseAndExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseBitwiseXORExpression : TJSElement;
|
Function TJSParser.ParseBitwiseXORExpression : TJSElement;
|
||||||
@ -1124,6 +1167,7 @@ Var
|
|||||||
L : TJSBitwiseXOrExpression;
|
L : TJSBitwiseXOrExpression;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseBitwiseXorExpression');{$endif debugparser}
|
||||||
Result:=ParseBitwiseAndExpression;
|
Result:=ParseBitwiseAndExpression;
|
||||||
try
|
try
|
||||||
If (CurrentToken<>tjsXOr) then
|
If (CurrentToken<>tjsXOr) then
|
||||||
@ -1132,12 +1176,13 @@ begin
|
|||||||
L:=TJSBitwiseXOrExpression(CreateElement(TJSBitwiseXOrExpression));
|
L:=TJSBitwiseXOrExpression(CreateElement(TJSBitwiseXOrExpression));
|
||||||
L.A:=Result;
|
L.A:=Result;
|
||||||
Result:=L;
|
Result:=L;
|
||||||
L.B:=ParseBitwiseXORExpression;
|
L.B:=ParseBitwiseXORExpression();
|
||||||
IsLHS:=False;
|
IsLHS:=False;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseBitwiseXorExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseBitwiseORExpression : TJSElement;
|
Function TJSParser.ParseBitwiseORExpression : TJSElement;
|
||||||
@ -1155,12 +1200,13 @@ begin
|
|||||||
L:=TJSBitwiseOrExpression(CreateElement(TJSBitwiseOrExpression));
|
L:=TJSBitwiseOrExpression(CreateElement(TJSBitwiseOrExpression));
|
||||||
L.A:=Result;
|
L.A:=Result;
|
||||||
Result:=L;
|
Result:=L;
|
||||||
L.B:=ParseBitwiseORExpression;
|
L.B:=ParseBitwiseORExpression();
|
||||||
IsLHS:=False;
|
IsLHS:=False;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseBitWiseOrExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseLogicalAndExpression : TJSElement;
|
Function TJSParser.ParseLogicalAndExpression : TJSElement;
|
||||||
@ -1178,12 +1224,13 @@ begin
|
|||||||
L:=TJSLogicalAndExpression(CreateElement(TJSLogicalAndExpression));
|
L:=TJSLogicalAndExpression(CreateElement(TJSLogicalAndExpression));
|
||||||
L.A:=Result;
|
L.A:=Result;
|
||||||
Result:=L;
|
Result:=L;
|
||||||
L.B:=ParseLogicalAndExpression;
|
L.B:=ParseLogicalAndExpression();
|
||||||
IsLHS:=False;
|
IsLHS:=False;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseLogicalAndExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseLogicalORExpression : TJSElement;
|
Function TJSParser.ParseLogicalORExpression : TJSElement;
|
||||||
@ -1198,15 +1245,19 @@ begin
|
|||||||
If (CurrentToken<>tjsOROR) then
|
If (CurrentToken<>tjsOROR) then
|
||||||
exit;
|
exit;
|
||||||
GetNextToken;
|
GetNextToken;
|
||||||
|
Writeln('a');
|
||||||
L:=TJSLogicalOrExpression(CreateElement(TJSLogicalOrExpression));
|
L:=TJSLogicalOrExpression(CreateElement(TJSLogicalOrExpression));
|
||||||
L.A:=Result;
|
L.A:=Result;
|
||||||
|
Writeln('B');
|
||||||
Result:=L;
|
Result:=L;
|
||||||
L.B:=ParseLogicalOrExpression;
|
L.B:=ParseLogicalOrExpression();
|
||||||
|
Writeln('C');
|
||||||
IsLHS:=False;
|
IsLHS:=False;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseLogicalOrExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseConditionalExpression : TJSElement;
|
Function TJSParser.ParseConditionalExpression : TJSElement;
|
||||||
@ -1221,6 +1272,7 @@ begin
|
|||||||
try
|
try
|
||||||
If (CurrentToken=tjsConditional) then
|
If (CurrentToken=tjsConditional) then
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseConditionalExpression : Detected conditional ');{$endif debugparser}
|
||||||
GetNextToken;
|
GetNextToken;
|
||||||
L:=Result;
|
L:=Result;
|
||||||
N:=TJSConditionalExpression(CreateElement(TJSConditionalExpression));
|
N:=TJSConditionalExpression(CreateElement(TJSConditionalExpression));
|
||||||
@ -1235,6 +1287,7 @@ begin
|
|||||||
except
|
except
|
||||||
FreeandNil(Result);
|
FreeandNil(Result);
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseConditionalExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseAssignmentExpression : TJSElement;
|
Function TJSParser.ParseAssignmentExpression : TJSElement;
|
||||||
@ -1269,19 +1322,25 @@ begin
|
|||||||
Result:=N
|
Result:=N
|
||||||
end;
|
end;
|
||||||
If Result<>Nil then
|
If Result<>Nil then
|
||||||
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseAssignmentExpression - no assignment');{$endif debugparser}
|
||||||
Exit;
|
Exit;
|
||||||
|
end;
|
||||||
A:=TJSAssignStatement(CreateElement(C));
|
A:=TJSAssignStatement(CreateElement(C));
|
||||||
try
|
try
|
||||||
Result:=A;
|
Result:=A;
|
||||||
A.Lhs:=N;
|
A.Lhs:=N;
|
||||||
GetNextToken;
|
GetNextToken;
|
||||||
N:=Self.ParseAssignmentExpression;
|
{$ifdef debugparser} Writeln('ParseAssignmentExpression - level 2');{$endif debugparser}
|
||||||
|
N:=ParseAssignmentExpression();
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseAssignmentExpression - level 2');{$endif debugparser}
|
||||||
A.Expr:=N;
|
A.Expr:=N;
|
||||||
IsLhs:=False;
|
IsLhs:=False;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseAssignmentExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseVariableDeclaration : TJSElement;
|
Function TJSParser.ParseVariableDeclaration : TJSElement;
|
||||||
@ -1290,6 +1349,7 @@ Var
|
|||||||
V : TJSVarDeclaration;
|
V : TJSVarDeclaration;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseVariableDeclaration');{$endif debugparser}
|
||||||
V:=TJSVarDeclaration(CreateElement(TJSVarDeclaration));;
|
V:=TJSVarDeclaration(CreateElement(TJSVarDeclaration));;
|
||||||
try
|
try
|
||||||
V.Name:=CurrenttokenString;
|
V.Name:=CurrenttokenString;
|
||||||
@ -1307,6 +1367,7 @@ begin
|
|||||||
FreeAndNil(V);
|
FreeAndNil(V);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseVariableDeclaration');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TJSParser.ParseVariableDeclarationList : TJSElement;
|
Function TJSParser.ParseVariableDeclarationList : TJSElement;
|
||||||
@ -1326,7 +1387,7 @@ begin
|
|||||||
Result:=L;
|
Result:=L;
|
||||||
try
|
try
|
||||||
Consume(tjsComma);
|
Consume(tjsComma);
|
||||||
N:=Self.ParseVariableDeclarationList;
|
N:=ParseVariableDeclarationList();
|
||||||
L.A:=E;
|
L.A:=E;
|
||||||
L.B:=N;
|
L.B:=N;
|
||||||
except
|
except
|
||||||
@ -1349,7 +1410,7 @@ begin
|
|||||||
Consume(tjsVar);
|
Consume(tjsVar);
|
||||||
Result:=ParseVariableDeclarationList;
|
Result:=ParseVariableDeclarationList;
|
||||||
try
|
try
|
||||||
Consume(tjsSemicolon);
|
Consume(tjsSemicolon,true);
|
||||||
V:=TJSVariableStatement(CreateElement(TJSVariableStatement));
|
V:=TJSVariableStatement(CreateElement(TJSVariableStatement));
|
||||||
V.A:=Result;
|
V.A:=Result;
|
||||||
Result:=V;
|
Result:=V;
|
||||||
@ -1363,7 +1424,7 @@ end;
|
|||||||
function TJSParser.ParseEmptyStatement : TJSElement;
|
function TJSParser.ParseEmptyStatement : TJSElement;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Consume(tjsSemiColon);
|
Consume(tjsSemiColon,true);
|
||||||
Result:=CreateElement(TJSEmptyStatement);
|
Result:=CreateElement(TJSEmptyStatement);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1427,7 +1488,7 @@ begin
|
|||||||
Consume(tjsBraceOpen);
|
Consume(tjsBraceOpen);
|
||||||
W.Cond:=ParseExpression;
|
W.Cond:=ParseExpression;
|
||||||
Consume(tjsBraceClose);
|
Consume(tjsBraceClose);
|
||||||
Consume(tjsSemicolon);
|
Consume(tjsSemicolon,True);
|
||||||
end;
|
end;
|
||||||
tjsWhile :
|
tjsWhile :
|
||||||
begin
|
begin
|
||||||
@ -1540,7 +1601,7 @@ begin
|
|||||||
L:=LookupLabel(CurrentTokenString,tjsContinue);
|
L:=LookupLabel(CurrentTokenString,tjsContinue);
|
||||||
Consume(tjsIdentifier);
|
Consume(tjsIdentifier);
|
||||||
end;
|
end;
|
||||||
Consume(tjsSemicolon);
|
Consume(tjsSemicolon,True);
|
||||||
C.Target:=L.Labelset.Target;
|
C.Target:=L.Labelset.Target;
|
||||||
except
|
except
|
||||||
FreeAndNil(C);
|
FreeAndNil(C);
|
||||||
@ -1567,7 +1628,7 @@ begin
|
|||||||
L:=LookupLabel(CurrentTokenString,tjsBreak);
|
L:=LookupLabel(CurrentTokenString,tjsBreak);
|
||||||
Consume(tjsIdentifier);
|
Consume(tjsIdentifier);
|
||||||
end;
|
end;
|
||||||
Consume(tjsSemicolon);
|
Consume(tjsSemicolon,True);
|
||||||
B.Target:=L.Labelset.Target;
|
B.Target:=L.Labelset.Target;
|
||||||
except
|
except
|
||||||
FreeAndNil(B);
|
FreeAndNil(B);
|
||||||
@ -1587,9 +1648,9 @@ begin
|
|||||||
Consume(tjsReturn);
|
Consume(tjsReturn);
|
||||||
If (FunctionDepth=0) then
|
If (FunctionDepth=0) then
|
||||||
Error(SErrReturnNotInFunction);
|
Error(SErrReturnNotInFunction);
|
||||||
If Not (CurrentToken=tjsSemicolon) then
|
If Not (CurrentToken in [tjsSemicolon,tjsCurlyBraceClose]) then
|
||||||
R.Expr:=ParseExpression;
|
R.Expr:=ParseExpression;
|
||||||
Consume(tjsSemicolon);
|
Consume(tjsSemicolon,True);
|
||||||
except
|
except
|
||||||
FreeAndNil(R);
|
FreeAndNil(R);
|
||||||
Raise;
|
Raise;
|
||||||
@ -1680,7 +1741,7 @@ begin
|
|||||||
If IsEndOfLine then
|
If IsEndOfLine then
|
||||||
Error(SErrNewlineAfterThrow);
|
Error(SErrNewlineAfterThrow);
|
||||||
TS.A:=ParseExpression;
|
TS.A:=ParseExpression;
|
||||||
Consume(tjsSemicolon);
|
Consume(tjsSemicolon,true);
|
||||||
except
|
except
|
||||||
FreeAndNil(TS);
|
FreeAndNil(TS);
|
||||||
Raise;
|
Raise;
|
||||||
@ -1891,11 +1952,13 @@ Var
|
|||||||
E : TJSElement;
|
E : TJSElement;
|
||||||
R : TJSExpressionStatement;
|
R : TJSExpressionStatement;
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseExpressionStatement');{$endif debugparser}
|
||||||
E:=ParseExpression;
|
E:=ParseExpression;
|
||||||
Consume(tjsSemicolon);
|
Consume(tjsSemicolon,True);
|
||||||
R:=TJSExpressionStatement(CreateElement(TJSExpressionStatement));
|
R:=TJSExpressionStatement(CreateElement(TJSExpressionStatement));
|
||||||
R.A:=E;
|
R.A:=E;
|
||||||
Result:=R;
|
Result:=R;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseExpressionStatement');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSParser.ParseExpression : TJSElement;
|
function TJSParser.ParseExpression : TJSElement;
|
||||||
@ -1904,6 +1967,7 @@ Var
|
|||||||
C : TJSCommaExpression;
|
C : TJSCommaExpression;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
{$ifdef debugparser} Writeln('ParseExpression');{$endif debugparser}
|
||||||
Result:=ParseAssignmentExpression;
|
Result:=ParseAssignmentExpression;
|
||||||
try
|
try
|
||||||
If (CurrentToken=tjsComma) then
|
If (CurrentToken=tjsComma) then
|
||||||
@ -1912,13 +1976,13 @@ begin
|
|||||||
C.A:=Result;
|
C.A:=Result;
|
||||||
Result:=C;
|
Result:=C;
|
||||||
GetNextToken;
|
GetNextToken;
|
||||||
C.B:=ParseExpression;
|
C.B:=ParseExpression();
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
FreeAndNil(Result);
|
FreeAndNil(Result);
|
||||||
Raise;
|
Raise;
|
||||||
end;
|
end;
|
||||||
|
{$ifdef debugparser} Writeln('Exit ParseExpression');{$endif debugparser}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSParser.ParseStatement : TJSElement;
|
function TJSParser.ParseStatement : TJSElement;
|
||||||
@ -1965,7 +2029,7 @@ begin
|
|||||||
else
|
else
|
||||||
Result:=ParseExpressionStatement;
|
Result:=ParseExpressionStatement;
|
||||||
end;
|
end;
|
||||||
{$ifdef debugparser} Writeln('<<< Parsestatement ',Result.ClassName);{$endif}
|
{$ifdef debugparser} If Assigned(Result) then Writeln('<<< Parsestatement ',Result.ClassName) else Writeln('<<< Parsestatement (null');{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSParser.ParseSourceElements : TJSSourceElements;
|
function TJSParser.ParseSourceElements : TJSSourceElements;
|
||||||
|
@ -148,6 +148,7 @@ Type
|
|||||||
FCurLine: string;
|
FCurLine: string;
|
||||||
FDefines: TStrings;
|
FDefines: TStrings;
|
||||||
TokenStr: PChar;
|
TokenStr: PChar;
|
||||||
|
FWasEndOfLine : Boolean;
|
||||||
FSourceStream : TStream;
|
FSourceStream : TStream;
|
||||||
FOwnSourceFile : Boolean;
|
FOwnSourceFile : Boolean;
|
||||||
function CommentDiv: TJSToken;
|
function CommentDiv: TJSToken;
|
||||||
@ -170,6 +171,7 @@ Type
|
|||||||
procedure OpenFile(const AFilename: string);
|
procedure OpenFile(const AFilename: string);
|
||||||
Function FetchToken: TJSToken;
|
Function FetchToken: TJSToken;
|
||||||
Function IsEndOfLine : Boolean;
|
Function IsEndOfLine : Boolean;
|
||||||
|
Property WasEndOfLine : Boolean Read FWasEndOfLine;
|
||||||
Property ReturnComments : Boolean Read FReturnComments Write FReturnComments;
|
Property ReturnComments : Boolean Read FReturnComments Write FReturnComments;
|
||||||
Property ReturnWhiteSpace : Boolean Read FReturnWhiteSpace Write FReturnWhiteSpace;
|
Property ReturnWhiteSpace : Boolean Read FReturnWhiteSpace Write FReturnWhiteSpace;
|
||||||
property SourceFile: TLineReader read FSourceFile;
|
property SourceFile: TLineReader read FSourceFile;
|
||||||
@ -260,6 +262,7 @@ begin
|
|||||||
TokenStr := PChar(CurLine);
|
TokenStr := PChar(CurLine);
|
||||||
Result := true;
|
Result := true;
|
||||||
Inc(FCurRow);
|
Inc(FCurRow);
|
||||||
|
FWasEndofLine:=True;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -406,6 +409,7 @@ begin
|
|||||||
// Read escaped token
|
// Read escaped token
|
||||||
Case TokenStr[0] of
|
Case TokenStr[0] of
|
||||||
'"' : S:='"';
|
'"' : S:='"';
|
||||||
|
'''' : S:='''';
|
||||||
't' : S:=#9;
|
't' : S:=#9;
|
||||||
'b' : S:=#8;
|
'b' : S:=#8;
|
||||||
'n' : S:=#10;
|
'n' : S:=#10;
|
||||||
@ -538,15 +542,18 @@ var
|
|||||||
OldLength, SectionLength, NestingLevel, Index: Integer;
|
OldLength, SectionLength, NestingLevel, Index: Integer;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
if not (FCurtoken in [tjsWhiteSpace,tjsComment]) then
|
||||||
|
FWasEndOfLine:=False;
|
||||||
Repeat
|
Repeat
|
||||||
if TokenStr = nil then
|
if TokenStr = nil then
|
||||||
|
begin
|
||||||
if not FetchLine then
|
if not FetchLine then
|
||||||
begin
|
begin
|
||||||
Result := tjsEOF;
|
Result := tjsEOF;
|
||||||
FCurToken := Result;
|
FCurToken := Result;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
CurPos:=TokenStr;
|
CurPos:=TokenStr;
|
||||||
FCurTokenString := '';
|
FCurTokenString := '';
|
||||||
case TokenStr[0] of
|
case TokenStr[0] of
|
||||||
@ -684,13 +691,25 @@ begin
|
|||||||
'.':
|
'.':
|
||||||
begin
|
begin
|
||||||
Inc(TokenStr);
|
Inc(TokenStr);
|
||||||
Result := tjsDot;
|
if (TokenStr[0] in ['0'..'9']) then
|
||||||
|
begin
|
||||||
|
Result:=DoNumericLiteral;
|
||||||
|
If (Result=tjsNumber) then
|
||||||
|
FCurTokenString:='0.'+FCurTokenString;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Result := tjsDot;
|
||||||
end;
|
end;
|
||||||
':':
|
':':
|
||||||
begin
|
begin
|
||||||
Inc(TokenStr);
|
Inc(TokenStr);
|
||||||
Result := tjsColon;
|
Result := tjsColon;
|
||||||
end;
|
end;
|
||||||
|
'?':
|
||||||
|
begin
|
||||||
|
Inc(TokenStr);
|
||||||
|
Result := tjsConditional;
|
||||||
|
end;
|
||||||
';':
|
';':
|
||||||
begin
|
begin
|
||||||
Inc(TokenStr);
|
Inc(TokenStr);
|
||||||
@ -816,8 +835,6 @@ begin
|
|||||||
Until (Not (Result in [tjsComment,tjsWhitespace])) or
|
Until (Not (Result in [tjsComment,tjsWhitespace])) or
|
||||||
((Result=tjsComment) and ReturnComments) or
|
((Result=tjsComment) and ReturnComments) or
|
||||||
((Result=tjsWhiteSpace) and ReturnWhiteSpace);
|
((Result=tjsWhiteSpace) and ReturnWhiteSpace);
|
||||||
FCurToken:=Result;
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJSScanner.IsEndOfLine: Boolean;
|
function TJSScanner.IsEndOfLine: Boolean;
|
||||||
@ -880,9 +897,10 @@ begin
|
|||||||
begin
|
begin
|
||||||
Olen:=Length(Result);
|
Olen:=Length(Result);
|
||||||
SetLength(Result,OLen+Len);
|
SetLength(Result,OLen+Len);
|
||||||
Move(Buffer[FPos],Result[OLen+1],Len)
|
Move(Buffer[FPos],Result[OLen+1],Len);
|
||||||
end;
|
end;
|
||||||
FillBuffer;
|
FillBuffer;
|
||||||
|
FPos:=FBufPos;
|
||||||
end;
|
end;
|
||||||
until (FBufPos=FBufLen) or (PRun^ in [10,13]);
|
until (FBufPos=FBufLen) or (PRun^ in [10,13]);
|
||||||
Len:=FBufPos-FPos;
|
Len:=FBufPos-FPos;
|
||||||
|
Loading…
Reference in New Issue
Block a user