51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
|
|
||
|
// This needs to support multiple commands in future
|
||
|
|
||
|
export interface Command{
|
||
|
commandName: string,
|
||
|
commandIdentifier: string,
|
||
|
}
|
||
|
|
||
|
export interface ApplicableToResult{
|
||
|
commands: Command[],
|
||
|
applicableTo: string,
|
||
|
}
|
||
|
|
||
|
export function parseApplicableTo(applicableTo:string) :ApplicableToResult {
|
||
|
|
||
|
let applicableToIter = applicableTo[Symbol.iterator]();
|
||
|
|
||
|
let applicableToOut = "";
|
||
|
|
||
|
let commands:Command[] = [];
|
||
|
let curCommandName = "";
|
||
|
let curCommandIdentifier = "";
|
||
|
|
||
|
let nextIter;
|
||
|
while(!(nextIter = applicableToIter.next()).done){
|
||
|
if (nextIter.value === "<" && applicableToIter.next().value === "<") {
|
||
|
let commandChar;
|
||
|
let commandName = "";
|
||
|
|
||
|
while((commandChar = applicableToIter.next()).value != ":"){
|
||
|
commandName += commandChar.value;
|
||
|
}
|
||
|
|
||
|
let commandIdentifier = "";
|
||
|
|
||
|
while((commandChar = applicableToIter.next()).value != ">"){
|
||
|
commandIdentifier += commandChar.value;
|
||
|
}
|
||
|
|
||
|
let _ = applicableToIter.next();
|
||
|
|
||
|
commands.push({commandIdentifier, commandName});
|
||
|
}else{
|
||
|
applicableToOut += nextIter.value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {applicableTo:applicableToOut, commands};
|
||
|
|
||
|
}
|