⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokenmarker.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				matchedChars = pattern.count;				if(!TextUtilities.regionMatches(context.rules					.getIgnoreCase(),line,pos,pattern.array))				{					return false;				}			}			else			{				// note that all regexps start with \A so they only				// match the start of the string				int matchStart = pos - line.offset;				REMatch match = checkRule.startRegexp.getMatch(					new CharIndexedSegment(line,matchStart),					0,RE.REG_ANCHORINDEX);				if(match == null)					return false;				else if(match.getStartIndex() != 0)					throw new InternalError("Can't happen");				else					matchedChars = match.getEndIndex();			}		} //}}}		//{{{ Check for an escape sequence		if((checkRule.action & ParserRule.IS_ESCAPE) == ParserRule.IS_ESCAPE)		{			if(context.inRule != null)				handleRule(context.inRule,true);			escaped = !escaped;			pos += pattern.count - 1;		}		else if(escaped)		{			escaped = false;			pos += pattern.count - 1;		} //}}}		//{{{ Handle start of rule		else if(!end)		{			if(context.inRule != null)				handleRule(context.inRule,true);			markKeyword((checkRule.action & ParserRule.MARK_PREVIOUS)				!= ParserRule.MARK_PREVIOUS);			switch(checkRule.action & ParserRule.MAJOR_ACTIONS)			{			//{{{ SEQ			case ParserRule.SEQ:				if((checkRule.action & ParserRule.REGEXP) != 0)				{					handleTokenWithTabs(tokenHandler,						checkRule.token,						pos - line.offset,						matchedChars,						context);				}				else				{					tokenHandler.handleToken(checkRule.token,						pos - line.offset,matchedChars,context);				}				// a DELEGATE attribute on a SEQ changes the				// ruleset from the end of the SEQ onwards				ParserRuleSet delegateSet = checkRule.getDelegateRuleSet(this);				if(delegateSet != null)				{					context = new LineContext(delegateSet,						context.parent);					keywords = context.rules.getKeywords();				}				break;			//}}}			//{{{ SPAN, EOL_SPAN			case ParserRule.SPAN:			case ParserRule.EOL_SPAN:				context.inRule = checkRule;				delegateSet = checkRule.getDelegateRuleSet(this);				byte tokenType = ((checkRule.action & ParserRule.EXCLUDE_MATCH)					== ParserRule.EXCLUDE_MATCH					? context.rules.getDefault() : checkRule.token);				if((checkRule.action & ParserRule.REGEXP) != 0)				{					handleTokenWithTabs(tokenHandler,						tokenType,						pos - line.offset,						matchedChars,						context);				}				else				{					tokenHandler.handleToken(tokenType,						pos - line.offset,matchedChars,context);				}				// XXX				/* String spanEndSubst = null;				if((checkRule.action & ParserRule.REGEXP) == ParserRule.REGEXP)					spanEndSubst = checkRule.startRegexp... */				context = new LineContext(delegateSet, context);				keywords = context.rules.getKeywords();				break;			//}}}			//{{{ MARK_FOLLOWING			case ParserRule.MARK_FOLLOWING:				tokenHandler.handleToken((checkRule.action					& ParserRule.EXCLUDE_MATCH)					== ParserRule.EXCLUDE_MATCH ?					context.rules.getDefault()					: checkRule.token,pos - line.offset,					pattern.count,context);				context.inRule = checkRule;				break;			//}}}			//{{{ MARK_PREVIOUS			case ParserRule.MARK_PREVIOUS:				if ((checkRule.action & ParserRule.EXCLUDE_MATCH)					== ParserRule.EXCLUDE_MATCH)				{					if(pos != lastOffset)					{						tokenHandler.handleToken(							checkRule.token,							lastOffset - line.offset,							pos - lastOffset,							context);					}					tokenHandler.handleToken(						context.rules.getDefault(),						pos - line.offset,pattern.count,						context);				}				else				{					tokenHandler.handleToken(checkRule.token,						lastOffset - line.offset,						pos - lastOffset + pattern.count,						context);				}				break;			//}}}			default:				throw new InternalError("Unhandled major action");			}			// move pos to last character of match sequence			pos += (matchedChars - 1);			lastOffset = pos + 1;			// break out of inner for loop to check next char		} //}}}		//{{{ Handle end of MARK_FOLLOWING		else if((context.inRule.action & ParserRule.MARK_FOLLOWING) != 0)		{			if(pos != lastOffset)			{				tokenHandler.handleToken(					context.inRule.token,					lastOffset - line.offset,					pos - lastOffset,context);			}			lastOffset = pos;			context.inRule = null;		} //}}}		return true;	} //}}}	//{{{ handleNoWordBreak() method	private void handleNoWordBreak()	{		if(context.parent != null)		{			ParserRule rule = context.parent.inRule;			if(rule != null && (context.parent.inRule.action				& ParserRule.NO_WORD_BREAK) != 0)			{				if(pos != lastOffset)				{					tokenHandler.handleToken(rule.token,						lastOffset - line.offset,						pos - lastOffset,context);				}				lastOffset = pos;				context = context.parent;				keywords = context.rules.getKeywords();				context.inRule = null;			}		}	} //}}}	//{{{ handleTokenWithTabs() method	private void handleTokenWithTabs(TokenHandler tokenHandler, byte tokenType,		int start, int len, LineContext context)	{		int last = start;		int end = start + len;		for(int i = start; i < end; i++)		{			if(line.array[i] == '\t')			{				if(last != i)					tokenHandler.handleToken(tokenType,last,i - last,context);				tokenHandler.handleToken(tokenType,i,1,context);				last = i + 1;			}		}		if(last != end)			tokenHandler.handleToken(tokenType,last,end - last,context);	} //}}}	//{{{ markKeyword() method	private void markKeyword(boolean addRemaining)	{		int len = pos - lastOffset;		if(len == 0)			return;		//{{{ Do digits		if(context.rules.getHighlightDigits())		{			boolean digit = false;			boolean mixed = false;			for(int i = lastOffset; i < pos; i++)			{				char ch = line.array[i];				if(Character.isDigit(ch))					digit = true;				else					mixed = true;			}			if(mixed)			{				RE digitRE = context.rules.getDigitRegexp();				// only match against regexp if its not all				// digits; if all digits, no point matching				if(digit)				{ 					if(digitRE == null)					{						// mixed digit/alpha keyword,						// and no regexp... don't						// highlight as DIGIT						digit = false;					}					else					{						CharIndexedSegment seg = new CharIndexedSegment(							line,false);						int oldCount = line.count;						int oldOffset = line.offset;						line.offset = lastOffset;						line.count = len;						if(!digitRE.isMatch(seg))							digit = false;						line.offset = oldOffset;						line.count = oldCount;					}				}			}			if(digit)			{				tokenHandler.handleToken(Token.DIGIT,					lastOffset - line.offset,					len,context);				lastOffset = pos;				return;			}		} //}}}		//{{{ Do keywords		if(keywords != null)		{			byte id = keywords.lookup(line, lastOffset, len);			if(id != Token.NULL)			{				tokenHandler.handleToken(id,					lastOffset - line.offset,					len,context);				lastOffset = pos;				return;			}		} //}}}		//{{{ Handle any remaining crud		if(addRemaining)		{			tokenHandler.handleToken(context.rules.getDefault(),				lastOffset - line.offset,len,context);			lastOffset = pos;		} //}}}	} //}}}	//}}}	//{{{ LineContext class	/**	 * Stores persistent per-line syntax parser state.	 */	public static class LineContext	{		private static Hashtable intern = new Hashtable();		public LineContext parent;		public ParserRule inRule;		public ParserRuleSet rules;		// used for SPAN_REGEXP rules; otherwise null		public String spanEndSubst;		//{{{ LineContext constructor		public LineContext(ParserRule r, ParserRuleSet rs,			String spanEndSubst)		{			inRule = r;			rules = rs;			this.spanEndSubst = spanEndSubst;		} //}}}		//{{{ LineContext constructor		public LineContext(ParserRuleSet rs, LineContext lc)		{			rules = rs;			parent = (lc == null ? null : (LineContext)lc.clone());		} //}}}		//{{{ LineContext constructor		public LineContext()		{		} //}}}		//{{{ intern() method		public LineContext intern()		{			Object obj = intern.get(this);			if(obj == null)			{				intern.put(this,this);				return this;			}			else				return (LineContext)obj;		} //}}}		//{{{ hashCode() method		public int hashCode()		{			if(inRule != null)				return inRule.hashCode();			else if(rules != null)				return rules.hashCode();			else				return 0;		} //}}}		//{{{ equals() method		public boolean equals(Object obj)		{			if(obj instanceof LineContext)			{				LineContext lc = (LineContext)obj;				if(lc.parent == null)				{					if(parent != null)						return false;				}				else //if(lc.parent != null)				{					if(parent == null)						return false;					else if(!lc.parent.equals(parent))						return false;				}				if(lc.spanEndSubst == null)				{					if(spanEndSubst != null)						return false;				}				else				{					if(spanEndSubst == null)						return false;					else if(!lc.spanEndSubst.equals(spanEndSubst))						return false;				}				return lc.inRule == inRule && lc.rules == rules;			}			else				return false;		} //}}}		//{{{ clone() method		public Object clone()		{			LineContext lc = new LineContext();			lc.inRule = inRule;			lc.rules = rules;			lc.parent = (parent == null) ? null : (LineContext) parent.clone();			lc.spanEndSubst = spanEndSubst;			return lc;		} //}}}	} //}}}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -