|
|
|
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
|