-
Notifications
You must be signed in to change notification settings - Fork 0
/
useful.txt
45 lines (35 loc) · 1.18 KB
/
useful.txt
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
# get java
# get homebrew
# get ANTLR
brew update; brew install antlr
# regenerate recogniser java source files for latest antlr
cd directory-containing-this
antlr4 -o src -Dlanguage=Java -listener -visitor Java8.g4
# build the source without an IDE
cd directory-containing-this
mkdir out/production/J2S
javac -cp "/usr/local/Cellar/antlr/4.6/antlr-4.6-complete.jar:." -d out/production/J2S src/*.java
# use the binaries to convert a java file
src_file=path-to-your-source-file
dst_file="${src_file%\.*}.swift"
cd directory-containing-this
J2S="$(pwd)/out/production/J2S"
java -cp "/usr/local/Cellar/antlr/4.6/antlr-4.6-complete.jar:${J2S}:." J2S "${src_file}" > "${dst_file}"
# Misc
# Regex to create listener stubs from grammar
:Find:
(^(\s*)([a-z])(\w+)\n(.+\n)+?\s*;$)
:Replace with:
$2/*
$1
$2@Override public void enter\u$3$4( Java8Parser.\u$3$4Context ctx ) { }
$2@Override public void exit\u$3$4( Java8Parser.\u$3$4Context ctx ) { }
$2*/
# Regex to create visitor stubs from grammar (substitute your visitor return type for T)
:Find:
(^(\s*)([a-z])(\w+)\n(.+\n)+?\s*;$)
:Replace with:
$2/*
$1
$2@Override public T visit\u$3$4( Java8Parser.\u$3$4Context ctx ) { return visitChildren(ctx); }
$2*/