1 | /*
|
---|
2 | * 02/24/2004
|
---|
3 | *
|
---|
4 | * TokenMaker.java - An object that can take a chunk of text and return a
|
---|
5 | * linked list of <code>Token</code>s representing it.
|
---|
6 | *
|
---|
7 | * This library is distributed under a modified BSD license. See the included
|
---|
8 | * RSyntaxTextArea.License.txt file for details.
|
---|
9 | */
|
---|
10 | package org.fife.ui.rsyntaxtextarea;
|
---|
11 |
|
---|
12 | import javax.swing.Action;
|
---|
13 | import javax.swing.text.Segment;
|
---|
14 |
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * An implementation of <code>TokenMaker</code> is a class that turns text into
|
---|
18 | * a linked list of <code>Token</code>s for syntax highlighting
|
---|
19 | * in a particular language.
|
---|
20 | *
|
---|
21 | * @see Token
|
---|
22 | * @see AbstractTokenMaker
|
---|
23 | *
|
---|
24 | * @author Robert Futrell
|
---|
25 | * @version 0.2
|
---|
26 | */
|
---|
27 | public interface TokenMaker {
|
---|
28 |
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Adds a null token to the end of the current linked list of tokens.
|
---|
32 | * This should be put at the end of the linked list whenever the last
|
---|
33 | * token on the current line is NOT a multi-line token.
|
---|
34 | */
|
---|
35 | public void addNullToken();
|
---|
36 |
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Adds the token specified to the current linked list of tokens.
|
---|
40 | *
|
---|
41 | * @param array The character array from which to get the text.
|
---|
42 | * @param start Start offset in <code>segment</code> of token.
|
---|
43 | * @param end End offset in <code>segment</code> of token.
|
---|
44 | * @param tokenType The token's type.
|
---|
45 | * @param startOffset The offset in the document at which this token
|
---|
46 | * occurs.
|
---|
47 | */
|
---|
48 | public void addToken(char[] array, int start, int end, int tokenType,
|
---|
49 | int startOffset);
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Returns whether this programming language uses curly braces
|
---|
54 | * ('<tt>{</tt>' and '<tt>}</tt>') to denote code blocks.
|
---|
55 | *
|
---|
56 | * @return Whether curly braces denote code blocks.
|
---|
57 | */
|
---|
58 | public boolean getCurlyBracesDenoteCodeBlocks();
|
---|
59 |
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Returns the last token on this line's type if the token is "unfinished",
|
---|
63 | * or {@link Token#NULL} if it was finished. For example, if C-style
|
---|
64 | * syntax highlighting is being implemented, and <code>text</code>
|
---|
65 | * contained a line of code that contained the beginning of a comment but
|
---|
66 | * no end-comment marker ("*\/"), then this method would return
|
---|
67 | * {@link Token#COMMENT_MULTILINE} for that line. This is useful
|
---|
68 | * for doing syntax highlighting.
|
---|
69 | *
|
---|
70 | * @param text The line of tokens to examine.
|
---|
71 | * @param initialTokenType The token type to start with (i.e., the value
|
---|
72 | * of <code>getLastTokenTypeOnLine</code> for the line before
|
---|
73 | * <code>text</code>).
|
---|
74 | * @return The last token on this line's type, or {@link Token#NULL}
|
---|
75 | * if the line was completed.
|
---|
76 | */
|
---|
77 | public int getLastTokenTypeOnLine(Segment text, int initialTokenType);
|
---|
78 |
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Returns the text to place at the beginning and end of a
|
---|
82 | * line to "comment" it in a this programming language.
|
---|
83 | *
|
---|
84 | * @return The start and end strings to add to a line to "comment"
|
---|
85 | * it out. A <code>null</code> value for either means there
|
---|
86 | * is no string to add for that part. A value of
|
---|
87 | * <code>null</code> for the array means this language
|
---|
88 | * does not support commenting/uncommenting lines.
|
---|
89 | */
|
---|
90 | public String[] getLineCommentStartAndEnd();
|
---|
91 |
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Returns an action to handle "insert break" key presses (i.e. Enter).
|
---|
95 | *
|
---|
96 | * @return The action, or <code>null</code> if the default action should
|
---|
97 | * be used.
|
---|
98 | */
|
---|
99 | public Action getInsertBreakAction();
|
---|
100 |
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Returns whether tokens of the specified type should have "mark
|
---|
104 | * occurrences" enabled for the current programming language.
|
---|
105 | *
|
---|
106 | * @param type The token type.
|
---|
107 | * @return Whether tokens of this type should have "mark occurrences"
|
---|
108 | * enabled.
|
---|
109 | */
|
---|
110 | public boolean getMarkOccurrencesOfTokenType(int type);
|
---|
111 |
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * If a line ends in the specified token, this method returns whether
|
---|
115 | * a new line inserted after that line should be indented.
|
---|
116 | *
|
---|
117 | * @param token The token the previous line ends with.
|
---|
118 | * @return Whether the next line should be indented.
|
---|
119 | */
|
---|
120 | public boolean getShouldIndentNextLineAfter(Token token);
|
---|
121 |
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Returns the first token in the linked list of tokens generated
|
---|
125 | * from <code>text</code>. This method must be implemented by
|
---|
126 | * subclasses so they can correctly implement syntax highlighting.
|
---|
127 | *
|
---|
128 | * @param text The text from which to get tokens.
|
---|
129 | * @param initialTokenType The token type we should start with.
|
---|
130 | * @param startOffset The offset into the document at which
|
---|
131 | * <code>text</code> starts.
|
---|
132 | * @return The first <code>Token</code> in a linked list representing
|
---|
133 | * the syntax highlighted text.
|
---|
134 | */
|
---|
135 | public Token getTokenList(Segment text, int initialTokenType,
|
---|
136 | int startOffset);
|
---|
137 |
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Returns whether this language is a markup language.
|
---|
141 | *
|
---|
142 | * @return Whether this language is markup.
|
---|
143 | */
|
---|
144 | public boolean isMarkupLanguage();
|
---|
145 |
|
---|
146 |
|
---|
147 | /**
|
---|
148 | * Returns whether whitespace is visible.
|
---|
149 | *
|
---|
150 | * @return Whether whitespace is visible.
|
---|
151 | * @see #setWhitespaceVisible(boolean)
|
---|
152 | */
|
---|
153 | public boolean isWhitespaceVisible();
|
---|
154 |
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Sets whether tokens are generated that "show" whitespace.
|
---|
158 | *
|
---|
159 | * @param visible Whether whitespace should be visible.
|
---|
160 | * @see #isWhitespaceVisible()
|
---|
161 | */
|
---|
162 | public void setWhitespaceVisible(boolean visible);
|
---|
163 |
|
---|
164 |
|
---|
165 | } |
---|