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