/*
* BatchFileTokenMarker.java - Batch file token marker
* Copyright (C) 1998, 1999 Slava Pestov
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.gjt.sp.jedit.syntax;
import javax.swing.text.Segment;
/**
* Batch file token marker.
*
* @author Slava Pestov
* @version $Id: BatchFileTokenMarker.java,v 1.2 2002/03/26 18:21:01 tonyj Exp $
*/
public class BatchFileTokenMarker extends TokenMarker
{
public byte markTokensImpl(byte token, Segment line, int lineIndex)
{
int offset = line.offset;
int lastOffset = offset;
int length = line.count + offset;
loop: for(int i = offset; i < length; i++)
{
switch(line.array[i])
{
case '%':
if(token == Token.NULL)
{
addToken(i - lastOffset,Token.NULL);
lastOffset = i;
if(length - i <= 3 || line.array[i+2]
== ' ')
{
addToken(2,Token.KEYWORD2);
i++;
lastOffset = i + 1;
}
else
token = Token.KEYWORD2;
}
else if(token == Token.KEYWORD2)
{
token = Token.NULL;
addToken((i+1) - lastOffset,Token.KEYWORD2);
lastOffset = i + 1;
}
break;
case '"':
if(token == Token.NULL)
{
token = Token.LITERAL1;
addToken(i - lastOffset,Token.NULL);
lastOffset = i;
}
else if(token == Token.LITERAL1)
{
token = Token.NULL;
addToken((i+1) - lastOffset,Token.LITERAL1);
lastOffset = i + 1;
}
break;
case '=':
if(token == Token.NULL && lastOffset == offset)
{
addToken(i - lastOffset,Token.NULL);
lastOffset = i;
}
break;
case ':':
if(i == offset)
{
addToken(line.count,Token.LABEL);
lastOffset = length;
break loop;
}
break;
case ' ':
if(lastOffset == offset)
{
if(i > 2 && SyntaxUtilities
.regionMatches(true,line,
i - 3,"rem"))
{
addToken(length - lastOffset,
Token.COMMENT1);
lastOffset = length;
break loop;
}
else if(token == Token.NULL)
{
addToken(i - lastOffset,
Token.KEYWORD1);
lastOffset = i;
}
}
break;
}
}
if(lastOffset != length)
{
if(token != Token.NULL)
token = Token.INVALID;
else if(lastOffset == offset)
token = Token.KEYWORD1;
addToken(length - lastOffset,token);
}
return Token.NULL;
}
}
/*
* ChangeLog:
* $Log: BatchFileTokenMarker.java,v $
* Revision 1.2 2002/03/26 18:21:01 tonyj
* Remove spurious carriage returns
*
* Revision 1.1.1.1 1999/10/21 01:48:12 tonyj
* Initial import from SourceSafe
*
* Revision 1.14 1999/04/19 05:38:20 sp
* Syntax API changes
*
* Revision 1.13 1999/03/26 05:13:04 sp
* Enhanced menu item updates
*
* Revision 1.12 1999/03/13 08:50:39 sp
* Syntax colorizing updates and cleanups, general code reorganizations
*
* Revision 1.11 1999/03/13 00:09:07 sp
* Console updates, uncomment removed cos it's too buggy, cvs log tags added
*
* Revision 1.10 1999/03/12 23:51:00 sp
* Console updates, uncomment removed cos it's too buggy, cvs log tags added
*
*/
Ads help maintain this website.