code: public int getDirective(char[] array, int currentIndex, StringBuffer velocityBlock, VelocityParserContext context)
          throws InvalidVelocityException
      {
          int i = currentIndex + 1;
  
          // Get macro name
          StringBuffer directiveNameBuffer = new StringBuffer();
          i = getDirectiveName(array, i, directiveNameBuffer, null, context);
  
          String directiveName = directiveNameBuffer.toString();
  
          if (!VELOCITYDIRECTIVE_NOPARAM.contains(directiveName)) {
              // Skip spaces
              while (i < array.length && array[i] == ' ') {
                  ++i;
              }
  
              if (i < array.length && array[i] == '(') {
                  // Skip condition
                  i = getMethodParameters(array, i, null, context);
              } else {
                  throw new InvalidVelocityException();
              }
          }
  
          if (VELOCITYDIRECTIVE_ALL.contains(directiveName)) {
              if (VELOCITYDIRECTIVE_BEGIN.contains(directiveName)) {
                  context.pushVelocityElement(new VelocityBlock(directiveName, VelocityBlock.VelocityType.DIRECTIVE));
              } else if (VELOCITYDIRECTIVE_END.contains(directiveName)) {
                  context.popVelocityElement();
              }
  
              // consume the end of the line
              i = getDirectiveEndOfLine(array, i, null, context);
  
              context.setType(VelocityBlock.VelocityType.DIRECTIVE);
          } else {
              context.setType(VelocityBlock.VelocityType.MACRO);
          }
  
          if (velocityBlock != null) {
              velocityBlock.append(array, currentIndex, i - currentIndex);
          }
  
          return i;
      }
docs: Get any valid Velocity block starting with a sharp character except comments.
  
  @param array the source to parse
  @param currentIndex the current index in the <code>array</code>
  @param velocityBlock the buffer where to append matched velocity block
  @param context the parser context to put some informations
  @return the index in the <code>array</code> after the matched block
  @throws InvalidVelocityException not a valid velocity block