Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / console / jedit / BatchFileTokenMarker.java @ 40561

History | View | Annotate | Download (3.21 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * 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, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils.console.jedit;
25
/*
26
 * BatchFileTokenMarker.java - Batch file token marker
27
 * Copyright (C) 1998, 1999 Slava Pestov
28
 *
29
 * You may use and modify this package for any purpose. Redistribution is
30
 * permitted, in both source and binary form, provided that this notice
31
 * remains intact in all source distributions of this package.
32
 */
33

    
34
import javax.swing.text.Segment;
35

    
36
/**
37
 * Batch file token marker.
38
 *
39
 * @author Slava Pestov
40
 * @version $Id$
41
 */
42
public class BatchFileTokenMarker extends TokenMarker
43
{
44
        public byte markTokensImpl(byte token, Segment 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("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
}