Namespace: utils
Table of contents
Functions
- addLeftIndent
- codeGenerator
- getConversionFunctionIdentifier
- getNaturalOrZero
- getParseRuleSource
- getParseTreeSource
- getTokenIntervalSource
- getTokenSource
- inverseMap
- replaceObjKeys
- titleCase
Functions
addLeftIndent
▸ addLeftIndent(msg
, firstLinePrefix?
, spaces?
): string
Adds a left indentation to the message with the specified amount of spaces.
Since
0.11.0
Parameters
Name | Type | Default value | Description |
---|---|---|---|
msg |
string |
undefined |
The message to indent. |
firstLinePrefix |
string |
"" |
The prefix to add to the message on the first line. |
spaces |
number |
2 |
The amount of spaces to indent the message with. |
Returns
string
Defined in
kipper/core/src/tools/functions/indent.ts:8
codeGenerator
▸ codeGenerator(target
): (target
: any
, propertyKey
: string
, descriptor
: PropertyDescriptor
) => void
A decorator function which registers the given method as a code generator for the specified target.
By applying this decorator to a method, the method will be automatically called when the compiler is generating code for the specified target.
Since
0.11.0
Parameters
Name | Type | Description |
---|---|---|
target |
ASTKind |
The number identifier of the target for which the decorated method should be called. This number can be fetched from the kind property. |
Returns
fn
▸ (target
, propertyKey
, descriptor
): void
Parameters
Name | Type |
---|---|
target |
any |
propertyKey |
string |
descriptor |
PropertyDescriptor |
Returns
void
Defined in
kipper/core/src/tools/decorators/code-generator.ts:16
getConversionFunctionIdentifier
▸ getConversionFunctionIdentifier(originalType
, destType
): string
Generates for the specific types the corresponding conversion function identifier that should be implemented by the KipperTargetBuiltInGenerator.
Since
0.8.0
Parameters
Name | Type | Description |
---|---|---|
originalType |
string |
The original type. |
destType |
string |
The type to convert to. |
Returns
string
Defined in
kipper/core/src/tools/functions/other.ts:31
getNaturalOrZero
▸ getNaturalOrZero(num
): number
Returns num unchanged if its positive, otherwise if its negative it will return 0.
Since
0.4.0
Parameters
Name | Type |
---|---|
num |
number |
Returns
number
Defined in
kipper/core/src/tools/functions/other.ts:10
getParseRuleSource
▸ getParseRuleSource(antlrCtx
): string
Returns the token source for the passed antlrCtx instance.
Since
0.4.0
Parameters
Name | Type | Description |
---|---|---|
antlrCtx |
KipperParserRuleContext |
The token antlr4 context. |
Returns
string
Defined in
kipper/core/src/tools/functions/parser-rules.ts:16
getParseTreeSource
▸ getParseTreeSource(inputStream
, parseTree
): string
Get the source code for a parse tree.
Since
0.6.0
Parameters
Name | Type | Description |
---|---|---|
inputStream |
CharStream |
The input stream to fetch from. |
parseTree |
ParseTree |
The parse tree. |
Returns
string
Defined in
kipper/core/src/tools/functions/parser-rules.ts:59
getTokenIntervalSource
▸ getTokenIntervalSource(inputStream
, start
, stop
): string
Get the source code for two tokens (interval between these two tokens).
Since
0.6.0
Parameters
Name | Type | Description |
---|---|---|
inputStream |
CharStream |
The input stream to fetch from. |
start |
Token |
The start token |
stop |
Token |
The stop token |
Returns
string
Defined in
kipper/core/src/tools/functions/parser-rules.ts:39
getTokenSource
▸ getTokenSource(inputStream
, token
): string
Get the source code for a single token.
Since
0.6.0
Parameters
Name | Type | Description |
---|---|---|
inputStream |
CharStream |
The input stream to fetch from. |
token |
Token |
The token to get the source code from. |
Returns
string
Defined in
kipper/core/src/tools/functions/parser-rules.ts:49
inverseMap
▸ inverseMap<T
>(obj
): InverseMap
<T
>
Returns a given object with its keys and value inverted.
Since
0.11.0
Type parameters
Name | Type |
---|---|
T |
extends Record string | number | symbol \> |
Parameters
Name | Type | Description |
---|---|---|
obj |
T |
The object to inverse. |
Returns
InverseMap
<T
>
Defined in
kipper/core/src/tools/functions/inverse-map.ts:8
replaceObjKeys
▸ replaceObjKeys<O
, N
, V
>(obj
, callback
): Record
<N
, V
>
Replaces the keys of an object with the result of the callback function.
Since
0.11.0
Type parameters
Name | Type |
---|---|
O |
extends string | number | symbol |
N |
extends string | number | symbol |
V |
any |
Parameters
Name | Type | Description |
---|---|---|
obj |
Record <O , V > |
The object to replace the keys of. |
callback |
(key : O ) => N |
The callback function to replace the keys with. |
Returns
Record
<N
, V
>
Defined in
kipper/core/src/tools/functions/replace-obj-keys.ts:7
titleCase
▸ titleCase(str
): string
Apply title-case formatting on the specific string e.g. the first character of a word/char sequence must always be uppercase.
Since
0.8.0
Parameters
Name | Type | Description |
---|---|---|
str |
string |
The string to modify. |
Returns
string
Defined in
kipper/core/src/tools/functions/other.ts:20