Browse Source

webidl: extended attributes, exposed=*

mattias 3 years ago
parent
commit
2a7100be87

+ 28 - 28
packages/webidl/src/webidldefs.pp

@@ -23,9 +23,9 @@ uses
 
 Type
 
-  { TAttributeList }
+  { TExtAttributeList }
 
-  TAttributeList = Class(TPersistent)
+  TExtAttributeList = Class(TPersistent)
   private
     Fattrs: TStringList;
     function GetAttrs(aIndex : Integer): UTF8String;
@@ -56,12 +56,12 @@ Type
 
   TIDLDefinition = Class(TIDLBaseObject)
   private
-    FAttributes: TAttributeList;
+    FAttributes: TExtAttributeList;
     FData: TObject;
     FName: UTF8String;
     FParent: TIDLDefinition;
-    function GetAttributes: TAttributeList;
-    procedure SetAttributes(AValue: TAttributeList);
+    function GetAttributes: TExtAttributeList;
+    procedure SetAttributes(AValue: TExtAttributeList);
   Public
     Constructor Create(aParent : TIDLDefinition;Const aName : UTF8String); virtual;
     Function Add(aClass : TIDLDefinitionClass; Const AName : UTF8String) : TIDLDefinition; override;
@@ -75,7 +75,7 @@ Type
     Property Data : TObject Read FData Write FData;
     Property Parent : TIDLDefinition Read FParent Write FParent;
     // Attributes are owned by the definition. If you set it, your list will be freed by the definition
-    Property Attributes : TAttributeList Read GetAttributes Write SetAttributes;
+    Property Attributes : TExtAttributeList Read GetAttributes Write SetAttributes;
   end;
 
   { TIDLDefinitionList }
@@ -256,15 +256,15 @@ Type
   TIDLSerializerDefinition = Class(TIDLDefinition)
   private
     FKind: TSerializerKind;
-    FIdentifiers : TAttributeList;
+    FIdentifiers : TExtAttributeList;
     FSerializerFunction: TIDLFunctionDefinition;
-    procedure SetIdentifierList(AValue: TAttributeList);
+    procedure SetIdentifierList(AValue: TExtAttributeList);
     Procedure SetSerializerFunction (aValue : TIDLFunctionDefinition);
-    function GetIdentifierList: TAttributeList;
+    function GetIdentifierList: TExtAttributeList;
   Public
     Destructor Destroy; override;
     Function HasIdentifiers : Boolean;
-    Property Identifiers : TAttributeList Read GetIdentifierList Write SetIDentifierList;
+    Property Identifiers : TExtAttributeList Read GetIdentifierList Write SetIDentifierList;
     Property SerializerFunction : TIDLFunctionDefinition Read FSerializerFunction Write SetSerializerFunction;
     Property Kind : TSerializerKind Read FKind Write FKind;
   end;
@@ -659,7 +659,7 @@ begin
     Kind:=skFunction;
 end;
 
-procedure TIDLSerializerDefinition.SetIdentifierList(AValue: TAttributeList);
+procedure TIDLSerializerDefinition.SetIdentifierList(AValue: TExtAttributeList);
 begin
   If (FIdentifiers=AValue) then
     exit;
@@ -667,11 +667,11 @@ begin
   FAttributes:=AValue;
 end;
 
-function TIDLSerializerDefinition.GetIdentifierList: TAttributeList;
+function TIDLSerializerDefinition.GetIdentifierList: TExtAttributeList;
 
 begin
   If FIdentifiers=Nil then
-    FIdentifiers:=TAttributeList.Create;
+    FIdentifiers:=TExtAttributeList.Create;
   Result:=FIdentifiers;
 end;
 
@@ -1081,41 +1081,41 @@ begin
   Result:=Assigned(FPartials) and (FPartials.Count>0);
 end;
 
-{ TAttributeList }
+{ TExtAttributeList }
 
-function TAttributeList.GetAttrs(aIndex : Integer): UTF8String;
+function TExtAttributeList.GetAttrs(aIndex : Integer): UTF8String;
 begin
   Result:=FAttrs[aIndex];
 end;
 
-function TAttributeList.GetCount: Integer;
+function TExtAttributeList.GetCount: Integer;
 begin
   Result:=FAttrs.Count;
 end;
 
