public IElementType captureFormat(){
  popState();
  CharSequence buffer=getBuffer();
  int tokenStart=getTokenEnd();
  setTokenStart(tokenStart);
  int bufferEnd=getBufferEnd();
  int currentPosition=tokenStart;
  int linePos=currentPosition;
  while (true) {
    while (linePos < bufferEnd && buffer.charAt(linePos) != '\n' && buffer.charAt(linePos) != '\r') {
      linePos++;
    }
    int lineContentsEnd=linePos;
    if (linePos < bufferEnd && buffer.charAt(linePos) == '\r') {
      linePos++;
    }
    if (linePos < bufferEnd && buffer.charAt(linePos) == '\n') {
      linePos++;
    }
    if (lineContentsEnd == currentPosition + 1 && buffer.charAt(currentPosition) == '.') {
      preparsedTokensList.clear();
      preparsedTokensList.add(new CustomToken(currentPosition,lineContentsEnd,FORMAT_TERMINATOR));
      if (currentPosition > tokenStart) {
        setTokenStart(tokenStart);
        setTokenEnd(currentPosition);
        return FORMAT;
      }
 else {
        return getPreParsedToken();
      }
    }
 else     if (linePos == bufferEnd) {
      if (currentPosition > tokenStart) {
        setTokenStart(tokenStart);
        setTokenEnd(currentPosition);
        return FORMAT;
      }
 else {
        return null;
      }
    }
    currentPosition=linePos;
  }
}

public IElementType captureFormat ( ) { popState ( ) ; CharSequence buffer = getBuffer ( ) ; int tokenStart = getTokenEnd ( ) ; setTokenStart ( tokenStart ) ; int bufferEnd = getBufferEnd ( ) ; int currentPosition = tokenStart ; int linePos = currentPosition ; while ( true ) { while ( linePos < bufferEnd && buffer . charAt ( linePos ) != '\n' && buffer . charAt ( linePos ) != '\r' ) { linePos ++ ; } int lineContentsEnd = linePos ; if ( linePos < bufferEnd && buffer . charAt ( linePos ) == '\r' ) { linePos ++ ; } if ( linePos < bufferEnd && buffer . charAt ( linePos ) == '\n' ) { linePos ++ ; } if ( lineContentsEnd == currentPosition + 1 && buffer . charAt ( currentPosition ) == '.' ) { preparsedTokensList . clear ( ) ; preparsedTokensList . add ( new CustomToken ( currentPosition , lineContentsEnd , FORMAT_TERMINATOR ) ) ; if ( currentPosition > tokenStart ) { setTokenStart ( tokenStart ) ; setTokenEnd ( currentPosition ) ; return FORMAT ; } else { return getPreParsedToken ( ) ; } } else if ( linePos == bufferEnd ) { if ( currentPosition > tokenStart ) { setTokenStart ( tokenStart ) ; setTokenEnd ( currentPosition ) ; return FORMAT ; } else { return null ; } } currentPosition = linePos ; } }
captures format ; fixme refactor with captureheredoc got common parts
