mirror of
https://github.com/github/codeql.git
synced 2026-05-05 21:55:19 +02:00
Codegen: add set to schema definitions
This commit is contained in:
@@ -25,6 +25,7 @@ class Property:
|
||||
OPTIONAL = auto()
|
||||
REPEATED_OPTIONAL = auto()
|
||||
PREDICATE = auto()
|
||||
REPEATED_UNORDERED = auto()
|
||||
|
||||
kind: Kind
|
||||
name: Optional[str] = None
|
||||
@@ -44,7 +45,11 @@ class Property:
|
||||
|
||||
@property
|
||||
def is_repeated(self) -> bool:
|
||||
return self.kind in (self.Kind.REPEATED, self.Kind.REPEATED_OPTIONAL)
|
||||
return self.kind in (self.Kind.REPEATED, self.Kind.REPEATED_OPTIONAL, self.Kind.REPEATED_UNORDERED)
|
||||
|
||||
@property
|
||||
def is_unordered(self) -> bool:
|
||||
return self.kind == self.Kind.REPEATED_UNORDERED
|
||||
|
||||
@property
|
||||
def is_predicate(self) -> bool:
|
||||
@@ -65,6 +70,7 @@ RepeatedProperty = functools.partial(Property, Property.Kind.REPEATED)
|
||||
RepeatedOptionalProperty = functools.partial(
|
||||
Property, Property.Kind.REPEATED_OPTIONAL)
|
||||
PredicateProperty = functools.partial(Property, Property.Kind.PREDICATE)
|
||||
RepeatedUnorderedProperty = functools.partial(Property, Property.Kind.REPEATED_UNORDERED)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -77,7 +77,7 @@ class _Optionalizer(_schema.PropertyModifier):
|
||||
K = _schema.Property.Kind
|
||||
if prop.kind != K.SINGLE:
|
||||
raise _schema.Error(
|
||||
"Optional should only be applied to simple property types")
|
||||
"optional should only be applied to simple property types")
|
||||
prop.kind = K.OPTIONAL
|
||||
|
||||
|
||||
@@ -90,7 +90,14 @@ class _Listifier(_schema.PropertyModifier):
|
||||
prop.kind = K.REPEATED_OPTIONAL
|
||||
else:
|
||||
raise _schema.Error(
|
||||
"Repeated should only be applied to simple or optional property types")
|
||||
"list should only be applied to simple or optional property types")
|
||||
|
||||
class _Setifier(_schema.PropertyModifier):
|
||||
def modify(self, prop: _schema.Property):
|
||||
K = _schema.Property.Kind
|
||||
if prop.kind != K.SINGLE:
|
||||
raise _schema.Error("set should only be applied to simple property types")
|
||||
prop.kind = K.REPEATED_UNORDERED
|
||||
|
||||
|
||||
class _TypeModifier:
|
||||
@@ -122,6 +129,7 @@ string = "string"
|
||||
predicate = _schema.predicate_marker
|
||||
optional = _TypeModifier(_Optionalizer())
|
||||
list = _TypeModifier(_Listifier())
|
||||
set = _TypeModifier(_Setifier())
|
||||
|
||||
child = _ChildModifier()
|
||||
doc = _DocModifier
|
||||
|
||||
Reference in New Issue
Block a user