001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * BatchFileTokenMarker.java
028: *
029: */
030:
031: package org.syntax.jedit.tokenmarker;
032:
033: import org.syntax.jedit.*;
034: import javax.swing.text.Segment;
035:
036: /**
037: * Batch file token marker.
038: *
039: * @author Slava Pestov
040: * @version $Id: BatchFileTokenMarker.java 1167 2008-01-15 18:49:05Z gtoffoli $
041: */
042: public class BatchFileTokenMarker extends TokenMarker {
043: public byte markTokensImpl(byte token, Segment line, int lineIndex) {
044: char[] array = line.array;
045: int offset = line.offset;
046: int lastOffset = offset;
047: int length = line.count + offset;
048:
049: if (SyntaxUtilities.regionMatches(true, line, offset, "rem")) {
050: addToken(line.count, Token.COMMENT1);
051: return Token.NULL;
052: }
053:
054: loop: for (int i = offset; i < length; i++) {
055: int i1 = (i + 1);
056:
057: switch (token) {
058: case Token.NULL:
059: switch (array[i]) {
060: case '%':
061: addToken(i - lastOffset, token);
062: lastOffset = i;
063: if (length - i <= 3 || array[i + 2] == ' ') {
064: addToken(2, Token.KEYWORD2);
065: i += 2;
066: lastOffset = i;
067: } else
068: token = Token.KEYWORD2;
069: break;
070: case '"':
071: addToken(i - lastOffset, token);
072: token = Token.LITERAL1;
073: lastOffset = i;
074: break;
075: case ':':
076: if (i == offset) {
077: addToken(line.count, Token.LABEL);
078: lastOffset = length;
079: break loop;
080: }
081: break;
082: case ' ':
083: if (lastOffset == offset) {
084: addToken(i - lastOffset, Token.KEYWORD1);
085: lastOffset = i;
086: }
087: break;
088: }
089: break;
090: case Token.KEYWORD2:
091: if (array[i] == '%') {
092: addToken(i1 - lastOffset, token);
093: token = Token.NULL;
094: lastOffset = i1;
095: }
096: break;
097: case Token.LITERAL1:
098: if (array[i] == '"') {
099: addToken(i1 - lastOffset, token);
100: token = Token.NULL;
101: lastOffset = i1;
102: }
103: break;
104: default:
105: throw new InternalError("Invalid state: " + token);
106: }
107: }
108:
109: if (lastOffset != length) {
110: if (token != Token.NULL)
111: token = Token.INVALID;
112: else if (lastOffset == offset)
113: token = Token.KEYWORD1;
114: addToken(length - lastOffset, token);
115: }
116: return Token.NULL;
117: }
118:
119: public boolean supportsMultilineTokens() {
120: return false;
121: }
122: }
|