01: /*
02: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
03: * http://www.jaspersoft.com.
04: *
05: * Unless you have purchased a commercial license agreement from JasperSoft,
06: * the following license terms apply:
07: *
08: * This program is free software; you can redistribute it and/or modify
09: * it under the terms of the GNU General Public License version 2 as published by
10: * the Free Software Foundation.
11: *
12: * This program is distributed WITHOUT ANY WARRANTY; and without the
13: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14: * See the GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18: * or write to:
19: *
20: * Free Software Foundation, Inc.,
21: * 59 Temple Place - Suite 330,
22: * Boston, MA USA 02111-1307
23: *
24: *
25: *
26: *
27: * PropsTokenMarker.java
28: *
29: */
30:
31: package org.syntax.jedit.tokenmarker;
32:
33: import javax.swing.text.Segment;
34:
35: /**
36: * Java properties/DOS INI token marker.
37: *
38: * @author Slava Pestov
39: * @version $Id: PropsTokenMarker.java 1167 2008-01-15 18:49:05Z gtoffoli $
40: */
41: public class PropsTokenMarker extends TokenMarker {
42: public static final byte VALUE = Token.INTERNAL_FIRST;
43:
44: public byte markTokensImpl(byte token, Segment line, int lineIndex) {
45: char[] array = line.array;
46: int offset = line.offset;
47: int lastOffset = offset;
48: int length = line.count + offset;
49: loop: for (int i = offset; i < length; i++) {
50: int i1 = (i + 1);
51:
52: switch (token) {
53: case Token.NULL:
54: switch (array[i]) {
55: case '#':
56: case ';':
57: if (i == offset) {
58: addToken(line.count, Token.COMMENT1);
59: lastOffset = length;
60: break loop;
61: }
62: break;
63: case '[':
64: if (i == offset) {
65: addToken(i - lastOffset, token);
66: token = Token.KEYWORD2;
67: lastOffset = i;
68: }
69: break;
70: case '=':
71: addToken(i - lastOffset, Token.KEYWORD1);
72: token = VALUE;
73: lastOffset = i;
74: break;
75: }
76: break;
77: case Token.KEYWORD2:
78: if (array[i] == ']') {
79: addToken(i1 - lastOffset, token);
80: token = Token.NULL;
81: lastOffset = i1;
82: }
83: break;
84: case VALUE:
85: break;
86: default:
87: throw new InternalError("Invalid state: " + token);
88: }
89: }
90: if (lastOffset != length)
91: addToken(length - lastOffset, Token.NULL);
92: return Token.NULL;
93: }
94:
95: public boolean supportsMultilineTokens() {
96: return false;
97: }
98: }
|