Skip to content

Commit

Permalink
fcl-css: parse relational selector list
Browse files Browse the repository at this point in the history
  • Loading branch information
Felzomah committed Sep 19, 2022
1 parent 6454c93 commit 879b6f1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
35 changes: 27 additions & 8 deletions packages/fcl-css/src/fpcssparser.pp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ implementation
ctkMinus: Result:=uoMinus;
ctkPlus: Result:=uoPlus;
ctkDiv: Result:=uoDiv;
ctkGT: Result:=uoGT;
ctkTILDE: Result:=uoTilde;
else
Raise ECSSParser.CreateFmt(SUnaryInvalidToken,[GetEnumName(TypeInfo(aToken),Ord(aToken))]);
end;
Expand Down Expand Up @@ -950,7 +952,7 @@ function TCSSParser.ParseUnary: TCSSElement;

begin
Result:=nil;
if not (CurrentToken in [ctkDOUBLECOLON, ctkMinus, ctkPlus, ctkDiv]) then
if not (CurrentToken in [ctkDOUBLECOLON, ctkMinus, ctkPlus, ctkDiv, ctkGT, ctkTILDE]) then
Raise ECSSParser.CreateFmt(SUnaryInvalidToken,[CurrentTokenString]);
Un:=TCSSUnaryElement(CreateElement(TCSSUnaryElement));
try
Expand Down Expand Up @@ -1058,16 +1060,17 @@ function TCSSParser.ParseComponentValue: TCSSElement;
ctkLBRACKET: Result:=ParseArray(Nil);
ctkMinus,
ctkPlus,
ctkDiv: Result:=ParseUnary;
ctkDiv,
ctkGT,
ctkTilde: Result:=ParseUnary;
ctkUnicodeRange: Result:=ParseUnicodeRange;
ctkSTRING,
ctkHASH : Result:=ParseString;
ctkINTEGER: Result:=ParseInteger;
ctkFloat : Result:=ParseFloat;
ctkPSEUDOFUNCTION,
ctkFUNCTION : Result:=ParseCall('');
ctkSTAR,
ctkTILDE: Result:=ParseInvalidToken;
ctkSTAR: Result:=ParseInvalidToken;
ctkIDENTIFIER: Result:=ParseIdentifier;
ctkCLASSNAME : Result:=ParseClassName;
else
Expand Down Expand Up @@ -1426,14 +1429,30 @@ procedure TCSSParser.ParseSelectorCommaList(aCall: TCSSCallElement);
procedure TCSSParser.ParseRelationalSelectorCommaList(aCall: TCSSCallElement);
var
El: TCSSElement;
aToken: TCSSToken;
IsUnary: Boolean;
Unary: TCSSUnaryElement;
begin
while not (CurrentToken in [ctkEOF,ctkRBRACKET,ctkRBRACE,ctkRPARENTHESIS]) do
begin
if CurrentToken in [ctkGT,ctkPLUS,ctkTILDE,ctkPIPE] then
aCall.AddArg(ParseInvalidToken);
IsUnary:=false;
aToken:=CurrentToken;
if aToken in [ctkGT,ctkPLUS,ctkTILDE] then
begin
IsUnary:=true;
GetNextToken;
end;
El:=ParseSelector;
if EL=nil then exit;
aCall.AddArg(El);
if El=nil then exit;
if IsUnary then
begin
Unary:=TCSSUnaryElement(CreateElement(TCSSUnaryElement));
aCall.AddArg(Unary);
Unary.Right:=El;
Unary.Operation:=TokenToUnaryOperation(aToken);
end
else
aCall.AddArg(El);
if CurrentToken<>ctkCOMMA then
exit;
GetNextToken;
Expand Down
1 change: 0 additions & 1 deletion packages/fcl-css/src/fpcssresolver.pas
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
*: 0
ToDo:
- replace parser invalidtoken for relational operators ctkGt, ctkTilde
- :has()
- 'all' attribute: resets all properties, except direction and unicode bidi
- TCSSResolver.FindComputedAttribute use binary search for >8 elements
Expand Down
4 changes: 2 additions & 2 deletions packages/fcl-css/src/fpcsstree.pp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ TCSSFloatElement = class(TCSSElement)
end;

{ TCSSUnaryElement }
TCSSUnaryOperation = (uoDoubleColon,uoMinus,uoPlus,uoDiv);
TCSSUnaryOperation = (uoDoubleColon,uoMinus,uoPlus,uoDiv,uoGT,uoTilde);
TCSSUnaryElement = Class(TCSSBaseUnaryElement)
private
FOperation: TCSSUnaryOperation;
Expand Down Expand Up @@ -397,7 +397,7 @@ TCSSAtRuleElement = class(TCSSRuleElement)
CSSUnitNames : Array[TCSSUnits] of TCSSString =
('','px','%','rem','em','pt','fr','vw','vh','deg');
UnaryOperators : Array[TCSSUnaryOperation] of TCSSString =
('::','-','+','/');
('::','-','+','/','>','~');
BinaryOperators : Array[TCSSBinaryOperation] of TCSSString =
('=','+','-','and','<=','<','>=','>','/','*','~',':','::','^','|','$',' ',
'*=','~=','^=','|=','$=');
Expand Down
5 changes: 1 addition & 4 deletions packages/fcl-css/tests/tccsstree.pp
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,6 @@ procedure TCSSTreeAsStringTest.TestCALL;

procedure TCSSTreeAsStringTest.TestUNARYOP;

Const
MyUnaryOperators : Array[TCSSUnaryOperation] of string =
('::','-','+','/');
Var
Op : TCSSUnaryOperation;
Sop : String;
Expand All @@ -586,7 +583,7 @@ procedure TCSSTreeAsStringTest.TestUNARYOP;
For Op in TCSSUnaryOperation do
begin
CreateUnaryOperation(op,'a',amReplace);
Sop:=MyUnaryOperators[Op];
Sop:=UnaryOperators[Op];
if Not (Op in [uoDoubleColon]) then
Sop:=Sop+' ';
AssertEquals('Value '+Sop,sop+'a',Element.AsString)
Expand Down

0 comments on commit 879b6f1

Please sign in to comment.