GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tm4java/src/test/java/tm4java/UsageTest.java at master · mkpaz/tm4java

Expand file tree

/

UsageTest.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
64 lines (54 loc) · 2.23 KB
/

UsageTest.java

Copy path

File metadata and controls

64 lines (54 loc) · 2.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright © 2025 tm4java authors
* Original authors (EPL-2.0): Sebastian Thomschke, Angelo Zerr (tm4e).
* Initial code (MIT): Microsoft Corporation (vscode-textmate).
*
* This program is licensed under the Eclipse Public License 2.0 (EPL-2.0).
* See https://www.eclipse.org/legal/epl-2.0/ for details.
*/
package tm4java;
import java.time.Duration;
import java.util.Arrays;
import java.util.function.BiConsumer;
import tm4java.grammar.IGrammar;
import tm4java.grammar.IGrammarSource;
import tm4java.grammar.IStateStack;
import tm4java.grammar.IToken;
import tm4java.grammar.ITokenizeLineResult;
import tm4java.registry.Registry;
import tm4java.theme.ITheme;
import tm4java.theme.IThemeSource;
import tm4java.theme.StyleAttributes;
public class UsageTest {
public static void main(String[] args) {
var registry = new Registry();
IGrammar grammar = registry.addGrammar(IGrammarSource.fromFile(
Resources.getFile("/tm4java/language_pack/java/java.tmLanguage.json")
));
ITheme theme = registry.setTheme(IThemeSource.fromFile(
Resources.getFile("/tm4java/test-cases/themes/light_vs.json")
));
String text = """
public static void main(String[] args) {
System.out.println("Hello World!");
}
""";
BiConsumer<String, IToken> printer = (line, token) -> {
System.out.printf("Token:\t'%s'%n", line.substring(token.getStartIndex(), token.getEndIndex()));
System.out.printf("Scopes:\t%s%n",token.getScopes());
for (int i = token.getScopes().size() - 1; i >= 0; i--) {
String scope = token.getScopes().get(i);
StyleAttributes style = theme.match(scope);
if (style != null && !StyleAttributes.NO_STYLE.equals(style)) {
System.out.println("Style:\t" + style);
}
}
};
IStateStack state = null;
for (var line : text.split("\r?\n")) {
ITokenizeLineResult<IToken[]> result = grammar.tokenizeLine(line, state, Duration.ofSeconds(1));
state = result.ruleStack();
Arrays.stream(result.tokens()).forEach(token -> printer.accept(line, token));
}
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.