Skip to content

Commit eebeb4e

Browse files
committed
fix: invalid lookbehind when parsing julia textmate language
1 parent e7c67d4 commit eebeb4e

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/oniguruma/OnigRegExp.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ private String rewritePatternIfRequired(final String pattern) {
117117
if (pattern.startsWith(lookbehind3)) {
118118
return "\\s*\\." + pattern.substring(lookbehind3.length());
119119
}
120+
121+
// e.g. used in julia.tmLanguage.json
122+
final var lookbehind4 = "(?<=\\S\\s+)";
123+
if (pattern.startsWith(lookbehind4)) {
124+
return "\\S\\s+" + pattern.substring(lookbehind4.length());
125+
}
120126
return pattern;
121127
}
122128

org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/parser/TMParserTest.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.eclipse.tm4e.core.internal.grammar.raw.RawGrammarReader;
3737
import org.eclipse.tm4e.core.internal.oniguruma.OnigRegExp;
3838
import org.eclipse.tm4e.core.internal.utils.ResourceUtils;
39+
import org.eclipse.tm4e.core.registry.IGrammarSource;
40+
import org.eclipse.tm4e.core.registry.Registry;
3941
import org.junit.jupiter.api.MethodOrderer;
4042
import org.junit.jupiter.api.Test;
4143
import org.junit.jupiter.api.TestMethodOrder;
@@ -235,18 +237,28 @@ void testLanguagePackGrammars() throws IOException {
235237
Files.walkFileTree(Paths.get("../org.eclipse.tm4e.language_pack"), new SimpleFileVisitor<Path>() {
236238
@Override
237239
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
238-
if (file.getFileName().toString().endsWith("tmLanguage.json")) {
239-
try (var input = Files.newBufferedReader(file)) {
240+
final var fileName = file.getFileName().toString().toLowerCase();
241+
if (fileName.endsWith("tmlanguage.yaml") || fileName.endsWith("tmlanguage.json") || fileName.endsWith("plist")
242+
|| fileName.endsWith("tmlanguage")) {
243+
try {
240244
System.out.println("Parsing [" + file + "]...");
241-
final var grammar = TMParserJSON.INSTANCE.parse(input, RawGrammarReader.OBJECT_FACTORY);
245+
final var rawGrammar = RawGrammarReader.readGrammar(IGrammarSource.fromFile(file));
242246
count.incrementAndGet();
243-
assertFalse(grammar.getScopeName().isBlank());
244-
assertNotNull(grammar.getFileTypes());
245-
assertNotNull(grammar.getRepository());
247+
assertFalse(rawGrammar.getScopeName().isBlank());
248+
assertNotNull(rawGrammar.getFileTypes());
249+
assertNotNull(rawGrammar.getRepository());
246250

247-
final var patterns = castNonNull(grammar.getPatterns());
251+
final var patterns = castNonNull(rawGrammar.getPatterns());
248252
assertFalse(patterns.isEmpty());
249253
assertParseablePatterns(patterns);
254+
255+
final var reg = new Registry();
256+
final var grammar = reg.addGrammar(IGrammarSource.fromFile(file));
257+
assertEquals(grammar.getName(), rawGrammar.getName());
258+
assertEquals(grammar.getScopeName(), rawGrammar.getScopeName());
259+
assertEquals(grammar.getFileTypes(), rawGrammar.getFileTypes());
260+
grammar.tokenizeLine("");
261+
250262
} catch (final Exception ex) {
251263
throw new RuntimeException(ex);
252264
}

0 commit comments

Comments
 (0)