KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > syntax > jedit > tokenmarker > PropsTokenMarker


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * 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 JavaDoc;
34
35 /**
36  * Java properties/DOS INI token marker.
37  *
38  * @author Slava Pestov
39  * @version $Id: PropsTokenMarker.java 932 2006-10-20 09:32:45Z gtoffoli $
40  */

41 public class PropsTokenMarker extends TokenMarker
42 {
43     public static final byte VALUE = Token.INTERNAL_FIRST;
44
45     public byte markTokensImpl(byte token, Segment JavaDoc line, int lineIndex)
46     {
47         char[] array = line.array;
48         int offset = line.offset;
49         int lastOffset = offset;
50         int length = line.count + offset;
51 loop: for(int i = offset; i < length; i++)
52         {
53             int i1 = (i+1);
54
55             switch(token)
56             {
57             case Token.NULL:
58                 switch(array[i])
59                 {
60                 case '#': case ';':
61                     if(i == offset)
62                     {
63                         addToken(line.count,Token.COMMENT1);
64                         lastOffset = length;
65                         break loop;
66                     }
67                     break;
68                 case '[':
69                     if(i == offset)
70                     {
71                         addToken(i - lastOffset,token);
72                         token = Token.KEYWORD2;
73                         lastOffset = i;
74                     }
75                     break;
76                 case '=':
77                     addToken(i - lastOffset,Token.KEYWORD1);
78                     token = VALUE;
79                     lastOffset = i;
80                     break;
81                 }
82                 break;
83             case Token.KEYWORD2:
84                 if(array[i] == ']')
85                 {
86                     addToken(i1 - lastOffset,token);
87                     token = Token.NULL;
88                     lastOffset = i1;
89                 }
90                 break;
91             case VALUE:
92                 break;
93             default:
94                 throw new InternalError JavaDoc("Invalid state: "
95                     + token);
96             }
97         }
98         if(lastOffset != length)
99             addToken(length - lastOffset,Token.NULL);
100         return Token.NULL;
101     }
102
103     public boolean supportsMultilineTokens()
104     {
105         return false;
106     }
107 }
108
Popular Tags