-constructor TAttributeList.Create;
+constructor TExtAttributeList.Create;
 begin
   Fattrs:=TStringList.Create;
 end;
 
-destructor TAttributeList.destroy;
+destructor TExtAttributeList.destroy;
 begin
   FreeAndNil(Fattrs);
   inherited;
 end;
 
-procedure TAttributeList.Assign(aSource: TPersistent);
+procedure TExtAttributeList.Assign(aSource: TPersistent);
 begin
-  If aSource is TAttributeList then
-    Fattrs.Assign(TAttributeList(aSource).Fattrs);
+  If aSource is TExtAttributeList then
+    Fattrs.Assign(TExtAttributeList(aSource).Fattrs);
 end;
 
-procedure TAttributeList.Add(aAttribute: UTF8String);
+procedure TExtAttributeList.Add(aAttribute: UTF8String);
 begin
   FAttrs.Add(aAttribute);
 end;
 
-function TAttributeList.ToLine(ASep: String): UTF8String;
+function TExtAttributeList.ToLine(ASep: String): UTF8String;
 
 Var
   I : Integer;
@@ -1130,7 +1130,7 @@ begin
     end;
 end;
 
-function TAttributeList.AsString(Full: Boolean): UTF8String;
+function TExtAttributeList.AsString(Full: Boolean): UTF8String;
 
 begin
   Result:=ToLine(',');
@@ -1138,7 +1138,7 @@ begin
     Result:='['+Result+']';
 end;
 
-function TAttributeList.IndexOf(const aName: UTF8string): Integer;
+function TExtAttributeList.IndexOf(const aName: UTF8string): Integer;
 begin
   Result:=Fattrs.IndexOf(aName);
 end;
@@ -1228,17 +1228,17 @@ end;
 
 { TIDLDefinition }
 
-procedure TIDLDefinition.SetAttributes(AValue: TAttributeList);
+procedure TIDLDefinition.SetAttributes(AValue: TExtAttributeList);
 begin
   if FAttributes=AValue then Exit;
   FreeAndNil(FAttributes);
   FAttributes:=AValue;
 end;
 
-function TIDLDefinition.GetAttributes: TAttributeList;
+function TIDLDefinition.GetAttributes: TExtAttributeList;
 begin
   if FAttributes=Nil then
-    Fattributes:=TAttributeList.Create;
+    Fattributes:=TExtAttributeList.Create;
   Result:=Fattributes;
 end;
 

+ 24 - 25
packages/webidl/src/webidlparser.pp

@@ -78,9 +78,9 @@ Type
     Procedure CheckCurrentTokens(aTokens: TIDLTokens);
     function ExpectToken(aToken: TIDLToken): TIDLToken;
     function ExpectTokens(aTokens: TIDLTokens): TIDLToken;
-    // Attributes
-    function ParseAttributes: TAttributeList;
-    procedure ParseAttributes(aList: TAttributeList; aTerminator: TIDLToken; ForSerializer: Boolean=False); virtual;
+    // Extended Attributes
+    function ParseExtAttributes: TExtAttributeList;
+    procedure ParseExtAttributes(aList: TExtAttributeList; aTerminator: TIDLToken; ForSerializer: Boolean=False); virtual;
     // Definitions
     // Type is a type without name of the type
     function ParseAttribute(aParent: TIDLBaseObject): TIDLAttributeDefinition; virtual;
@@ -233,18 +233,18 @@ end;
 // We're at the [,{,( token when we enter here
 // On exit, we're on the terminator token.
 
-procedure TWebIDLParser.ParseAttributes(aList: TAttributeList; aTerminator: TIDLToken; ForSerializer : Boolean = False);
+procedure TWebIDLParser.ParseExtAttributes(aList: TExtAttributeList; aTerminator: TIDLToken; ForSerializer : Boolean = False);
 
-  Function AddSub(aTerm : TIDLTOken) : String;
+  Function AddSub(aTerm : TIDLToken) : String;
 
   Var
-    L : TAttributeList;
+    L : TExtAttributeList;
 
   begin
     Result:=CurrentTokenString;
-    L:=TAttributeList.Create;
+    L:=TExtAttributeList.Create;
     try
-      ParseAttributes(L,aTerm,ForSerializer);
+      ParseExtAttributes(L,aTerm,ForSerializer);
       Result:=Trim(Result+L.ToLine(',')+CurrentTokenString);
     finally
       L.Free;
