Skip to content

Commit

Permalink
refact: rename OnigScanner#findNextMatchSync to findNextMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jun 11, 2023
1 parent 2a84d09 commit 715289f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ private MatchResult matchRule(final Grammar grammar, final OnigString lineText,
final var rule = stack.getRule(grammar);
final var ruleScanner = rule.compileAG(grammar, stack.endRule, isFirstLine, linePos == anchorPosition);

final OnigNextMatchResult r = ruleScanner.scanner.findNextMatchSync(lineText, linePos);
final OnigNextMatchResult r = ruleScanner.scanner.findNextMatch(lineText, linePos);

if (r != null) {
return new MatchResult(ruleScanner.rules[r.getIndex()], r.getCaptureIndices());
Expand Down Expand Up @@ -379,7 +379,7 @@ private MatchInjectionsResult matchInjections(final List<Injection> injections,

final var rule = grammar.getRule(injection.ruleId);
final var ruleScanner = rule.compileAG(grammar, null, isFirstLine, linePos == anchorPosition);
final var matchResult = ruleScanner.scanner.findNextMatchSync(lineText, linePos);
final var matchResult = ruleScanner.scanner.findNextMatch(lineText, linePos);
if (matchResult == null) {
continue;
}
Expand Down Expand Up @@ -524,7 +524,7 @@ final class WhileStack {
final var whileRule = whileRules.get(i);

final var ruleScanner = whileRule.rule.compileWhileAG(whileRule.stack.endRule, isFirstLine, anchorPosition == linePos);
final var r = ruleScanner.scanner.findNextMatchSync(lineText, linePos);
final var r = ruleScanner.scanner.findNextMatch(lineText, linePos);
if (LOGGER.isLoggable(TRACE)) {
LOGGER.log(TRACE, " scanning for while rule");
LOGGER.log(TRACE, debugCompiledRuleToString(ruleScanner));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.eclipse.tm4e.core.internal.oniguruma;

import java.util.Collection;
import java.util.List;

import org.eclipse.jdt.annotation.Nullable;

Expand All @@ -28,12 +28,12 @@ public final class OnigScanner {

private final OnigSearcher searcher;

public OnigScanner(final Collection<String> regexps) {
public OnigScanner(final List<String> regexps) {
searcher = new OnigSearcher(regexps);
}

@Nullable
public OnigNextMatchResult findNextMatchSync(final OnigString source, final int startPosition) {
public OnigNextMatchResult findNextMatch(final OnigString source, final int startPosition) {
final OnigResult bestResult = searcher.search(source, startPosition);
if (bestResult != null) {
return new OnigNextMatchResult(bestResult, source);
Expand All @@ -42,7 +42,7 @@ public OnigNextMatchResult findNextMatchSync(final OnigString source, final int
}

@Nullable
public OnigNextMatchResult findNextMatchSync(final String text, final int startPosition) {
return findNextMatchSync(OnigString.of(text), startPosition);
public OnigNextMatchResult findNextMatch(final String text, final int startPosition) {
return findNextMatch(OnigString.of(text), startPosition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.eclipse.tm4e.core.internal.oniguruma;

import java.util.Collection;
import java.util.List;

import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -29,7 +28,7 @@ final class OnigSearcher {

private final List<OnigRegExp> regExps;

OnigSearcher(final Collection<String> regExps) {
OnigSearcher(final List<String> regExps) {
this.regExps = regExps.stream().map(OnigRegExp::new).toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class OnigScannerTest {
@Test
void testOnigScanner() {
var scanner = new OnigScanner(Arrays.asList("c", "a(b)?"));
OnigNextMatchResult result = scanner.findNextMatchSync("abc", 0);
OnigNextMatchResult result = scanner.findNextMatch("abc", 0);
assertNotNull(result);
assertEquals(1, result.getIndex());
assertArrayEquals(new OnigCaptureIndex[] {
Expand All @@ -31,7 +31,7 @@ void testOnigScanner() {
result.getCaptureIndices());

scanner = new OnigScanner(Arrays.asList("a([b-d])c"));
result = scanner.findNextMatchSync("!abcdef", 0);
result = scanner.findNextMatch("!abcdef", 0);
assertNotNull(result);
assertEquals(0, result.getIndex());
assertArrayEquals(new OnigCaptureIndex[] {
Expand Down

0 comments on commit 715289f

Please sign in to comment.