Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
27,500
CharSequence (@NotNull Constants.StringKey key) { return myStringAttributes.get(key); }
getStringAttribute
27,501
void (@NotNull Constants.CaptureKey key, TextMateCapture @Nullable [] captures) { myCaptures.put(key, captures); }
setCaptures
27,502
boolean (Constants.@NotNull StringKey key) { return true; }
hasBackReference
27,503
TextMateCapture[] (Constants.@NotNull CaptureKey key) { return myCaptures.get(key); }
getCaptureRules
27,504
Int2ObjectMap<CharSequence> (@NotNull Constants.CaptureKey key) { TextMateCapture[] realCaptures = myCaptures.get(key); if (realCaptures == null) { return null; } Int2ObjectMap<CharSequence> captures = new Int2ObjectOpenHashMap<>(realCaptures.length); for (int group = 0; group < myCaptures.get(key).length; group++) { TextMateCapture capture = realCaptures[group]; if (capture != null) { captures.put(group, capture instanceof TextMateCapture.Name ? ((TextMateCapture.Name)capture).getName() : ""); } } return captures; }
getCaptures
27,505
boolean (Constants.@NotNull CaptureKey key, int group) { return true; }
hasBackReference
27,506
void (SyntaxNodeDescriptor descriptor) { myChildren.add(descriptor); }
addChild
27,507
List<SyntaxNodeDescriptor> () { return myChildren; }
getChildren
27,508
void (int ruleId, SyntaxNodeDescriptor descriptor) { myRepository.put(ruleId, descriptor); }
appendRepository
27,509
void () { myStringAttributes = PreferencesReadUtil.compactMap(myStringAttributes); myCaptures = PreferencesReadUtil.compactMap(myCaptures); myChildren = compactList(myChildren); myInjections = compactList(myInjections); myRepository = compactMap(myRepository); }
compact
27,510
Int2ObjectMap<SyntaxNodeDescriptor> (Int2ObjectMap<SyntaxNodeDescriptor> map) { if (map.isEmpty()) { return null; } if (map instanceof Int2ObjectOpenHashMap) { ((Int2ObjectOpenHashMap<SyntaxNodeDescriptor>)map).trim(); } return map; }
compactMap
27,511
List<InjectionNodeDescriptor> () { return myInjections; }
getInjections
27,512
void (@NotNull InjectionNodeDescriptor injection) { myInjections.add(injection); }
addInjection
27,513
SyntaxNodeDescriptor (int ruleId) { SyntaxNodeDescriptor syntaxNodeDescriptor = myRepository != null ? myRepository.get(ruleId) : null; if (syntaxNodeDescriptor == null && myParentNode != null) { return myParentNode.findInRepository(ruleId); } if (syntaxNodeDescriptor == null) { LOG.warn("Can't find repository " + ruleId); return EMPTY_NODE; } return syntaxNodeDescriptor; }
findInRepository
27,514
CharSequence () { return myScopeName; }
getScopeName
27,515
SyntaxNodeDescriptor () { return myParentNode; }
getParentNode
27,516
String () { CharSequence name = myStringAttributes.get(Constants.StringKey.NAME); return name != null ? "Syntax rule: " + name : super.toString(); }
toString
27,517
Node () { Node result = parseSelectorList(); if (!eof()) { LOG.error("Cannot parse highlighting selector: " + myHighlightingSelector); } return result; }
parse
27,518
Node () { Node node = parseConjunction(); if (node == null || getToken() != TextMateSelectorToken.COMMA) { return node; } List<Node> children = new ArrayList<>(); children.add(node); while (getToken() == TextMateSelectorToken.COMMA) { advance(); Node child = parseConjunction(); if (child == null) break; children.add(child); } return new SelectorList(children); }
parseSelectorList
27,519
Node () { Node node = parseScopeSelector(); if (node == null || getToken() != TextMateSelectorToken.PIPE) { return node; } List<Node> children = new ArrayList<>(); children.add(node); while (getToken() == TextMateSelectorToken.PIPE) { advance(); Node child = parseScopeSelector(); if (child == null) break; children.add(child); } return new Conjunction(children); }
parseConjunction
27,520
Node () { TextMateWeigh.Priority priority = TextMateWeigh.Priority.NORMAL; TextMateSelectorToken token = getToken(); if (token instanceof TextMateSelectorLexer.PriorityToken) { advance(); priority = ((TextMateSelectorLexer.PriorityToken)token).getPriority(); } boolean startMatch = false; if (getToken() == TextMateSelectorToken.HAT) { advance(); startMatch = true; } List<Node> children = new ArrayList<>(); List<Node> exclusions = new ArrayList<>(); Node next = parseSelector(); while (next != null) { children.add(next); next = parseSelector(); } while (getToken() == TextMateSelectorToken.MINUS) { advance(); Node exclusion = parseScopeSelector(); if (exclusion != null) { exclusions.add(exclusion); } } if (children.isEmpty() && exclusions.isEmpty()) { return null; } return new ScopeSelector(children, exclusions, startMatch, priority); }
parseScopeSelector
27,521
Node () { TextMateSelectorToken token = getToken(); if (token == TextMateSelectorToken.LPAREN) { advance(); Node result = parseSelectorList(); if (getToken() == TextMateSelectorToken.RPAREN) { advance(); } return result; } if (token instanceof TextMateSelectorLexer.SelectorToken) { advance(); return new Selector(((TextMateSelectorLexer.SelectorToken)token).getText()); } return null; }
parseSelector
27,522
TextMateSelectorToken () { if (myIndex < myTokens.size()) { return myTokens.get(myIndex); } return null; }
getToken
27,523
void () { myIndex++; }
advance
27,524
boolean () { return myIndex >= myTokens.size(); }
eof
27,525
TextMateWeigh (@NotNull TextMateScope scope) { CharSequence scopeName = scope.getScopeName(); if (scopeName != null && (selector.isEmpty() || StringUtilRt.startsWith(scopeName, selector + ".") || StringUtilRt.equal(scopeName, selector, true))) { return new TextMateWeigh(BASE_WEIGH - scope.getDotsCount() + Strings.countChars(selector, '.'), TextMateWeigh.Priority.NORMAL); } return TextMateWeigh.ZERO; }
weigh
27,526
TextMateWeigh (@NotNull TextMateScope scope) { for (Node exclusion : exclusions) { if (exclusion.weigh(scope).weigh > 0) { return TextMateWeigh.ZERO; } } if (scope.getLevel() > 100) { return TextMateWeigh.ZERO; } Deque<Node> highlightingSelectors = new LinkedList<>(); for (Node child : children) { highlightingSelectors.push(child); } if (highlightingSelectors.isEmpty()) { highlightingSelectors.push(new Selector("")); } TextMateScope currentTargetSelector = scope; Node currentHighlightingSelector = highlightingSelectors.peek(); int nestingWeigh = NESTING_WEIGH_INITIAL; int result = 0; while (!highlightingSelectors.isEmpty() && currentTargetSelector != null) { TextMateWeigh weigh = currentHighlightingSelector instanceof Selector ? currentHighlightingSelector.weigh(currentTargetSelector) : currentHighlightingSelector.weigh(scope); if (weigh.weigh > 0) { result += weigh.weigh * nestingWeigh; highlightingSelectors.pop(); if (!highlightingSelectors.isEmpty()) { currentHighlightingSelector = highlightingSelectors.peek(); } } nestingWeigh--; currentTargetSelector = currentTargetSelector.getParent(); } if (!highlightingSelectors.isEmpty()) { return TextMateWeigh.ZERO; } return new TextMateWeigh(!startMatch || currentTargetSelector == null || currentTargetSelector.isEmpty() ? result : 0, priority); }
weigh
27,527
TextMateWeigh (@NotNull TextMateScope scope) { TextMateWeigh result = TextMateWeigh.ZERO; for (Node child : children) { TextMateWeigh weigh = child.weigh(scope); if (weigh.compareTo(result) > 0) { result = weigh; } } return result; }
weigh
27,528
TextMateWeigh (@NotNull TextMateScope scope) { for (Node child : children) { TextMateWeigh weigh = child.weigh(scope); if (weigh.weigh > 0) { return weigh; } } return TextMateWeigh.ZERO; }
weigh
27,529
List<TextMateSelectorToken> (@NotNull CharSequence selector) { ArrayList<TextMateSelectorToken> result = new ArrayList<>(); StringBuilder currentSelector = new StringBuilder(); for (int i = 0; i < selector.length(); i++) { char c = selector.charAt(i); if (c == '(') { currentSelector = addPendingToken(result, currentSelector); result.add(TextMateSelectorToken.LPAREN); } else if (c == ')') { currentSelector = addPendingToken(result, currentSelector); result.add(TextMateSelectorToken.RPAREN); } else if (c == ',') { currentSelector = addPendingToken(result, currentSelector); result.add(TextMateSelectorToken.COMMA); } else if (c == '|') { currentSelector = addPendingToken(result, currentSelector); result.add(TextMateSelectorToken.PIPE); } else if (c == '^') { currentSelector = addPendingToken(result, currentSelector); result.add(TextMateSelectorToken.HAT); } else if (c == '-' && currentSelector.isEmpty()) { currentSelector = addPendingToken(result, currentSelector); result.add(TextMateSelectorToken.MINUS); } else if (c == ' ') { currentSelector = addPendingToken(result, currentSelector); } else if ((c == 'R' || c == 'L' || c == 'B') && i + 1 < selector.length() && selector.charAt(i+1) == ':') { currentSelector = addPendingToken(result, currentSelector); //noinspection AssignmentToForLoopParameter i++; if (c == 'R') { result.add(new PriorityToken(TextMateWeigh.Priority.LOW)); } else if (c == 'L') { result.add(new PriorityToken(TextMateWeigh.Priority.HIGH)); } } else { currentSelector.append(c); } } addPendingToken(result, currentSelector); return result; }
tokenize
27,530
StringBuilder (ArrayList<TextMateSelectorToken> result, StringBuilder currentSelector) { if (!currentSelector.isEmpty()) { result.add(new SelectorToken(currentSelector.toString())); return new StringBuilder(); } return currentSelector; }
addPendingToken
27,531
String () { return String.valueOf(mySign); }
toString
27,532
String () { return myPriority.name(); }
toString
27,533
String () { return myText; }
getText
27,534
String () { return myText; }
toString
27,535
TextMateWeigh (@NotNull final CharSequence scopeSelector, final @NotNull TextMateScope scope) { return myCache.get(new CacheKey(scopeSelector, scope), this::weigh); }
weigh
27,536
TextMateWeigh (@NotNull CacheKey pair) { return myOriginalWeigher.weigh(pair.selector, pair.scope); }
weigh
27,537
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; CacheKey key = (CacheKey)o; return selector.equals(key.selector) && scope.equals(key.scope); }
equals
27,538
int () { return Objects.hash(selector, scope); }
hashCode
27,539
int (@NotNull TextMateWeigh o) { int priorityCompare = priority.compareTo(o.priority); if (priorityCompare != 0) { return priorityCompare; } return Integer.compare(weigh, o.weigh); }
compareTo
27,540
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TextMateWeigh weigh1 = (TextMateWeigh)o; return weigh == weigh1.weigh && priority == weigh1.priority; }
equals
27,541
int () { return Objects.hash(weigh, priority); }
hashCode
27,542
TextMateWeigh (@NotNull CharSequence scopeSelector, @NotNull TextMateScope scope) { TextMateSelectorParser parser = new TextMateSelectorParser(scopeSelector); TextMateSelectorParser.Node node = parser.parse(); if (node == null) { return TextMateWeigh.ZERO; } return node.weigh(scope); }
weigh
27,543
void (@Nullable Runnable runnable) { ourCheckCancelledCallback = runnable; }
setCheckCancelledCallback
27,544
Runnable () { return ourCheckCancelledCallback; }
getCheckCancelledCallback
27,545
TextMateLexerState (@NotNull SyntaxNodeDescriptor syntaxNodeDescriptor, @NotNull StringWithId string, int byteOffset, int gosOffset, boolean matchBeginOfString, @NotNull TextMateWeigh.Priority priority, @NotNull TextMateScope currentScope) { return CACHE.get(new MatchKey(syntaxNodeDescriptor, string, byteOffset, gosOffset, matchBeginOfString, priority, currentScope), SyntaxMatchUtils::matchFirstUncached); }
matchFirst
27,546
TextMateLexerState (MatchKey key) { return matchFirstUncached(Objects.requireNonNull(key).descriptor, key.string, key.byteOffset, key.gosOffset, key.matchBeginOfString, key.priority, key.currentScope); }
matchFirstUncached
27,547
TextMateLexerState (@NotNull SyntaxNodeDescriptor syntaxNodeDescriptor, @NotNull StringWithId string, int byteOffset, int gosOffset, boolean matchBeginOfString, @NotNull TextMateWeigh.Priority priority, @NotNull TextMateScope currentScope) { TextMateLexerState resultState = TextMateLexerState.notMatched(syntaxNodeDescriptor); List<SyntaxNodeDescriptor> children = syntaxNodeDescriptor.getChildren(); for (SyntaxNodeDescriptor child : children) { resultState = moreImportantState(resultState, matchFirstChild(child, string, byteOffset, gosOffset, matchBeginOfString, priority, currentScope)); if (resultState.matchData.matched() && resultState.matchData.byteOffset().start == byteOffset) { // optimization. There cannot be anything more `important` than current state matched from the very beginning break; } } return moreImportantState(resultState, matchInjections(syntaxNodeDescriptor, string, byteOffset, gosOffset, matchBeginOfString, currentScope)); }
matchFirstUncached
27,548
TextMateLexerState (@NotNull SyntaxNodeDescriptor syntaxNodeDescriptor, @NotNull StringWithId string, int byteOffset, int gosOffset, boolean matchBeginOfString, @NotNull TextMateScope currentScope) { TextMateLexerState resultState = TextMateLexerState.notMatched(syntaxNodeDescriptor); List<InjectionNodeDescriptor> injections = syntaxNodeDescriptor.getInjections(); for (InjectionNodeDescriptor injection : injections) { TextMateWeigh selectorWeigh = mySelectorWeigher.weigh(injection.getSelector(), currentScope); if (selectorWeigh.weigh <= 0) { continue; } TextMateLexerState injectionState = matchFirstUncached(injection.getSyntaxNodeDescriptor(), string, byteOffset, gosOffset, matchBeginOfString, selectorWeigh.priority, currentScope); resultState = moreImportantState(resultState, injectionState); } return resultState; }
matchInjections
27,549
TextMateLexerState (@NotNull TextMateLexerState oldState, @NotNull TextMateLexerState newState) { if (!newState.matchData.matched()) { return oldState; } else if (!oldState.matchData.matched()) { return newState; } int newScore = newState.matchData.byteOffset().start; int oldScore = oldState.matchData.byteOffset().start; if (newScore < oldScore || newScore == oldScore && newState.priorityMatch.compareTo(oldState.priorityMatch) > 0) { if (!newState.matchData.byteOffset().isEmpty() || oldState.matchData.byteOffset().isEmpty() || hasBeginKey(newState)) { return newState; } } return oldState; }
moreImportantState
27,550
boolean (@NotNull TextMateLexerState lexerState) { return lexerState.syntaxRule.getStringAttribute(Constants.StringKey.BEGIN) != null; }
hasBeginKey
27,551
TextMateLexerState (@NotNull SyntaxNodeDescriptor syntaxNodeDescriptor, @NotNull StringWithId string, int byteOffset, int gosOffset, boolean matchBeginOfString, @NotNull TextMateWeigh.Priority priority, @NotNull TextMateScope currentScope) { CharSequence match = syntaxNodeDescriptor.getStringAttribute(Constants.StringKey.MATCH); if (match != null) { RegexFacade regex = regex(match.toString()); MatchData matchData = regex.match(string, byteOffset, gosOffset, matchBeginOfString, ourCheckCancelledCallback); return new TextMateLexerState(syntaxNodeDescriptor, matchData, priority, byteOffset, string); } CharSequence begin = syntaxNodeDescriptor.getStringAttribute(Constants.StringKey.BEGIN); if (begin != null) { RegexFacade regex = regex(begin.toString()); MatchData matchData = regex.match(string, byteOffset, gosOffset, matchBeginOfString, ourCheckCancelledCallback); return new TextMateLexerState(syntaxNodeDescriptor, matchData, priority, byteOffset, string); } if (syntaxNodeDescriptor.getStringAttribute(Constants.StringKey.END) != null) { return TextMateLexerState.notMatched(syntaxNodeDescriptor); } return matchFirstUncached(syntaxNodeDescriptor, string, byteOffset, gosOffset, matchBeginOfString, priority, currentScope); }
matchFirstChild
27,552
MatchData (@NotNull Constants.StringKey keyName, @NotNull StringWithId string, int byteOffset, int anchorOffset, boolean matchBeginOfString, @NotNull TextMateLexerState lexerState) { CharSequence regex = lexerState.syntaxRule.getStringAttribute(keyName); if (regex == null) return MatchData.NOT_MATCHED; String regexString = lexerState.syntaxRule.hasBackReference(keyName) ? replaceGroupsWithMatchDataInRegex(regex, lexerState.string, lexerState.matchData) : regex.toString(); return regex(regexString).match(string, byteOffset, anchorOffset, matchBeginOfString, ourCheckCancelledCallback); }
matchStringRegex
27,553
CharSequence (Constants.@NotNull StringKey keyName, @NotNull SyntaxNodeDescriptor syntaxRule, @NotNull StringWithId string, @NotNull MatchData matchData) { CharSequence stringAttribute = syntaxRule.getStringAttribute(keyName); if (stringAttribute == null) { return null; } return syntaxRule.hasBackReference(keyName) ? replaceGroupsWithMatchDataInCaptures(stringAttribute, string, matchData) : stringAttribute; }
getStringAttribute
27,554
String (@NotNull CharSequence string, @Nullable StringWithId matchingString, @NotNull MatchData matchData) { if (matchingString == null || !matchData.matched()) { return string.toString(); } StringBuilder result = new StringBuilder(); int charIndex = 0; int length = string.length(); while (charIndex < length) { char c = string.charAt(charIndex); if (c == '\\') { boolean hasGroupIndex = false; int groupIndex = 0; int digitIndex = charIndex + 1; while (digitIndex < length) { int digit = Character.digit(string.charAt(digitIndex), 10); if (digit == -1) { break; } hasGroupIndex = true; groupIndex = groupIndex * 10 + digit; digitIndex++; } if (hasGroupIndex && matchData.count() > groupIndex) { TextMateRange range = matchData.byteOffset(groupIndex); Strings.escapeToRegexp(new String(matchingString.bytes, range.start, range.getLength(), StandardCharsets.UTF_8), result); charIndex = digitIndex; continue; } } result.append(c); charIndex++; } return result.toString(); }
replaceGroupsWithMatchDataInRegex
27,555
CharSequence (@NotNull CharSequence string, @NotNull StringWithId matchingString, @NotNull MatchData matchData) { if (!matchData.matched()) { return string; } Matcher matcher = CAPTURE_GROUP_REGEX.matcher(string); StringBuilder result = new StringBuilder(); int lastPosition = 0; while (matcher.find()) { int groupIndex = StringUtilRt.parseInt(matcher.group(1) != null ? matcher.group(1) : matcher.group(2), -1); if (groupIndex >= 0 && matchData.count() > groupIndex) { result.append(string, lastPosition, matcher.start()); TextMateRange range = matchData.byteOffset(groupIndex); String capturedText = new String(matchingString.bytes, range.start, range.getLength(), StandardCharsets.UTF_8); int numberOfDotsAtTheBeginning = Strings.countChars(capturedText, '.', 0, true); String replacement = capturedText.substring(numberOfDotsAtTheBeginning); String command = matcher.group(3); if ("downcase".equals(command)) { result.append(replacement.toLowerCase(Locale.ROOT)); } else if ("upcase".equals(command)) { result.append(replacement.toUpperCase(Locale.ROOT)); } else { result.append(replacement); } lastPosition = matcher.end(); } } if (lastPosition < string.length()) { result.append(string.subSequence(lastPosition, string.length())); } return result.toString(); }
replaceGroupsWithMatchDataInCaptures
27,556
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MatchKey key = (MatchKey)o; return byteOffset == key.byteOffset && gosOffset == key.gosOffset && matchBeginOfString == key.matchBeginOfString && descriptor.equals(key.descriptor) && Objects.equals(string, key.string) && priority == key.priority && currentScope.equals(key.currentScope); }
equals
27,557
int () { return Objects.hash(descriptor, string, byteOffset, gosOffset, matchBeginOfString, priority, currentScope); }
hashCode
27,558
TextMateLexerState (@NotNull SyntaxNodeDescriptor syntaxRule) { return new TextMateLexerState(syntaxRule, MatchData.NOT_MATCHED, TextMateWeigh.Priority.NORMAL, 0,null); }
notMatched
27,559
String () { return "TextMateLexerState{" + "syntaxRule=" + syntaxRule + ", matchData=" + matchData + '}'; }
toString
27,560
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TextMateLexerState state = (TextMateLexerState)o; return syntaxRule.equals(state.syntaxRule) && matchData.equals(state.matchData) && priorityMatch == state.priorityMatch && stringId() == state.stringId(); }
equals
27,561
int () { return hashcode; }
hashCode
27,562
Object () { return string != null ? string.id : null; }
stringId
27,563
int () { return dotsCount; }
getDotsCount
27,564
int () { return level; }
getLevel
27,565
TextMateScope (@Nullable CharSequence scopeName) { return new TextMateScope(scopeName, this); }
add
27,566
CharSequence () { return scopeName; }
getScopeName
27,567
TextMateScope () { return parentScope; }
getParent
27,568
TextMateScope () { return parentScope != null ? parentScope : this; }
getParentOrSelf
27,569
boolean () { return empty; }
isEmpty
27,570
String () { StringBuilder builder = new StringBuilder(); if (scopeName != null) { builder.append(scopeName); } TextMateScope parent = parentScope; while (parent != null) { CharSequence parentScopeName = parent.scopeName; if (parentScopeName != null) { if (!builder.isEmpty()) { builder.insert(0, " "); } builder.insert(0, parentScopeName); } parent = parent.parentScope; } return builder.toString().trim(); }
toString
27,571
boolean (Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; TextMateScope scope = (TextMateScope)o; return level == scope.level && hashCode == scope.hashCode && Objects.equals(scopeName, scope.scopeName); }
equals
27,572
int () { return hashCode; }
hashCode
27,573
void (CharSequence text, int startOffset) { myText = text; myCurrentOffset = startOffset; myStates = FList.singleton(myLanguageInitialState); myCurrentScope = new TextMateScope(myLanguageScopeName, null); }
init
27,574
int () { return myCurrentOffset; }
getCurrentOffset
27,575
void (@NotNull Queue<Token> output) { int startLineOffset = myCurrentOffset; int endLineOffset = startLineOffset; while (endLineOffset < myText.length()) { if (myText.charAt(endLineOffset) == '\n') { endLineOffset++; break; } endLineOffset++; } CharSequence lineCharSequence = myText.subSequence(startLineOffset, endLineOffset); if (myLineLimit >= 0 && lineCharSequence.length() > myLineLimit) { myStates = parseLine(lineCharSequence.subSequence(0, myLineLimit), output, myStates, startLineOffset, 0, 0); addToken(output, endLineOffset); } else { myStates = parseLine(lineCharSequence, output, myStates, startLineOffset, 0, 0); } }
advanceLine
27,576
FList<TextMateLexerState> (@NotNull CharSequence line, @NotNull Queue<Token> output, @NotNull FList<TextMateLexerState> states, int lineStartOffset, int linePosition, int lineByteOffset) { FList<TextMateLexerState> lastSuccessState = states; int lastSuccessStateOccursCount = 0; int lastMovedOffset = lineStartOffset; boolean matchBeginOfString = lineStartOffset == 0; int anchorByteOffset = -1; // makes sense only for a line, cannot be used across lines StringWithId string = new StringWithId(line); while (true) { final TextMateLexerState lexerState = states.getHead(); if (lexerState.syntaxRule.getStringAttribute(Constants.StringKey.WHILE) != null) { MatchData matchWhile = SyntaxMatchUtils.matchStringRegex(Constants.StringKey.WHILE, string, lineByteOffset, anchorByteOffset, matchBeginOfString, lexerState); if (!matchWhile.matched()) { closeScopeSelector(output, linePosition + lineStartOffset); closeScopeSelector(output, linePosition + lineStartOffset); states = states.getTail(); // this is happening at line start, none of the previous states couldn't be run on this line, so no need to update anchorByteOffset continue; } else { anchorByteOffset = matchWhile.byteOffset().end; } } break; } Set<TextMateLexerState> localStates = new HashSet<>(); while (true) { TextMateLexerState lastState = states.getHead(); SyntaxNodeDescriptor lastRule = lastState.syntaxRule; TextMateLexerState currentState = SyntaxMatchUtils.matchFirst(lastRule, string, lineByteOffset, anchorByteOffset, matchBeginOfString, TextMateWeigh.Priority.NORMAL, myCurrentScope); SyntaxNodeDescriptor currentRule = currentState.syntaxRule; MatchData currentMatch = currentState.matchData; int endPosition; MatchData endMatch = SyntaxMatchUtils.matchStringRegex(Constants.StringKey.END, string, lineByteOffset, anchorByteOffset, matchBeginOfString, lastState); if (endMatch.matched() && (!currentMatch.matched() || currentMatch.byteOffset().start >= endMatch.byteOffset().start || lastState.equals(currentState))) { TextMateLexerState poppedState = states.getHead(); if (poppedState.matchData.matched() && !poppedState.matchedEOL) { // if begin hasn't matched EOL, it was performed on the same line; we need to use its anchor anchorByteOffset = poppedState.matchData.byteOffset().end; } states = states.getTail(); TextMateRange endRange = endMatch.charRange(line, string.bytes); int startPosition = endPosition = endRange.start; closeScopeSelector(output, startPosition + lineStartOffset); // closing content scope if (lastRule.getCaptureRules(Constants.CaptureKey.END_CAPTURES) == null && lastRule.getCaptureRules(Constants.CaptureKey.CAPTURES) == null && lastRule.getCaptureRules(Constants.CaptureKey.BEGIN_CAPTURES) == null || parseCaptures(output, Constants.CaptureKey.END_CAPTURES, lastRule, endMatch, string, line, lineStartOffset, states) || parseCaptures(output, Constants.CaptureKey.CAPTURES, lastRule, endMatch, string, line, lineStartOffset, states)) { // move line position only if anything was captured or if there is nothing to capture at all endPosition = endRange.end; } closeScopeSelector(output, endPosition + lineStartOffset); // closing basic scope if (linePosition == endPosition && containsLexerState(localStates, poppedState) && poppedState.enterByteOffset == lineByteOffset) { addToken(output, line.length() + lineStartOffset); break; } localStates.remove(poppedState); } else if (currentMatch.matched()) { anchorByteOffset = currentMatch.byteOffset().end; TextMateRange currentRange = currentMatch.charRange(line, string.bytes); int startPosition = currentRange.start; endPosition = currentRange.end; if (currentRule.getStringAttribute(Constants.StringKey.BEGIN) != null) { states = states.prepend(currentState); CharSequence name = SyntaxMatchUtils.getStringAttribute(Constants.StringKey.NAME, currentRule, string, currentMatch); openScopeSelector(output, name, startPosition + lineStartOffset); parseCaptures(output, Constants.CaptureKey.BEGIN_CAPTURES, currentRule, currentMatch, string, line, lineStartOffset, states); parseCaptures(output, Constants.CaptureKey.CAPTURES, currentRule, currentMatch, string, line, lineStartOffset, states); CharSequence contentName = SyntaxMatchUtils.getStringAttribute(Constants.StringKey.CONTENT_NAME, currentRule, string, currentMatch); openScopeSelector(output, contentName, endPosition + lineStartOffset); } else if (currentRule.getStringAttribute(Constants.StringKey.MATCH) != null) { CharSequence name = SyntaxMatchUtils.getStringAttribute(Constants.StringKey.NAME, currentRule, string, currentMatch); openScopeSelector(output, name, startPosition + lineStartOffset); parseCaptures(output, Constants.CaptureKey.CAPTURES, currentRule, currentMatch, string, line, lineStartOffset, states); closeScopeSelector(output, endPosition + lineStartOffset); } if (linePosition == endPosition && containsLexerState(localStates, currentState)) { addToken(output, line.length() + lineStartOffset); break; } localStates.add(currentState); } else { addToken(output, line.length() + lineStartOffset); break; } // global looping protection if (lastMovedOffset < myCurrentOffset) { lastSuccessState = states; lastSuccessStateOccursCount = 0; lastMovedOffset = myCurrentOffset; } else if (lastSuccessState.equals(states)) { if (lastSuccessStateOccursCount > MAX_LOOPS_COUNT) { addToken(output, line.length() + lineStartOffset); break; } lastSuccessStateOccursCount++; } if (linePosition != endPosition) { linePosition = endPosition; lineByteOffset = RegexUtil.byteOffsetByCharOffset(line, linePosition); } if (myCheckCancelledCallback != null) { myCheckCancelledCallback.run(); } } return states; }
parseLine
27,577
boolean (Set<TextMateLexerState> states, TextMateLexerState state) { for (TextMateLexerState s : states) { if (s.enterByteOffset == state.enterByteOffset && s.syntaxRule.equals(state.syntaxRule)) { return true; } } return false; }
containsLexerState
27,578
boolean (@NotNull Queue<Token> output, Constants.CaptureKey captureKey, SyntaxNodeDescriptor rule, MatchData matchData, StringWithId string, CharSequence line, int startLineOffset, FList<TextMateLexerState> states) { TextMateCapture @Nullable [] captures = rule.getCaptureRules(captureKey); if (captures == null) { return false; } Deque<TextMateRange> activeCaptureRanges = new LinkedList<>(); for (int group = 0; group < matchData.count(); group++) { TextMateCapture capture = group < captures.length ? captures[group] : null; if (capture == null) { continue; } TextMateRange byteRange = matchData.byteOffset(group); if (byteRange.isEmpty()) { continue; } TextMateRange captureRange = matchData.charRange(line, string.bytes, group); while (!activeCaptureRanges.isEmpty() && activeCaptureRanges.peek().end <= captureRange.start) { closeScopeSelector(output, startLineOffset + activeCaptureRanges.pop().end); } if (capture instanceof TextMateCapture.Name) { CharSequence captureName = ((TextMateCapture.Name)capture).getName(); CharSequence scopeName = rule.hasBackReference(captureKey, group) ? SyntaxMatchUtils.replaceGroupsWithMatchDataInCaptures(captureName, string, matchData) : captureName; int selectorStartOffset = 0; int indexOfSpace = Strings.indexOf(scopeName, ' ', selectorStartOffset); if (indexOfSpace == -1) { openScopeSelector(output, scopeName, startLineOffset + captureRange.start); activeCaptureRanges.push(captureRange); } else { while (indexOfSpace >= 0) { openScopeSelector(output, scopeName.subSequence(selectorStartOffset, indexOfSpace), startLineOffset + captureRange.start); selectorStartOffset = indexOfSpace + 1; indexOfSpace = Strings.indexOf(scopeName, ' ', selectorStartOffset); activeCaptureRanges.push(captureRange); } openScopeSelector(output, scopeName.subSequence(selectorStartOffset, scopeName.length()), startLineOffset + captureRange.start); activeCaptureRanges.push(captureRange); } } else if (capture instanceof TextMateCapture.Rule) { CharSequence capturedString = line.subSequence(0, captureRange.end); StringWithId capturedStringWithId = new StringWithId(capturedString); TextMateLexerState captureState = new TextMateLexerState(((TextMateCapture.Rule)capture).getNode(), matchData, TextMateWeigh.Priority.NORMAL, byteRange.start, capturedStringWithId); parseLine(capturedString, output, states.prepend(captureState), startLineOffset, captureRange.start, byteRange.start); } else { throw new IllegalStateException("unknown capture type: " + capture); } } while (!activeCaptureRanges.isEmpty()) { closeScopeSelector(output, startLineOffset + activeCaptureRanges.pop().end); } return true; }
parseCaptures
27,579
void (@NotNull Queue<Token> output, @Nullable CharSequence name, int position) { addToken(output, position); myCurrentScope = myCurrentScope.add(name); }
openScopeSelector
27,580
void (@NotNull Queue<Token> output, int position) { CharSequence lastOpenedName = myCurrentScope.getScopeName(); if (lastOpenedName != null && !lastOpenedName.isEmpty()) { addToken(output, position); } myCurrentScope = myCurrentScope.getParentOrSelf(); }
closeScopeSelector
27,581
void (@NotNull Queue<Token> output, int position) { position = Math.min(position, myText.length()); if (position > myCurrentOffset) { boolean newState = myCurrentScope.getParent() == null; int wsStart = myCurrentOffset; while (myStripWhitespaces && position > myCurrentOffset && Character.isWhitespace(myText.charAt(myCurrentOffset))) { myCurrentOffset++; } if (wsStart < myCurrentOffset) { output.offer(new Token(TextMateScope.WHITESPACE, wsStart, myCurrentOffset, newState)); newState = false; } int wsEnd = position; while (myStripWhitespaces && wsEnd > myCurrentOffset && Character.isWhitespace(myText.charAt(wsEnd - 1))) { wsEnd--; } if (myCurrentOffset < wsEnd) { output.offer(new Token(myCurrentScope, myCurrentOffset, wsEnd, newState)); } if (wsEnd < position) { output.offer(new Token(TextMateScope.WHITESPACE, wsEnd, position, newState)); } myCurrentOffset = position; } }
addToken
27,582
void (@NotNull CharSequence scopeName, @NotNull Plist plist) { final PListValue shellVariables = plist.getPlistValue(Constants.SHELL_VARIABLES_KEY); if (shellVariables != null) { for (PListValue variable : shellVariables.getArray()) { Plist variablePlist = variable.getPlist(); String name = variablePlist.getPlistValue(Constants.NAME_KEY, "").getString(); String value = variablePlist.getPlistValue(Constants.VALUE_KEY, "").getString(); addVariable(new TextMateShellVariable(scopeName, name, value)); } } }
fillVariablesFromPlist
27,583
void (@NotNull TextMateShellVariable variable) { if (!variable.name.isEmpty()) { myVariables.computeIfAbsent(variable.name, key -> Collections.synchronizedList(new CopyOnWriteArrayList<>())).add(variable); } }
addVariable
27,584
TextMateShellVariable (@NotNull String name, @Nullable TextMateScope scope) { if (scope == null) { return null; } Collection<TextMateShellVariable> variables = myVariables.get(name); if (variables == null) { return null; } return new TextMateScopeComparator<>(scope, TextMateShellVariable::getScopeSelector).max(variables); }
getVariableValue
27,585
void () { myVariables.clear(); }
clear
27,586
String () { return myKey; }
getKey
27,587
String () { return myContent; }
getContent
27,588
CharSequence () { return myScope; }
getScopeSelector
27,589
String () { return myName; }
getName
27,590
String () { return mySettingsId; }
getSettingsId
27,591
IndentationRules () { return new IndentationRules(null, null, null, null); }
empty
27,592
Boolean () { return myIncreaseIndentPattern == null && myDecreaseIndentPattern == null && myIndentNextLinePattern == null && myUnIndentedLinePattern == null; }
isEmpty
27,593
IndentationRules (IndentationRules other) { return new IndentationRules( other.myIncreaseIndentPattern != null ? other.myIncreaseIndentPattern : myIncreaseIndentPattern, other.myDecreaseIndentPattern != null ? other.myDecreaseIndentPattern : myDecreaseIndentPattern, other.myIndentNextLinePattern != null ? other.myIndentNextLinePattern : myIndentNextLinePattern, other.myUnIndentedLinePattern != null ? other.myUnIndentedLinePattern : myUnIndentedLinePattern ); }
updateWith
27,594
CharSequence () { return scopeName; }
getScopeSelector
27,595
Set<TextMateBracePair> () { return myHighlightingPairs; }
getHighlightingPairs
27,596
Set<TextMateAutoClosingPair> () { return mySmartTypingPairs; }
getSmartTypingPairs
27,597
Set<TextMateBracePair> () { return mySurroundingPairs; }
getSurroundingPairs
27,598
String () { return myAutoCloseBefore; }
getAutoCloseBefore
27,599
CharSequence () { return myScopeRule; }
getScopeSelector