import * as _ from "lodash" ; class GrammarUtils { isSeparator ( c ) { return c == " " || c == "\r" || c == "\n" || c == "\t" || c == "(" || c == ")" ; } isWhiteSpace ( c ) { return c == " " || c == "\r" || c == "\n" || c == "\t" ; } findLastSeparatorIndex ( text ) { return _ . findLastIndex ( text , f => this . isSeparator ( f ) ) ; } needSpaceAfter ( char ) { return ! ( char == "(" ) ; } isLastCharacterWhiteSpace ( text ) { return ! ! text && this . isWhiteSpace ( text [ text . length - 1 ] ) ; } stripEndWithNonSeparatorCharacters ( text ) { if ( ! text ) return text ; if ( this . isSeparator ( text [ text . length - 1 ] ) ) { return text ; } var index = this . findLastSeparatorIndex ( text ) ; if ( index < 0 ) return "" ; return text . substr ( 0 , index + 1 ) ; } getEndNotSeparatorCharacers ( text ) { if ( ! text ) return text ; if ( this . isSeparator ( text [ text . length - 1 ] ) ) { return "" ; } var index = this . findLastSeparatorIndex ( text ) ; if ( index < 0 ) return text ; return text . substr ( index + 1 ) ; } } export default new GrammarUtils ( ) ;