##// END OF EJS Templates
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version
Added childContainer service to container services, ServiceContaier is destroyable, fixed browser Uuid version

File last commit:

r115:691199f665e0 ioc ts support
r146:f3f5c56d3b3e v1.4.0-rc5 default
Show More
FormatCompiler.ts
134 lines | 4.0 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / text / FormatCompiler.ts
cin
working on text writer
r79 import { FormatScanner, TokeType } from "./FormatScanner";
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 import { isNullOrEmptyString, isPrimitive, get } from "../safe";
import { TextWriter, MapOf } from "../interfaces";
type CompiledPattern = (writer: TextWriter, args: any) => void;
cin
working on text writer
r79
export class FormatCompiler {
cin
Working on text writer
r81 _scanner: FormatScanner;
cin
corrected code to support ts strict mode...
r115 static _cache: MapOf<CompiledPattern> = {};
_parts: Array<string | { name: string; format?: string; }>;
constructor(scanner: FormatScanner) {
this._scanner = scanner;
this._parts = [];
}
cin
working on text writer
r79
cin
corrected code to support ts strict mode...
r115 compile() {
this.visitText();
const parts = this._parts;
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82
cin
corrected code to support ts strict mode...
r115 return (writer: TextWriter, args: any) => {
parts.forEach(x => {
if (isPrimitive(x))
writer.writeValue(x);
else
writer.writeValue(get(x.name, args), x.format);
});
};
}
static compile(pattern: string) {
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 let compiledPattern = this._cache && this._cache[pattern];
if (!compiledPattern) {
cin
corrected code to support ts strict mode...
r115 const compiler = new this(new FormatScanner(pattern));
cin
Working on text writer
r81
cin
corrected code to support ts strict mode...
r115 compiledPattern = compiler.compile();
this._cache[pattern] = compiledPattern;
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 }
return compiledPattern;
cin
Working on text writer
r81 }
visitText() {
while (this._scanner.next()) {
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 // console.log(this._scanner.getTokenType(), this._scanner.getTokenValue());
cin
Working on text writer
r81 switch (this._scanner.getTokenType()) {
case TokeType.CurlOpen:
this.visitCurlOpen();
break;
case TokeType.CurlClose:
this.visitCurlClose();
break;
default:
this.pushText(this._scanner.getTokenValue());
}
cin
working on text writer
r79 }
}
cin
Working on text writer
r81 visitCurlClose() {
if (!this._scanner.next())
this.dieUnexpectedEnd("}");
if (this._scanner.getTokenType() !== TokeType.CurlClose)
this.dieUnexpectedToken("}");
this.pushText("}");
}
visitCurlOpen() {
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 if (!this._scanner.next())
this.dieUnexpectedEnd("{ | TEXT");
if (this._scanner.getTokenType() === TokeType.CurlOpen)
this.pushText("{");
else
this.visitTemplateSubst();
cin
working on text writer
r79 }
cin
Working on text writer
r81 visitTemplateSubst() {
if (this._scanner.getTokenType() !== TokeType.Text)
this.dieUnexpectedToken("TEXT");
cin
working on text writer
r79
cin
Working on text writer
r81 const fieldName = this._scanner.getTokenValue();
cin
corrected code to support ts strict mode...
r115 const filedFormat = this.readColon() ? this.readFieldFormat() : undefined;
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82
if (this._scanner.getTokenType() !== TokeType.CurlClose)
this.dieUnexpectedToken("}");
cin
working on text writer
r79
this.pushSubst(fieldName, filedFormat);
}
cin
Added ObservableValue...
r80
cin
Working on text writer
r81 readFieldFormat() {
const parts = new Array<string>();
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 do {
cin
Working on text writer
r81 if (this._scanner.getTokenType() === TokeType.CurlClose) {
return parts.join("");
} else {
parts.push(this._scanner.getTokenValue());
}
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 } while (this._scanner.next());
cin
Working on text writer
r81
this.dieUnexpectedEnd("}");
cin
working on text writer
r79 }
cin
Added ObservableValue...
r80
cin
Working on text writer
r81 readColon() {
if (!this._scanner.next())
this.dieUnexpectedEnd();
if (this._scanner.getTokenType() !== TokeType.Colon)
return false;
if (!this._scanner.next())
this.dieUnexpectedEnd();
return true;
cin
working on text writer
r79 }
cin
Added ObservableValue...
r80
cin
corrected code to support ts strict mode...
r115 pushSubst(fieldName: string, filedFormat?: string) {
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 // console.log("pushSubst ", fieldName, filedFormat);
this._parts.push({ name: fieldName, format: filedFormat });
cin
working on text writer
r79 }
pushText(text: string) {
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 this._parts.push(text);
cin
working on text writer
r79 }
cin
corrected code to support ts strict mode...
r115 dieUnexpectedToken(expected?: string): never {
cin
Working on text writer
r81 throw new Error(isNullOrEmptyString(expected) ?
`Unexpected token ${this._scanner.getTokenValue()}` :
`Unexpected token ${this._scanner.getTokenValue()}, expected ${expected}`
);
cin
working on text writer
r79 }
cin
corrected code to support ts strict mode...
r115 dieUnexpectedEnd(expected?: string): never {
cin
Working on text writer
r81 throw new Error(isNullOrEmptyString(expected) ? "Unexpected end of the string" : `Unexpected end of the string, expected ${expected}`);
cin
working on text writer
r79 }
}