001: package net.xoetrope.builder.editor.syntaxhighlight;
002:
003: /*
004: * MakefileTokenMarker.java - Makefile 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: * Makefile token marker.
016: *
017: * @author Slava Pestov
018: * @version $Id: MakefileTokenMarker.java,v 1.22 2005/01/05 17:20:49 luano Exp $
019: */
020: public class MakefileTokenMarker extends TokenMarker {
021: // public members
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: boolean backslash = false;
028: loop: for (int i = offset; i < length; i++) {
029: int i1 = (i + 1);
030:
031: char c = array[i];
032: if (c == '\\') {
033: backslash = !backslash;
034: continue;
035: }
036:
037: switch (token) {
038: case Token.NULL:
039: switch (c) {
040: case ':':
041: case '=':
042: case ' ':
043: case '\t':
044: backslash = false;
045: if (lastOffset == offset) {
046: addToken(i1 - lastOffset, Token.KEYWORD1);
047: lastOffset = i1;
048: }
049: break;
050: case '#':
051: if (backslash)
052: backslash = false;
053: else {
054: addToken(i - lastOffset, token);
055: addToken(length - i, Token.COMMENT1);
056: lastOffset = length;
057: break loop;
058: }
059: break;
060: case '$':
061: if (backslash)
062: backslash = false;
063: else if (lastOffset != offset) {
064: addToken(i - lastOffset, token);
065: lastOffset = i;
066: if (length - i > 1) {
067: char c1 = array[i1];
068: if (c1 == '(' || c1 == '{')
069: token = Token.KEYWORD2;
070: else {
071: addToken(2, Token.KEYWORD2);
072: lastOffset += 2;
073: i++;
074: }
075: }
076: }
077: break;
078: case '"':
079: if (backslash)
080: backslash = false;
081: else {
082: addToken(i - lastOffset, token);
083: token = Token.LITERAL1;
084: lastOffset = i;
085: }
086: break;
087: case '\'':
088: if (backslash)
089: backslash = false;
090: else {
091: addToken(i - lastOffset, token);
092: token = Token.LITERAL2;
093: lastOffset = i;
094: }
095: break;
096: default:
097: backslash = false;
098: break;
099: }
100: case Token.KEYWORD2:
101: backslash = false;
102: if (c == ')' || c == '}') {
103: addToken(i1 - lastOffset, token);
104: token = Token.NULL;
105: lastOffset = i1;
106: }
107: break;
108: case Token.LITERAL1:
109: if (backslash)
110: backslash = false;
111: else if (c == '"') {
112: addToken(i1 - lastOffset, token);
113: token = Token.NULL;
114: lastOffset = i1;
115: } else
116: backslash = false;
117: break;
118: case Token.LITERAL2:
119: if (backslash)
120: backslash = false;
121: else if (c == '\'') {
122: addToken(i1 - lastOffset, Token.LITERAL1);
123: token = Token.NULL;
124: lastOffset = i1;
125: } else
126: backslash = false;
127: break;
128: }
129: }
130: switch (token) {
131: case Token.KEYWORD2:
132: addToken(length - lastOffset, Token.INVALID);
133: token = Token.NULL;
134: break;
135: case Token.LITERAL2:
136: addToken(length - lastOffset, Token.LITERAL1);
137: break;
138: default:
139: addToken(length - lastOffset, token);
140: break;
141: }
142: return token;
143: }
144: }
|