public void parseSegments() {
    if (!toParseSegments) {
      return;
    }

    String templateRawText = myString;
    StringBuilder buffer;
    synchronized (mySegments) {
      if (myParsed) {
        return;
      }

      buffer = new StringBuilder(templateRawText.length());
      TemplateTextLexer lexer = new TemplateTextLexer();
      lexer.start(templateRawText);

      while (true) {
        IElementType tokenType = lexer.getTokenType();
        if (tokenType == null) break;
        int start = lexer.getTokenStart();
        int end = lexer.getTokenEnd();
        String token = templateRawText.substring(start, end);
        if (tokenType == TemplateTokenType.VARIABLE){
          String name = token.substring(1, token.length() - 1);
          Segment segment = new Segment(name, buffer.length());
          mySegments.add(segment);
        }
        else if (tokenType == TemplateTokenType.ESCAPE_DOLLAR){
          buffer.append("$");
        }
        else{
          buffer.append(token);
        }
        lexer.advance();
      }
      myParsed = true;
    }
    myTemplateText = buffer.toString();
  }
public void parseSegments()