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 javax.swing.text.Segment;
013:
014: import org.syntax.jedit.SyntaxUtilities;
015:
016: /**
017: * Batch file token marker.
018: *
019: * @author Slava Pestov
020: * @version $Id: BatchFileTokenMarker.java,v 1.20 1999/12/13 03:40:29 sp Exp $
021: */
022: public class BatchFileTokenMarker extends TokenMarker {
023: public byte markTokensImpl(byte token, Segment line, int lineIndex) {
024: char[] array = line.array;
025: int offset = line.offset;
026: int lastOffset = offset;
027: int length = line.count + offset;
028:
029: if (SyntaxUtilities.regionMatches(true, line, offset, "rem")) {
030: addToken(line.count, Token.COMMENT1);
031: return Token.NULL;
032: }
033:
034: loop: for (int i = offset; i < length; i++) {
035: int i1 = (i + 1);
036:
037: switch (token) {
038: case Token.NULL:
039: switch (array[i]) {
040: case '%':
041: addToken(i - lastOffset, token);
042: lastOffset = i;
043: if (length - i <= 3 || array[i + 2] == ' ') {
044: addToken(2, Token.KEYWORD2);
045: i += 2;
046: lastOffset = i;
047: } else
048: token = Token.KEYWORD2;
049: break;
050: case '"':
051: addToken(i - lastOffset, token);
052: token = Token.LITERAL1;
053: lastOffset = i;
054: break;
055: case ':':
056: if (i == offset) {
057: addToken(line.count, Token.LABEL);
058: lastOffset = length;
059: break loop;
060: }
061: break;
062: case ' ':
063: if (lastOffset == offset) {
064: addToken(i - lastOffset, Token.KEYWORD1);
065: lastOffset = i;
066: }
067: break;
068: }
069: break;
070: case Token.KEYWORD2:
071: if (array[i] == '%') {
072: addToken(i1 - lastOffset, token);
073: token = Token.NULL;
074: lastOffset = i1;
075: }
076: break;
077: case Token.LITERAL1:
078: if (array[i] == '"') {
079: addToken(i1 - lastOffset, token);
080: token = Token.NULL;
081: lastOffset = i1;
082: }
083: break;
084: default:
085: throw new InternalError("Invalid state: " + token);
086: }
087: }
088:
089: if (lastOffset != length) {
090: if (token != Token.NULL)
091: token = Token.INVALID;
092: else if (lastOffset == offset)
093: token = Token.KEYWORD1;
094: addToken(length - lastOffset, token);
095: }
096: return Token.NULL;
097: }
098:
099: public boolean supportsMultilineTokens() {
100: return false;
101: }
102: }
|