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: * MakefileTokenMarker.java
028: *
029: */
030:
031: package org.syntax.jedit.tokenmarker;
032:
033: import javax.swing.text.Segment;
034:
035: /**
036: * Makefile token marker.
037: *
038: * @author Slava Pestov
039: * @version $Id: MakefileTokenMarker.java 1167 2008-01-15 18:49:05Z gtoffoli $
040: */
041: public class MakefileTokenMarker extends TokenMarker {
042: // public members
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: boolean backslash = false;
049: loop: for (int i = offset; i < length; i++) {
050: int i1 = (i + 1);
051:
052: char c = array[i];
053: if (c == '\\') {
054: backslash = !backslash;
055: continue;
056: }
057:
058: switch (token) {
059: case Token.NULL:
060: switch (c) {
061: case ':':
062: case '=':
063: case ' ':
064: case '\t':
065: backslash = false;
066: if (lastOffset == offset) {
067: addToken(i1 - lastOffset, Token.KEYWORD1);
068: lastOffset = i1;
069: }
070: break;
071: case '#':
072: if (backslash)
073: backslash = false;
074: else {
075: addToken(i - lastOffset, token);
076: addToken(length - i, Token.COMMENT1);
077: lastOffset = length;
078: break loop;
079: }
080: break;
081: case '$':
082: if (backslash)
083: backslash = false;
084: else if (lastOffset != offset) {
085: addToken(i - lastOffset, token);
086: lastOffset = i;
087: if (length - i > 1) {
088: char c1 = array[i1];
089: if (c1 == '(' || c1 == '{')
090: token = Token.KEYWORD2;
091: else {
092: addToken(2, Token.KEYWORD2);
093: lastOffset += 2;
094: i++;
095: }
096: }
097: }
098: break;
099: case '"':
100: if (backslash)
101: backslash = false;
102: else {
103: addToken(i - lastOffset, token);
104: token = Token.LITERAL1;
105: lastOffset = i;
106: }
107: break;
108: case '\'':
109: if (backslash)
110: backslash = false;
111: else {
112: addToken(i - lastOffset, token);
113: token = Token.LITERAL2;
114: lastOffset = i;
115: }
116: break;
117: default:
118: backslash = false;
119: break;
120: }
121: case Token.KEYWORD2:
122: backslash = false;
123: if (c == ')' || c == '}') {
124: addToken(i1 - lastOffset, token);
125: token = Token.NULL;
126: lastOffset = i1;
127: }
128: break;
129: case Token.LITERAL1:
130: if (backslash)
131: backslash = false;
132: else if (c == '"') {
133: addToken(i1 - lastOffset, token);
134: token = Token.NULL;
135: lastOffset = i1;
136: } else
137: backslash = false;
138: break;
139: case Token.LITERAL2:
140: if (backslash)
141: backslash = false;
142: else if (c == '\'') {
143: addToken(i1 - lastOffset, Token.LITERAL1);
144: token = Token.NULL;
145: lastOffset = i1;
146: } else
147: backslash = false;
148: break;
149: }
150: }
151: switch (token) {
152: case Token.KEYWORD2:
153: addToken(length - lastOffset, Token.INVALID);
154: token = Token.NULL;
155: break;
156: case Token.LITERAL2:
157: addToken(length - lastOffset, Token.LITERAL1);
158: break;
159: default:
160: addToken(length - lastOffset, token);
161: break;
162: }
163: return token;
164: }
165: }
|