org.eclipse.jface.text.rules.ICharacterScanner Java Examples
The following examples show how to use
org.eclipse.jface.text.rules.ICharacterScanner.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BibBraceRule.java From texlipse with Eclipse Public License 1.0 | 6 votes |
public IToken evaluate(ICharacterScanner scanner, boolean resume) { if (resume) { boolean inString = false; do { int c = scanner.read(); if (((char) c) == ',' && !inString) break; else if (((char) c) == '@') { scanner.unread(); return Token.UNDEFINED; } else if (((char) c) == '"' && !inString) inString = true; else if (((char) c) == '"' && inString) inString = false; else if (c == ICharacterScanner.EOF) return Token.UNDEFINED; } while (true); } return doEvaluate(scanner, 1); }
Example #2
Source File: StartTagRule.java From http4e with Apache License 2.0 | 6 votes |
protected boolean sequenceDetected( ICharacterScanner scanner, char[] sequence, boolean eofAllowed){ int c = scanner.read(); if (sequence[0] == '<') { if (c == '?') { // processing instruction - abort scanner.unread(); return false; } if (c == '!') { scanner.unread(); // comment - abort return false; } } else if (sequence[0] == '>') { scanner.unread(); } return super.sequenceDetected(scanner, sequence, eofAllowed); }
Example #3
Source File: JavaCodeScanner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean readInterface(ICharacterScanner scanner) { int ch= scanner.read(); int i= 0; while (i < INTERFACE.length() && INTERFACE.charAt(i) == ch) { i++; ch= scanner.read(); } if (i < INTERFACE.length()) return false; if (fWordDetector.isWordPart((char) ch)) return false; if (ch != ICharacterScanner.EOF) scanner.unread(); return true; }
Example #4
Source File: DocTypeRule.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
@Override protected boolean endSequenceDetected(ICharacterScanner scanner) { int c; int embeddedDTD = 0; CollectingCharacterScanner collectingCharacterScanner = new CollectingCharacterScanner(scanner, String.valueOf(fStartSequence)); while ((c = collectingCharacterScanner.read()) != ICharacterScanner.EOF) { if (c == fEscapeCharacter) { // Skip the escaped character. collectingCharacterScanner.read(); } else if (c == '[') { if (breakOnDTD) { break; } ++embeddedDTD; } else if (c == ']') { --embeddedDTD; } else if (c == '>' && embeddedDTD <= 0) { break; } } if (fToken instanceof ExtendedToken) { ((ExtendedToken) fToken).setContents(collectingCharacterScanner.getContents()); } return true; }
Example #5
Source File: CDataRule.java From http4e with Apache License 2.0 | 6 votes |
public IToken evaluate( ICharacterScanner scanner){ buffer.setLength(0); charsRead = 0; int c = read(scanner); if (c == matchString.charAt(0)) { do { c = read(scanner); } while (isOK((char) c)); if (charsRead == matchString.length()) { return fToken; } else { rewind(scanner); return Token.UNDEFINED; } } scanner.unread(); return Token.UNDEFINED; }
Example #6
Source File: TextUtils.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public static boolean sequenceDetected(ICharacterScanner characterScanner, char[] sequence, boolean ignoreCase) { for (int i = 1; i < sequence.length; ++i) { int c = characterScanner.read(); if ((ignoreCase && Character.toLowerCase(c) != Character.toLowerCase(sequence[i])) || (!ignoreCase && c != sequence[i])) { // Non-matching character detected, rewind the scanner back to the start. // Do not unread the first character. characterScanner.unread(); for (int j = i - 1; j > 0; --j) { characterScanner.unread(); } return false; } } for (int j = sequence.length - 1; j > 0; --j) { characterScanner.unread(); } return true; }
Example #7
Source File: RegexpRule.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
private String readNextLine(ICharacterScanner scanner) { char[][] lineDelims = TextUtils.rsort(scanner.getLegalLineDelimiters()); StringBuilder builder = new StringBuilder(); int c; while ((c = scanner.read()) != ICharacterScanner.EOF) { // FIXME We need to properly handle multi-char line delims! if (isLineDelim((char) c, lineDelims)) { break; } builder.append((char) c); } if (c == ICharacterScanner.EOF && builder.length() == 0) return null; scanner.unread(); return builder.toString(); }
Example #8
Source File: JsniScanner.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
@Override protected boolean endSequenceDetected(ICharacterScanner scanner) { int c = 0, readCount = 1; while ((c = scanner.read()) != ICharacterScanner.EOF) { if (!isValidJavaRefCharacter((char) c)) { scanner.unread(); return true; } readCount++; } while (--readCount > 0) { scanner.unread(); } return super.endSequenceDetected(scanner); }
Example #9
Source File: BibBraceRule.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Does the actual evaluation of the stream. * * @param scanner The scanner * @param count The initial count of { * @return <code>fToken</code> on success, <code>Token.UNDEFINED</code> if * the match doesn't succeed */ private IToken doEvaluate(ICharacterScanner scanner, int count) { boolean inString = false; int c = scanner.read(); if (((char) c) == '{') { do { c = scanner.read(); if (((char) c) == '{' && !inString) count++; else if (((char) c) == '}' && !inString) count--; else if (((char) c) == '"' && !inString) inString = true; else if (((char) c) == '"' && inString) inString = false; else if (c == ICharacterScanner.EOF) return Token.UNDEFINED; } while (count > 0); return fToken; } scanner.unread(); return Token.UNDEFINED; }
Example #10
Source File: JSXScanner.java From typescript.java with MIT License | 6 votes |
@Override public IToken evaluate(ICharacterScanner scanner) { int ch = scanner.read(); if (ch == '<') { ch = scanner.read(); if (ch == '/') { return token; } scanner.unread(); return token; } else if (ch == '>') { ch = scanner.read(); if (ch == '/') { return token; } scanner.unread(); return token; } scanner.unread(); return Token.UNDEFINED; }
Example #11
Source File: DocTypeRule.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
protected boolean endSequenceDetected(ICharacterScanner scanner) { int c; while ((c = scanner.read()) != ICharacterScanner.EOF) { if (c == fEscapeCharacter) { // Skip the escaped character. scanner.read(); } else if (c == '<') { fEmbeddedStart++; } else if (c == '>') { if (fEmbeddedStart == 0) { return true; } fEmbeddedStart--; } } return true; }
Example #12
Source File: FullPatternRule_Test.java From goclipse with Eclipse Public License 1.0 | 6 votes |
protected void runRuleTest(String text, Integer[] tokenIndexes, Integer[] tokenLen) { StringCharacterScanner scanner = new StringCharacterScanner(text); FullPatternRule fpRule = new FullPatternRule(new Token(null), sequences, new SampleJavaWordDetector()); while (scanner.peekNext() != ICharacterScanner.EOF) { int beginOffset = scanner.textOffset; IToken token = fpRule.evaluate(scanner); if(token.isUndefined()) { assertTrue(scanner.textOffset == beginOffset); assertTrue(ArrayUtil.contains(tokenIndexes, beginOffset) == false); scanner.read(); // advance } else { int indexOf = ArrayUtil.indexOf(tokenIndexes, beginOffset); assertTrue(indexOf != -1); assertTrue(scanner.textOffset == beginOffset + tokenLen[indexOf]); } } }
Example #13
Source File: CSSCodeScannerRuleBased.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
@Override public boolean wordOK(String word, ICharacterScanner scanner) { // Table 1. Vendor Extension Prefixes // Prefix Organisation // -ms- Microsoft // mso- Microsoft Office // -moz- Mozilla Foundation (Gecko-based browsers) // -o- Opera Software // -atsc- Advanced Television Standards Committee // -wap- The WAP Forum // -webkit- Safari (and other WebKit-based browsers) // -khtml- return word.startsWith("-moz-") || word.startsWith("-webkit-") || word.startsWith("-ms-") || word.startsWith("-o-") || word.startsWith("-atsc-") || word.startsWith("-khtml-") || word.startsWith("-wap-"); }
Example #14
Source File: MultiSuffixedWordRule.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
public IToken evaluate(ICharacterScanner scanner) { int c = scanner.read(); if ((c != ICharacterScanner.EOF) && wordDetector.isWordStart((char)c)) { readLength = 1; do { c = scanner.read(); readLength++; } while ((c != ICharacterScanner.EOF) && wordDetector.isWordPart((char)c)); for (char ch: endCharacters) { if (c == ch) { return successToken; } } while (readLength > 1) { readLength--; scanner.unread(); } } scanner.unread(); return Token.UNDEFINED; }
Example #15
Source File: RealNumberRule.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public IToken evaluate(ICharacterScanner scanner) { int c = scanner.read(); if ((c != ICharacterScanner.EOF) && Character.isDigit((char)c)) { readLength = 1; do { c = scanner.read(); readLength++; } while ((c != ICharacterScanner.EOF) && Character.isDigit((char)c)); if (c == '.') { do { c = scanner.read(); } while ((c != ICharacterScanner.EOF) && Character.isDigit((char)c)); if (c == 'E') { c = scanner.read(); if ((c == '+') || (c == '-')) { c = scanner.read(); } while ((c != ICharacterScanner.EOF) && Character.isDigit((char)c)) { c = scanner.read(); } } scanner.unread(); return successToken; } while (readLength > 1) { readLength--; scanner.unread(); } } scanner.unread(); return Token.UNDEFINED; }
Example #16
Source File: DefaultPredicateRule.java From goclipse with Eclipse Public License 1.0 | 5 votes |
protected IToken currentOr(char altA, ICharacterScanner scanner) { int second = scanner.read(); if(second == altA) { return getSuccessToken(); } scanner.unread(); return getSuccessToken(); }
Example #17
Source File: XMLAttributeRule.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected boolean wordOK(String word, ICharacterScanner scanner) { char c = (char) scanner.read(); // rewind since we're only performing lookahead scanner.unread(); return c == '='; }
Example #18
Source File: FixedMultiLineRule.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected boolean endSequenceDetected(ICharacterScanner scanner) { try { fBreaksOnEOF = endBreaksOnEOF; return super.endSequenceDetected(scanner); } finally { fBreaksOnEOF = false; } }
Example #19
Source File: JavaCodeScanner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public IToken evaluate(ICharacterScanner scanner, CombinedWordRule.CharacterBuffer word) { IToken token= super.evaluate(scanner, word); if (fIsVersionMatch || token.isUndefined()) return token; return fDefaultToken; }
Example #20
Source File: ResumableMultiLineRule.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) { try { fResume = resume; return super.doEvaluate(scanner, resume); } finally { fResume = false; } }
Example #21
Source File: JavaRegExpRule.java From LogViewer with Eclipse Public License 2.0 | 5 votes |
public IToken evaluate(ICharacterScanner scanner, boolean resume) { String line = returnNextCompleteLine(scanner); if(line != null) { if (find) { if(regexp.matcher(line).find()) { return successToken; } } else { if(regexp.matcher(line).matches()) { return successToken; } } } return Token.UNDEFINED; }
Example #22
Source File: CollectingCharacterScanner.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public int read() { int c = baseCharacterScanner.read(); if (c != ICharacterScanner.EOF) { contents.append((char)c); } return c; }
Example #23
Source File: TLCMultiLineRule.java From tlaplus with MIT License | 5 votes |
public IToken evaluate(ICharacterScanner scanner, boolean resume) { // impl does not support resume! if(resume) { throw new UnsupportedOperationException("Not implemented"); } return doEvaluate(scanner); }
Example #24
Source File: TLCCharScanner.java From tlaplus with MIT License | 5 votes |
public static boolean isTag(final ICharacterScanner scanner, final String tag) { final int length = tag.length(); int i = 0; for (; i < length; i++) { if (tag.charAt(i) != scanner.read() ) { unwind(scanner, i + 1); return false; } } unwind(scanner, length); return true; }
Example #25
Source File: RegexpRule.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private void unread(ICharacterScanner scanner, int toUnread) { while (toUnread > 0) { scanner.unread(); toUnread--; } }
Example #26
Source File: CSSImportantRule.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
protected boolean wordOK(String word, ICharacterScanner scanner) { if (pattern == null) { pattern = Pattern.compile("!\\s*important", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ } return pattern.matcher(word).matches(); }
Example #27
Source File: JavaDocScanner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public IToken evaluate(ICharacterScanner scanner) { IToken result= super.evaluate(scanner); if (result == fToken) return evaluateToken(); return result; }
Example #28
Source File: CompositeSubPartitionScanner.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public void initCharacterScanner(ICharacterScanner baseCharacterScanner, IPartitionScannerSwitchStrategy switchStrategy) { parentSequenceCharacterScanner = new SequenceCharacterScanner(baseCharacterScanner, switchStrategy, true); sequenceCharacterScanners = new SequenceCharacterScanner[subPartitionScanners.length]; sequenceCharacterScanners[0] = parentSequenceCharacterScanner; for (int i = 0; i < switchStrategies.length; ++i) { sequenceCharacterScanners[1+i] = new SequenceCharacterScanner(parentSequenceCharacterScanner, switchStrategies[i], true); } }
Example #29
Source File: DefaultPredicateRule.java From goclipse with Eclipse Public License 1.0 | 5 votes |
protected IToken currentOr(char altA, char altB, ICharacterScanner scanner) { int second = scanner.read(); if(second == altA || second == altB) { return getSuccessToken(); } scanner.unread(); return getSuccessToken(); }
Example #30
Source File: MultiCharacterRule.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public IToken evaluate(ICharacterScanner scanner, boolean resume) { int index = 0; for (char c : sequence) { ++index; if (c != scanner.read()) { for (int j = index; j > 0; --j) { scanner.unread(); } return Token.UNDEFINED; } } return getSuccessToken(); }