@@ -256,7 +256,7 @@ procedure TWebIDLParser.ParseAttributes(aList: TAttributeList; aTerminator: TIDL
   begin
     if (Current<>'') then
       Current:=Current+' ';
-    Current:=Current+aterm;
+    Current:=Current+aTerm;
   end;
 
   Procedure AddToList(Var aTerm : UTF8String);
@@ -272,7 +272,7 @@ procedure TWebIDLParser.ParseAttributes(aList: TAttributeList; aTerminator: TIDL
 
 Const
   OtherTokens = [tkNumberInteger,tkNumberFloat,tkIdentifier,tkString, {tkOther, tkMinus,}tkNegInfinity,
-                 tkDot,tkEllipsis,tkColon,tkSemicolon,tkLess,tkEqual,tkLarger,tkQuestionmark,tkByteString,
+                 tkDot,tkEllipsis,tkColon,tkSemicolon,tkLess,tkEqual,tkLarger,tkQuestionmark,tkStar,tkByteString,
                  tkDOMString,tkInfinity,tkNan,tkUSVString,tkAny,tkboolean,tkbyte,tkDouble,tkFalse,tkFloat,tkComma,
                  tkLong,tkNull,tkObject,tkOctet,tkOr,tkOptional,tkSequence,tkShort,tkTrue,tkUnsigned,tkVoid];
 
@@ -317,16 +317,15 @@ begin
   AddToList(S);
 end;
 
-function TWebIDLParser.ParseAttributes: TAttributeList;
-
+function TWebIDLParser.ParseExtAttributes: TExtAttributeList;
 
 var
   ok: Boolean;
 begin
-  Result:=TAttributeList.Create;
+  Result:=TExtAttributeList.Create;
   ok:=false;
   try
-    ParseAttributes(Result,tkSquaredBraceClose);
+    ParseExtAttributes(Result,tkSquaredBraceClose);
     ok:=true;
   finally
     if not ok then
@@ -352,7 +351,7 @@ begin
       end;
     if (CurrentToken=tkSquaredBraceOpen) then
       begin
-      Result.Attributes:=ParseAttributes;
+      Result.Attributes:=ParseExtAttributes;
       GetToken;
       end;
     Result.ArgumentType:=ParseType(Result,False);
@@ -843,12 +842,12 @@ begin
     case CurrentToken of
       tkSquaredBraceOpen :
         begin
-        ParseAttributes(Result.Identifiers,tkSquaredBraceClose,True);
+        ParseExtAttributes(Result.Identifiers,tkSquaredBraceClose,True);
         Result.Kind:=skArray;
         end;
       tkCurlyBraceOpen :
         begin
-        ParseAttributes(Result.Identifiers,tkCurlyBraceClose,True);
+        ParseExtAttributes(Result.Identifiers,tkCurlyBraceClose,True);
         Result.Kind:=skObject;
         end;
       tkIdentifier :
@@ -871,7 +870,7 @@ function TWebIDLParser.ParseInterface(aParent : TIDLBaseObject): TIDLInterfaceDe
 
 Var
   tk : TIDLToken;
-  Attrs : TAttributeList;
+  Attrs : TExtAttributeList;
   M : TIDLDefinition;
   isMixin,SemicolonSeen , ok: Boolean;
 
@@ -906,7 +905,7 @@ begin
       M:=Nil;
       if tk=tkSquaredBraceOpen then
         begin
-        Attrs:=ParseAttributes;
+        Attrs:=ParseExtAttributes;
         tk:=GetToken;
         end;
       Case tk of
@@ -1042,7 +1041,7 @@ function TWebIDLParser.ParseDictionaryMember(aParent : TIDLBaseObject): TIDLDict
   On Exit, we're on the ; }
 
 Var
-  Attrs : TAttributeList;
+  Attrs : TExtAttributeList;
   tk : TIDLToken;
   isReq , ok: Boolean;
   S : UTF8String;
@@ -1055,7 +1054,7 @@ begin
     tk:=GetToken;
   if tk=tkSquaredBraceOpen then
     begin
-    Attrs:=ParseAttributes;
+    Attrs:=ParseExtAttributes;
     tk:=GetToken;
     isReq:=(tk=tkRequired);
     if IsReq then
@@ -1145,7 +1144,7 @@ function TWebIDLParser.ParseUnionTypeDef(aParent : TIDLBaseObject): TIDLUnionTyp
 Var
   D : TIDLTypeDefDefinition;
   tk : TIDLToken;
-  Attr : TAttributeList;
+  Attr : TExtAttributeList;
   ok: Boolean;
 
 begin
@@ -1159,7 +1158,7 @@ begin
       tk:=GetToken;
       if Tk=tkSquaredBraceOpen then
         begin
-        Attr:=ParseAttributes;
+        Attr:=ParseExtAttributes;
         tk:=GetToken;
         end;
       D:=ParseType(Result.Union,False);
@@ -1352,7 +1351,7 @@ function TWebIDLParser.ParseDefinition(aParent : TIDLBaseObject): TIDLDefinition
 
 Var
   tk : TIDLToken;
-  Attrs : TAttributeList;
+  Attrs : TExtAttributeList;
 
 begin
   Result:=Nil;
@@ -1360,7 +1359,7 @@ begin
   tk:=GetToken;
   if tk=tkSquaredBraceOpen then
     begin
-    Attrs:=ParseAttributes;
+    Attrs:=ParseExtAttributes;
     tk:=GetToken;
     end;
   Try

+ 5 - 2
packages/webidl/src/webidlscanner.pp

@@ -64,7 +64,8 @@ type
     tkLarger, // '>'
     tkLargerEqual, // '>='
     tkQuestionmark, // '?'
-    tkminus, // '-'
+    tkMinus, // '-'
+    tkStar, // '*'
     tkIdentifier,            // Any  identifier
     tkTrue,
     tkFalse,
@@ -329,6 +330,7 @@ const
   '>=',
   '?',
   '-',
+  '*',
   '',            // Any  identifier
   'true',
   'false',
@@ -1498,6 +1500,7 @@ begin
       '>': SetSingleToken(tkLarger);
       '?' : SetSingleToken(tkQuestionmark);
       ';' : SetSingleToken(tkSemicolon);
+      '*' : SetSingleToken(tkStar);
       '.' :
          begin
          inc(TokenStr);
@@ -1535,7 +1538,7 @@ begin
         begin
         Result:=tkComment;
         HandleDirective;
-        end
+        end;
     else
       Error(SErrInvalidCharacter, [CurRow,CurColumn,TokenStr[0]]);
     end;

+ 12 - 5
packages/webidl/tests/tcidlparser.pp

@@ -111,7 +111,7 @@ Type
   Public
     Function ParseInterface(AName,aInheritance : UTF8String; AMembers : Array of UTF8String) : TIDLInterfaceDefinition;
     Property isMixin : Boolean Read FisMixin Write FisMixin;
-    Property CustAttributes : String Read FCustAttributes Write FCustAttributes;
+    Property ExtAttributes : String Read FCustAttributes Write FCustAttributes;
   end;
 
   { TTestInterfaceParser }
@@ -123,7 +123,8 @@ Type
     Procedure ParseEmptyInheritance;
     Procedure ParseMixinEmpty;
     Procedure ParseMixinEmptyInheritance;
-    Procedure ParseCustomAttributes1;
+    Procedure ParseExtendedAttributes1;
+    Procedure ParseExtendedAttributes_Exposed;
 
     Procedure ParseIfDefSkip;
     Procedure ParseIfNDefUse;
@@ -1410,10 +1411,16 @@ begin
   ParseInterface('A','B',[]);
 end;
 
-procedure TTestInterfaceParser.ParseCustomAttributes1;
+procedure TTestInterfaceParser.ParseExtendedAttributes1;
 begin
-  CustAttributes:='[Constructor(DOMString type,optional WebGLContextEventInit eventInit)]';
-  AssertEquals('Attributes',CustAttributes,ParseInterface('A','B',[]).Attributes.AsString(True));
+  ExtAttributes:='[Constructor(DOMString type,optional WebGLContextEventInit eventInit)]';
+  AssertEquals('Attributes',ExtAttributes,ParseInterface('A','B',[]).Attributes.AsString(True));
+end;
+
+procedure TTestInterfaceParser.ParseExtendedAttributes_Exposed;
+begin
+  ExtAttributes:='[Exposed = *]';
+  AssertEquals('Attributes',ExtAttributes,ParseInterface('A','',[]).Attributes.AsString(True));
 end;
 
 procedure TTestInterfaceParser.ParseIfDefSkip;