KickJava   Java API By Example, From Geeks To Geeks.

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


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  * BatchFileTokenMarker.java
28  *
29  */

30
31 package org.syntax.jedit.tokenmarker;
32
33 import org.syntax.jedit.*;
34 import javax.swing.text.Segment JavaDoc;
35
36 /**
37  * Batch file token marker.
38  *
39  * @author Slava Pestov
40  * @version $Id: BatchFileTokenMarker.java 932 2006-10-20 09:32:45Z gtoffoli $
41  */

42 public class BatchFileTokenMarker extends TokenMarker
43 {
44     public byte markTokensImpl(byte token, Segment JavaDoc line, int lineIndex)
45     {
46         char[] array = line.array;
47         int offset = line.offset;
48         int lastOffset = offset;
49         int length = line.count + offset;
50
51         if(SyntaxUtilities.regionMatches(true,line,offset,"rem"))
52         {
53             addToken(line.count,Token.COMMENT1);
54             return Token.NULL;
55         }
56
57 loop: for(int i = offset; i < length; i++)
58         {
59             int i1 = (i+1);
60
61             switch(token)
62             {
63             case Token.NULL:
64                 switch(array[i])
65                 {
66                 case '%':
67                     addToken(i - lastOffset,token);
68                     lastOffset = i;
69                     if(length - i <= 3 || array[i+2] == ' ')
70                     {
71                         addToken(2,Token.KEYWORD2);
72                         i += 2;
73                         lastOffset = i;
74                     }
75                     else
76                         token = Token.KEYWORD2;
77                     break;
78                 case '"':
79                     addToken(i - lastOffset,token);
80                     token = Token.LITERAL1;
81                     lastOffset = i;
82                     break;
83                 case ':':
84                     if(i == offset)
85                     {
86                         addToken(line.count,Token.LABEL);
87                         lastOffset = length;
88                         break loop;
89                     }
90                     break;
91                 case ' ':
92                     if(lastOffset == offset)
93                     {
94                         addToken(i - lastOffset,Token.KEYWORD1);
95                         lastOffset = i;
96                     }
97                     break;
98                 }
99                 break;
100             case Token.KEYWORD2:
101                 if(array[i] == '%')
102                 {
103                     addToken(i1 - lastOffset,token);
104                     token = Token.NULL;
105                     lastOffset = i1;
106                 }
107                 break;
108             case Token.LITERAL1:
109                 if(array[i] == '"')
110                 {
111                     addToken(i1 - lastOffset,token);
112                     token = Token.NULL;
113                     lastOffset = i1;
114                 }
115                 break;
116             default:
117                 throw new InternalError JavaDoc("Invalid state: " + token);
118             }
119         }
120
121         if(lastOffset != length)
122         {
123             if(token != Token.NULL)
124                 token = Token.INVALID;
125             else if(lastOffset == offset)
126                 token = Token.KEYWORD1;
127             addToken(length - lastOffset,token);
128         }
129         return Token.NULL;
130     }
131
132     public boolean supportsMultilineTokens()
133     {
134         return false;
135     }
136 }
137
Popular Tags