001: /*
002: * BatchFileTokenMarker.java - Batch file token marker
003: * Copyright (C) 1998, 1999 Slava Pestov
004: *
005: * You may use and modify this package for any purpose. Redistribution is
006: * permitted, in both source and binary form, provided that this notice
007: * remains intact in all source distributions of this package.
008: */
009:
010: package org.syntax.jedit.tokenmarker;
011:
012: import org.syntax.jedit.*;
013: import javax.swing.text.Segment;
014:
015: /**
016: * Batch file token marker.
017: *
018: * @author Slava Pestov
019: * @version $Id: BatchFileTokenMarker.java 3074 2004-11-08 04:24:58Z bquig $
020: */
021: public class BatchFileTokenMarker extends TokenMarker {
022: public byte markTokensImpl(byte token, Segment line, int lineIndex) {
023: char[] array = line.array;
024: int offset = line.offset;
025: int lastOffset = offset;
026: int length = line.count + offset;
027:
028: if (SyntaxUtilities.regionMatches(true, line, offset, "rem")) {
029: addToken(line.count, Token.COMMENT1);
030: return Token.NULL;
031: }
032:
033: loop: for (int i = offset; i < length; i++) {
034: int i1 = (i + 1);
035:
036: switch (token) {
037: case Token.NULL:
038: switch (array[i]) {
039: case '%':
040: addToken(i - lastOffset, token);
041: lastOffset = i;
042: if (length - i <= 3 || array[i + 2] == ' ') {
043: addToken(2, Token.KEYWORD2);
044: i += 2;
045: lastOffset = i;
046: } else
047: token = Token.KEYWORD2;
048: break;
049: case '"':
050: addToken(i - lastOffset, token);
051: token = Token.LITERAL1;
052: lastOffset = i;
053: break;
054: case ':':
055: if (i == offset) {
056: addToken(line.count, Token.LABEL);
057: lastOffset = length;
058: break loop;
059: }
060: break;
061: case ' ':
062: if (lastOffset == offset) {
063: addToken(i - lastOffset, Token.KEYWORD1);
064: lastOffset = i;
065: }
066: break;
067: }
068: break;
069: case Token.KEYWORD2:
070: if (array[i] == '%') {
071: addToken(i1 - lastOffset, token);
072: token = Token.NULL;
073: lastOffset = i1;
074: }
075: break;
076: case Token.LITERAL1:
077: if (array[i] == '"') {
078: addToken(i1 - lastOffset, token);
079: token = Token.NULL;
080: lastOffset = i1;
081: }
082: break;
083: default:
084: throw new InternalError("Invalid state: " + token);
085: }
086: }
087:
088: if (lastOffset != length) {
089: if (token != Token.NULL)
090: token = Token.INVALID;
091: else if (lastOffset == offset)
092: token = Token.KEYWORD1;
093: addToken(length - lastOffset, token);
094: }
095: return Token.NULL;
096: }
097:
098: public boolean supportsMultilineTokens() {
099: return false;
100: }
101: }
|