📄 windowsbatchtokenmaker.java
字号:
/*
* 03/07/2004
*
* WindowsBatchTokenMaker.java - Scanner for Windows batch files.
* Copyright (C) 2004 Robert Futrell
* email@address.com
* www.website.com
*
* 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.fife.ui.rsyntaxtextarea.modes;
import javax.swing.text.Segment;
import org.fife.ui.rsyntaxtextarea.*;
/**
* A token maker that turns text into a linked list of
* <code>Token</code>s for syntax highlighting Microsoft
* Windows batch files.
*
* @author Robert Futrell
* @version 0.1
*/
public class WindowsBatchTokenMaker extends AbstractTokenMaker {
protected final String operators = "@:*<>=?";
private int currentTokenStart;
private int currentTokenType;
private boolean bracketVariable; // Whether a variable is of the format %{...}
/*****************************************************************************/
/**
* Constructor.
*/
public WindowsBatchTokenMaker() {
super(); // Initializes tokensToHighlight.
}
/*****************************************************************************/
/**
* Checks the token to give it the exact ID it deserves before
* being passed up to the super method.
*
* @param segment <code>Segment</code> to get text from.
* @param start Start offset in <code>segment</code> of token.
* @param end End offset in <code>segment</code> of token.
* @param tokenType The token's type.
* @param startOffset The offset in the document at which the token occurs.
*/
public void addToken(Segment segment, int start, int end, int tokenType, int startOffset) {
switch (tokenType) {
// Since reserved words, functions, and data types are all passed
// into here as "identifiers," we have to see what the token
// really is...
case Token.IDENTIFIER:
int value = wordsToHighlight.get(segment, start,end);
if (value!=-1)
tokenType = value;
break;
case Token.WHITESPACE:
case Token.SEPARATOR:
case Token.OPERATOR:
case Token.ERROR_STRING_DOUBLE:
case Token.LITERAL_STRING_DOUBLE_QUOTE:
case Token.COMMENT_EOL:
case Token.VARIABLE:
break;
default:
System.err.println("Unknown tokenType in WindowsBatchTokenMaker.addToken: '" + tokenType + "'");
System.exit(0);
}
super.addToken(segment, start, end, tokenType, startOffset);
}
/*****************************************************************************/
/**
* Returns the words to highlight for Windows batch files.
*
* @return A <code>TokenMap</code> containing the words to highlight for
* Windows batch files.
* @see org.fife.ui.rsyntaxtextarea.AbstractTokenMaker#getWordsToHighlight
*/
public TokenMap getWordsToHighlight() {
TokenMap tokenMap = new TokenMap(true); // Ignore case.
int reservedWord = Token.RESERVED_WORD;
tokenMap.put("call", reservedWord);
tokenMap.put("choice", reservedWord);
tokenMap.put("cls", reservedWord);
tokenMap.put("echo", reservedWord);
tokenMap.put("exit", reservedWord);
tokenMap.put("goto", reservedWord);
tokenMap.put("if", reservedWord);
tokenMap.put("pause", reservedWord);
tokenMap.put("shift", reservedWord);
tokenMap.put("start", reservedWord);
tokenMap.put("ansi.sys", reservedWord);
tokenMap.put("append", reservedWord);
tokenMap.put("arp", reservedWord);
tokenMap.put("assign", reservedWord);
tokenMap.put("assoc", reservedWord);
tokenMap.put("at", reservedWord);
tokenMap.put("attrib", reservedWord);
tokenMap.put("break", reservedWord);
tokenMap.put("cacls", reservedWord);
tokenMap.put("call", reservedWord);
tokenMap.put("cd", reservedWord);
tokenMap.put("chcp", reservedWord);
tokenMap.put("chdir", reservedWord);
tokenMap.put("chkdsk", reservedWord);
tokenMap.put("chknfts", reservedWord);
tokenMap.put("choice", reservedWord);
tokenMap.put("cls", reservedWord);
tokenMap.put("cmd", reservedWord);
tokenMap.put("color", reservedWord);
tokenMap.put("comp", reservedWord);
tokenMap.put("compact", reservedWord);
tokenMap.put("control", reservedWord);
tokenMap.put("convert", reservedWord);
tokenMap.put("copy", reservedWord);
tokenMap.put("ctty", reservedWord);
tokenMap.put("date", reservedWord);
tokenMap.put("debug", reservedWord);
tokenMap.put("defrag", reservedWord);
tokenMap.put("del", reservedWord);
tokenMap.put("deltree", reservedWord);
tokenMap.put("dir", reservedWord);
tokenMap.put("diskcomp", reservedWord);
tokenMap.put("diskcopy", reservedWord);
tokenMap.put("doskey", reservedWord);
tokenMap.put("dosshell", reservedWord);
tokenMap.put("drivparm", reservedWord);
tokenMap.put("echo", reservedWord);
tokenMap.put("edit", reservedWord);
tokenMap.put("edlin", reservedWord);
tokenMap.put("emm386", reservedWord);
tokenMap.put("erase", reservedWord);
tokenMap.put("exist", reservedWord);
tokenMap.put("exit", reservedWord);
tokenMap.put("expand", reservedWord);
tokenMap.put("extract", reservedWord);
tokenMap.put("fasthelp", reservedWord);
tokenMap.put("fc", reservedWord);
tokenMap.put("fdisk", reservedWord);
tokenMap.put("find", reservedWord);
tokenMap.put("for", reservedWord);
tokenMap.put("format", reservedWord);
tokenMap.put("ftp", reservedWord);
tokenMap.put("graftabl", reservedWord);
tokenMap.put("help", reservedWord);
tokenMap.put("ifshlp.sys", reservedWord);
tokenMap.put("ipconfig", reservedWord);
tokenMap.put("keyb", reservedWord);
tokenMap.put("label", reservedWord);
tokenMap.put("lh", reservedWord);
tokenMap.put("loadfix", reservedWord);
tokenMap.put("loadhigh", reservedWord);
tokenMap.put("lock", reservedWord);
tokenMap.put("md", reservedWord);
tokenMap.put("mem", reservedWord);
tokenMap.put("mkdir", reservedWord);
tokenMap.put("mode", reservedWord);
tokenMap.put("more", reservedWord);
tokenMap.put("move", reservedWord);
tokenMap.put("msav", reservedWord);
tokenMap.put("msd", reservedWord);
tokenMap.put("mscdex", reservedWord);
tokenMap.put("nbtstat", reservedWord);
tokenMap.put("net", reservedWord);
tokenMap.put("netstat", reservedWord);
tokenMap.put("nlsfunc", reservedWord);
tokenMap.put("not", reservedWord);
tokenMap.put("nslookup", reservedWord);
tokenMap.put("path", reservedWord);
tokenMap.put("pathping", reservedWord);
tokenMap.put("pause", reservedWord);
tokenMap.put("ping", reservedWord);
tokenMap.put("power", reservedWord);
tokenMap.put("print", reservedWord);
tokenMap.put("prompt", reservedWord);
tokenMap.put("qbasic", reservedWord);
tokenMap.put("rd", reservedWord);
tokenMap.put("ren", reservedWord);
tokenMap.put("rename", reservedWord);
tokenMap.put("rmdir", reservedWord);
tokenMap.put("route", reservedWord);
tokenMap.put("scandisk", reservedWord);
tokenMap.put("scandreg", reservedWord);
tokenMap.put("set", reservedWord);
tokenMap.put("setver", reservedWord);
tokenMap.put("share", reservedWord);
tokenMap.put("shutdown", reservedWord);
tokenMap.put("smartdrv", reservedWord);
tokenMap.put("sort", reservedWord);
tokenMap.put("subset", reservedWord);
tokenMap.put("switches", reservedWord);
tokenMap.put("sys", reservedWord);
tokenMap.put("time", reservedWord);
tokenMap.put("tracert", reservedWord);
tokenMap.put("tree", reservedWord);
tokenMap.put("type", reservedWord);
tokenMap.put("undelete", reservedWord);
tokenMap.put("unformat", reservedWord);
tokenMap.put("unlock", reservedWord);
tokenMap.put("ver", reservedWord);
tokenMap.put("verify", reservedWord);
tokenMap.put("vol", reservedWord);
tokenMap.put("xcopy", reservedWord);
return tokenMap;
}
/*****************************************************************************/
/**
* Returns a list of tokens representing the given text.
*
* @param text The text to break into tokens.
* @param startTokenType The token with which to start tokenizing.
* @param startOffset The offset at which the line of tokens begins.
* @return A linked list of tokens representing <code>text</code>.
*/
public Token getTokenList(Segment text, int startTokenType, final int startOffset) {
resetTokenList();
char[] array = text.array;
int offset = text.offset;
int count = text.count;
int end = offset + count;
// See, when we find a token, its starting position is always of the form:
// 'startOffset + (currentTokenStart-offset)'; but since startOffset and
// offset are constant, tokens' starting positions become:
// 'newStartOffset+currentTokenStart' for one less subraction operation.
int newStartOffset = startOffset - offset;
currentTokenStart = offset;
currentTokenType = startTokenType;
boolean numContainsExponent = false;
boolean numContainsEndCharacter = false;
beginning:
for (int i=offset; i<end; i++) {
char c = array[i];
switch (currentTokenType) {
case Token.NULL:
currentTokenStart = i; // Starting a new token here.
switch (c) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -