View Javadoc

    1   /*
    2    * BatchFileTokenMarker.java - Batch file token marker
    3    * Copyright (C) 1998, 1999 Slava Pestov
    4    *
    5    * You may use and modify this package for any purpose. Redistribution is
    6    * permitted, in both source and binary form, provided that this notice
    7    * remains intact in all source distributions of this package.
    8    */
    9
    10  package org.syntax.jedit.tokenmarker;
    11
    12  import javax.swing.text.Segment;
    13
    14  import org.syntax.jedit.SyntaxUtilities;
    15
    16  /***
    17   * Batch file token marker.
    18   *
    19   * @author Slava Pestov
    20   * @version $Id: BatchFileTokenMarker.java,v 1.20 1999/12/13 03:40:29 sp Exp $
    21   */
    22  public class BatchFileTokenMarker extends TokenMarker
    23  {
    24  	public byte markTokensImpl(byte token, Segment line, int lineIndex)
    25  	{
    26  		char[] array = line.array;
    27  		int offset = line.offset;
    28  		int lastOffset = offset;
    29  		int length = line.count + offset;
    30
    31  		if(SyntaxUtilities.regionMatches(true,line,offset,"rem"))
    32  		{
    33  			addToken(line.count,Token.COMMENT1);
    34  			return Token.NULL;
    35  		}
    36
    37  loop:		for(int i = offset; i < length; i++)
    38  		{
    39  			int i1 = (i+1);
    40
    41  			switch(token)
    42  			{
    43  			case Token.NULL:
    44  				switch(array[i])
    45  				{
    46  				case '%':
    47  					addToken(i - lastOffset,token);
    48  					lastOffset = i;
    49  					if(length - i <= 3 || array[i+2] == ' ')
    50  					{
    51  						addToken(2,Token.KEYWORD2);
    52  						i += 2;
    53  						lastOffset = i;
    54  					}
    55  					else
    56  						token = Token.KEYWORD2;
    57  					break;
    58  				case '"':
    59  					addToken(i - lastOffset,token);
    60  					token = Token.LITERAL1;
    61  					lastOffset = i;
    62  					break;
    63  				case ':':
    64  					if(i == offset)
    65  					{
    66  						addToken(line.count,Token.LABEL);
    67  						lastOffset = length;
    68  						break loop;
    69  					}
    70  					break;
    71  				case ' ':
    72  					if(lastOffset == offset)
    73  					{
    74  						addToken(i - lastOffset,Token.KEYWORD1);
    75  						lastOffset = i;
    76  					}
    77  					break;
    78  				}
    79  				break;
    80  			case Token.KEYWORD2:
    81  				if(array[i] == '%')
    82  				{
    83  					addToken(i1 - lastOffset,token);
    84  					token = Token.NULL;
    85  					lastOffset = i1;
    86  				}
    87  				break;
    88  			case Token.LITERAL1:
    89  				if(array[i] == '"')
    90  				{
    91  					addToken(i1 - lastOffset,token);
    92  					token = Token.NULL;
    93  					lastOffset = i1;
    94  				}
    95  				break;
    96  			default:
    97  				throw new InternalError("Invalid state: " + token);
    98  			}
    99  		}
    100
    101 		if(lastOffset != length)
    102 		{
    103 			if(token != Token.NULL)
    104 				token = Token.INVALID;
    105 			else if(lastOffset == offset)
    106 				token = Token.KEYWORD1;
    107 			addToken(length - lastOffset,token);
    108 		}
    109 		return Token.NULL;
    110 	}
    111
    112 	public boolean supportsMultilineTokens()
    113 	{
    114 		return false;
    115 	}
    116 }