3434
3535All declarations for literals, aggregates, operators forming an expressions.
3636"""
37- from typing import Tuple , List , Iterable , Union
37+ from enum import Flag
38+ from typing import Tuple , List , Iterable , Union , ClassVar
3839
3940from pyTooling .Decorators import export , readonly
4041
@@ -196,14 +197,32 @@ def __str__(self) -> str:
196197 return "\" " + self ._value + "\" "
197198
198199
200+ @export
201+ class BitStringBase (Flag ):
202+ NoBase = 0
203+ Binary = 2
204+ Octal = 8
205+ Decimal = 10
206+ Hexadecimal = 16
207+ Unsigned = 32
208+ Signed = 64
209+
210+
199211@export
200212class BitStringLiteral (Literal ):
213+ # _base: ClassVar[BitStringBase]
201214 _value : str
215+ _bits : int
202216
203217 def __init__ (self , value : str ) -> None :
204218 super ().__init__ ()
219+ self ._bits = len (value )
205220 self ._value = value
206221
222+ @readonly
223+ def Bits (self ) -> int :
224+ return self ._bits
225+
207226 @readonly
208227 def Value (self ) -> str :
209228 return self ._value
@@ -212,6 +231,58 @@ def __str__(self) -> str:
212231 return "\" " + self ._value + "\" "
213232
214233
234+ @export
235+ class BinaryBitStringLiteral (BitStringLiteral ):
236+ _base : ClassVar [BitStringBase ] = BitStringBase .Binary
237+
238+ def __init__ (self , value : str , bits : int = 0 ) -> None :
239+ super ().__init__ (value )
240+ if bits > 0 :
241+ self ._bits = bits
242+
243+ def __str__ (self ) -> str :
244+ return "b\" " + self ._value + "\" "
245+
246+
247+ @export
248+ class OctalBitStringLiteral (BitStringLiteral ):
249+ _base : ClassVar [BitStringBase ] = BitStringBase .Octal
250+
251+ def __init__ (self , value : str , bits : int = 0 ) -> None :
252+ super ().__init__ (value )
253+ if bits > 0 :
254+ self ._bits = bits
255+
256+ def __str__ (self ) -> str :
257+ return "o\" " + self ._value + "\" "
258+
259+
260+ @export
261+ class DecimalBitStringLiteral (BitStringLiteral ):
262+ _base : ClassVar [BitStringBase ] = BitStringBase .Decimal
263+
264+ def __init__ (self , value : str , bits : int = 0 ) -> None :
265+ super ().__init__ (value )
266+ if bits > 0 :
267+ self ._bits = bits
268+
269+ def __str__ (self ) -> str :
270+ return "d\" " + self ._value + "\" "
271+
272+
273+ @export
274+ class HexadecimalBitStringLiteral (BitStringLiteral ):
275+ _base : ClassVar [BitStringBase ] = BitStringBase .Hexadecimal
276+
277+ def __init__ (self , value : str , bits : int = 0 ) -> None :
278+ super ().__init__ (value )
279+ if bits > 0 :
280+ self ._bits = bits
281+
282+ def __str__ (self ) -> str :
283+ return "x\" " + self ._value + "\" "
284+
285+
215286@export
216287class ParenthesisExpression : #(Protocol):
217288 __slots__ = () # FIXME: use ExtendedType?
0 commit comments