You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.0 KiB
41 lines
1.0 KiB
export enum ScriptValueType {
|
|
NUMBER = "number",
|
|
IDENTIFIER = "identifier",
|
|
}
|
|
|
|
export interface NumberValue {
|
|
readonly type: ScriptValueType.NUMBER,
|
|
readonly value: number,
|
|
}
|
|
export function numberValue(value: number|string): NumberValue {
|
|
if (typeof value === "string") {
|
|
return {
|
|
type: ScriptValueType.NUMBER,
|
|
value: parseInt(value, 10),
|
|
}
|
|
} else {
|
|
return {
|
|
type: ScriptValueType.NUMBER,
|
|
value,
|
|
}
|
|
}
|
|
}
|
|
export function isNumberValue(value: ScriptValue): value is NumberValue {
|
|
return value.type === ScriptValueType.NUMBER
|
|
}
|
|
|
|
export interface ScriptIdentifier {
|
|
readonly type: ScriptValueType.IDENTIFIER
|
|
readonly value: string
|
|
}
|
|
export function identifier(value: string): ScriptIdentifier {
|
|
return {
|
|
type: ScriptValueType.IDENTIFIER,
|
|
value
|
|
}
|
|
}
|
|
export function isIdentifier(value: ScriptValue): value is ScriptIdentifier {
|
|
return value.type === ScriptValueType.IDENTIFIER
|
|
}
|
|
|
|
export type ScriptValue = NumberValue|ScriptIdentifier |