import { SourceCode } from "./SourceCode" ; import { AbstractParser } from "./AbstractParser" ; export const DefaultOptions = { separatorCharacters : [ "." , "．" , "。" , "?" , "!" , "？" , "！" ] } ; export interface SeparatorParserOptions { /**
     * Recognize each characters as separator
     * Example [".", "!", "?"]
     */ separatorCharacters ? : string [ ] ; } /**
 * Separator parser
 */ export class SeparatorParser implements AbstractParser { private separatorCharacters : string [ ] ; constructor ( readonly options ? ) { this . separatorCharacters = options && options . separatorCharacters ? options . separatorCharacters : DefaultOptions . separatorCharacters ; } test ( sourceCode ) { if ( sourceCode . isInContext ( ) ) { return false ; } if ( sourceCode . isInContextRange ( ) ) { return false ; } const firstChar = sourceCode . read ( ) ; const nextChar = sourceCode . read ( 1 ) ; if ( ! firstChar ) { return false ; } if ( ! this . separatorCharacters . includes ( firstChar ) ) { return false ; } if ( firstChar === "." ) { if ( nextChar ) { return /[\s\t\r\n]/ . test ( nextChar ) ; } else { return true ; } } return true ; } seek ( sourceCode ) { while ( this . test ( sourceCode ) ) { sourceCode . peek ( ) ; } } }