export class ExpressionRegexBuilder { private readonly parts = new Array < string > ( ) ; public expectCharacters ( characters ) { return this . addRawRegex ( characters . replaceAll ( '$' , '\\$' ) . replaceAll ( '.' , '\\.' ) ) ; } public expectOneOrMoreWhitespaces ( ) { return this . addRawRegex ( '\\s+' ) ; } public matchPipeline ( ) { return this . expectZeroOrMoreWhitespaces ( ) . addRawRegex ( '(\\|\\s*.+?)?' ) ; } public matchUntilFirstWhitespace ( ) { return this . addRawRegex ( '([^|\\s]+)' ) ; } public matchAnythingExceptSurroundingWhitespaces ( ) { return this . expectZeroOrMoreWhitespaces ( ) . addRawRegex ( '(.+?)' ) . expectZeroOrMoreWhitespaces ( ) ; } public expectExpressionStart ( ) { return this . expectCharacters ( '{{' ) . expectZeroOrMoreWhitespaces ( ) ; } public expectExpressionEnd ( ) { return this . expectZeroOrMoreWhitespaces ( ) . expectCharacters ( '}}' ) ; } public buildRegExp ( ) { return new RegExp ( this . parts . join ( '' ) , 'g' ) ; } private expectZeroOrMoreWhitespaces ( ) { return this . addRawRegex ( '\\s*' ) ; } private addRawRegex ( regex ) { this . parts . push ( regex ) ; return this ; } }