##// END OF EJS Templates
working on text writer
working on text writer

File last commit:

r79:51649f0f8acd default
r79:51649f0f8acd default
Show More
FormatCompiler.ts
61 lines | 1.7 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / text / FormatCompiler.ts
cin
working on text writer
r79 import { FormatScanner, TokeType } from "./FormatScanner";
export class FormatCompiler {
visitText(scanner: FormatScanner) {
while (scanner.next()) {
if (scanner.getTokenType() === TokeType.CurlOpen)
this.visitCurlOpen(scanner);
}
}
visitCurlOpen(scanner: FormatScanner) {
if (scanner.next()) {
if (scanner.getTokenType() === TokeType.CurlOpen)
this.pushText("{");
else
this.visitTemplateSubst(scanner);
}
}
visitTemplateSubst(scanner: FormatScanner) {
if (scanner.getTokenType() !== TokeType.Text)
this.dieUnexpectedToken(scanner);
const fieldName = scanner.getTokenValue();
let filedFormat: string;
if (this.readColon(scanner)) {
filedFormat = this.readFieldFormat(scanner);
} else {
if (scanner.getTokenType() !== TokeType.CurlClose)
this.dieUnexpectedToken(scanner);
}
this.pushSubst(fieldName, filedFormat);
}
pushSubst(fieldName: string, filedFormat: string) {
throw new Error("Method not implemented.");
}
readFieldFormat(scanner: FormatScanner): string {
throw new Error("Method not implemented.");
}
readColon(scanner: FormatScanner) {
if (!scanner.next())
this.dieUnexpectedEnd();
if (scanner.getTokenType() !== TokeType.Colon)
return false;
}
pushText(text: string) {
}
dieUnexpectedToken(scanner: FormatScanner) {
throw new Error(`Unexpected token ${scanner.getTokenValue()}`);
}
dieUnexpectedEnd() {
throw new Error("Unexpected end of string");
}
}