PpTokenCount¶
Keeps a count of Preprocessing tokens.
-
exception
cpip.core.PpTokenCount.
ExceptionPpTokenCount
¶ Exception when handling PpTokenCount object.
-
exception
cpip.core.PpTokenCount.
ExceptionPpTokenCountStack
¶ Exception when handling PpTokenCountStack object.
-
class
cpip.core.PpTokenCount.
PpTokenCount
¶ Maps of
{token_type : integer_count, ...}
self._cntrTokAll is all tokens.-
__iadd__
(other)¶ In-place add of the contents of another PpTokenCount object.
Parameters: other ( cpip.core.PpTokenCount.PpTokenCount
) – Other object.Returns: cpip.core.PpTokenCount.PpTokenCount
– Self.
-
__weakref__
¶ list of weak references to the object (if defined)
-
_inc
(tokStr, isUnCond, num)¶ Increment the count. tok is a string, isUnCond is a boolean that is True if this is not conditionally compiled. num is the number of tokens to increment.
Parameters: - tokStr (
str
) – The token type. - isUnCond (
bool
) – True if this is not conditionally compiled. - num (
int
) – Number of tokens.
Returns: NoneType
- tokStr (
-
inc
(tok, isUnCond, num=1)¶ Increment the count. tok is a PpToken, isUnCond is a boolean that is True if this is not conditionally compiled. num is the number of tokens to increment.
Parameters: - tok (
cpip.core.PpToken.PpToken
) – The token. - isUnCond (
bool
) – True if this is not conditionally compiled. - num (
int
) – Number of tokens. Default 1.
Returns: NoneType
- tok (
-
tokenCount
(theType, isAll)¶ Returns the token count including whitespace tokens.
Parameters: isAll ( bool
) – IfisAll
isTrue
then the count of all tokens is returned, ifFalse
the count of unconditional tokens is returned.Returns: int
– Count of tokens.
-
tokenCountNonWs
(isAll)¶ Returns the token count excluding whitespace tokens.
Parameters: isAll ( bool
) – IfisAll
isTrue
then the count of all tokens is returned, ifFalse
the count of unconditional tokens is returned.Returns: int
– Count of tokens.
-
tokenTypesAndCounts
(isAll, allPossibleTypes=True)¶ Generator the yields
(type, count)
inPpToken.LEX_PPTOKEN_TYPES
order where type is a string and count an integer.Parameters: - isAll (
bool
) – IfisAll
isTrue
then the count of all tokens is returned. IfFalse
the count of unconditional tokens is returned. - allPossibleTypes (
bool
) – IfallPossibleTypes
isTrue
the counts of all token types are yielded even if zero, ifFalse
then only token types encountered will be yielded i.e. all counts will be non-zero.
Returns: NoneType,tuple([str, int])
– Yields(type, count)
.- isAll (
-
totalAll
¶ The total token count.
Returns: int
– The count.
-
totalAllConditional
¶ The token count of conditional tokens.
Returns: int
– The count.
-
totalAllUnconditional
¶ The token count of unconditional tokens.
Returns: int
– The count.
-
-
class
cpip.core.PpTokenCount.
PpTokenCountStack
¶ This simply holds a stack of PpTokenCount objects that can be created and popped of the stack.
-
__init__
()¶ ctor with empty stack.
-
__weakref__
¶ list of weak references to the object (if defined)
-
close
()¶ Finalisation, will raise a ExceptionPpTokenCountStack if there is anything on the stack.
-
counter
()¶ Returns a reference to the current PpTokenCount object.
-
pop
()¶ Pops the current PpTokenCount object off the stack and returns it.
-
push
()¶ Add a new counter object to the stack.
-