CurlyFoldParser
Date: 2017-02-11

org.fife.ui.rsyntaxtextarea.folding

## Class CurlyFoldParser

- java.lang.Object
- - org.fife.ui.rsyntaxtextarea.folding.CurlyFoldParser

- All Implemented Interfaces:
    FoldParser
  Direct Known Subclasses:
    LispFoldParser

      public class CurlyFoldParser
      extends java.lang.Object
      implements FoldParser

  A basic fold parser that can be used for languages such as C, that use curly braces to denote code blocks. This parser searches for curly brace pairs and creates code folds out of them. It can also optionally find C-style multi-line comments ("`/* ... */`") and make them foldable as well.

  This parser knows nothing about language semantics; it uses `RSyntaxTextArea`'s syntax highlighting tokens to identify curly braces. By default, it looks for single-char tokens of type `TokenTypes.SEPARATOR`, with lexemes '`{`' or '`}`'. If your `TokenMaker` uses a different token type for curly braces, you should override the `isLeftCurly(Token)` and `isRightCurly(Token)` methods with your own definitions. In theory, you could extend this fold parser to parse languages that use completely different tokens than curly braces to denote foldable regions by overriding those two methods.

  Note also that this class may impose somewhat of a performance penalty on large source files, since it re-parses the entire document each time folds are reevaluated.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static char[]` | `C_MLC_END` Ending of a multi-line comment in C, C++, Java, etc.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CurlyFoldParser()` Creates a fold parser that identifies foldable regions via curly braces as well as C-style multi-line comments.
    `CurlyFoldParser(boolean cStyleMultiLineComments, boolean java)` Constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `getFoldableMultiLineComments()` Returns whether multi-line comments are foldable with this parser.
    `java.util.List<Fold>` | `getFolds(RSyntaxTextArea textArea)` Returns a list of all folds in the text area.
    `boolean` | `isLeftCurly(Token t)` Returns whether the token is a left curly brace.
    `boolean` | `isRightCurly(Token t)` Returns whether the token is a right curly brace.
    `void` | `setFoldableMultiLineComments(boolean foldable)` Sets whether multi-line comments are foldable with this parser.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### C_MLC_END

          protected static final char[] C_MLC_END

      Ending of a multi-line comment in C, C++, Java, etc.

  - ### Constructor Detail

    - #### CurlyFoldParser

          public CurlyFoldParser()

      Creates a fold parser that identifies foldable regions via curly braces as well as C-style multi-line comments.

    - #### CurlyFoldParser

          public CurlyFoldParser(boolean cStyleMultiLineComments,
                         boolean java)

      Constructor.
      Parameters:
        `cStyleMultiLineComments` - Whether to scan for C-style multi-line comments and make them foldable.
        `java` - Whether this parser is folding Java. This adds extra parsing rules, such as grouping all import statements into a fold section.

  - ### Method Detail

    - #### getFoldableMultiLineComments

          public boolean getFoldableMultiLineComments()

      Returns whether multi-line comments are foldable with this parser.
      Returns:
        Whether multi-line comments are foldable.
      See Also:
        `setFoldableMultiLineComments(boolean)`

    - #### getFolds

          public java.util.List<Fold> getFolds(RSyntaxTextArea textArea)

      Returns a list of all folds in the text area.
      Specified by:
        `getFolds` in interface `FoldParser`
      Parameters:
        `textArea` - The text area whose contents should be analyzed.
      Returns:
        The list of folds. If this method returns `null`, it is treated as if no folds were found.

    - #### isLeftCurly

          public boolean isLeftCurly(Token t)

      Returns whether the token is a left curly brace. This method exists so subclasses can provide their own curly brace definition.
      Parameters:
        `t` - The token.
      Returns:
        Whether it is a left curly brace.
      See Also:
        `isRightCurly(Token)`

    - #### isRightCurly

          public boolean isRightCurly(Token t)

      Returns whether the token is a right curly brace. This method exists so subclasses can provide their own curly brace definition.
      Parameters:
        `t` - The token.
      Returns:
        Whether it is a right curly brace.
      See Also:
        `isLeftCurly(Token)`

    - #### setFoldableMultiLineComments

          public void setFoldableMultiLineComments(boolean foldable)

      Sets whether multi-line comments are foldable with this parser.
      Parameters:
        `foldable` - Whether multi-line comments are foldable.
      See Also:
        `getFoldableMultiLineComments()`