support interface

This commit is contained in:
CaiHQ 2023-06-09 18:23:51 +08:00
parent 645f863d7b
commit b60e81e1a1
6 changed files with 85 additions and 5 deletions

4
README.md Normal file
View File

@ -0,0 +1,4 @@
1.修改input下面的`YJSParser.g4`
2.运行`AntlrGenLexerTool`
3.运行`AntlrGenParserTool`
4.运行`CleanTempFiles`

View File

@ -61,8 +61,14 @@ annotationLiteral
clzOrFunctionDeclaration
:classDeclaration
|functionDeclaration
|interfaceDeclaration
|eventDeclaration
;
interfaceDeclaration
: annotations? Interface Identifier '(' formalParameterList? ')' eos
;
eventDeclaration
:Event eventGlobalOrLocal? Identifier SemiColon
|Event eventGlobalOrLocal? Identifier '(' eventSemantics? ')' SemiColon

View File

@ -0,0 +1,26 @@
import org.antlr.v4.Tool;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class AntlrGenLexerTool {
public static void main(String[] args) throws IOException {
processLexer();
}
private static void processLexer() {
String g5 = "JavaScriptLexer.g4";
String pkg = "org.bdware.sc.parser";
File from = new File("./genparser/input/" + g5);
File out = new File(g5);
out.delete();
try {
Files.copy(from.toPath(), out.toPath());
Tool.main(new String[]{g5, "-package", pkg, "-o", "./common/src/main/gen/" +
pkg.replaceAll("\\.", "/"), "-visitor"});
new File(g5).delete();
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,33 @@
import org.antlr.v4.Tool;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class AntlrGenParserTool {
public static void main(String[] args) throws IOException {
processParser();
}
private static void processParser() {
String g4 = "YJSParser.g4";
String pkg;
// g4 = "ExprParser.g4";
if (g4.equals("YJSParser.g4"))
pkg = "org.bdware.sc.parser";
else
pkg = "org.bdware.sc.parser.test";
System.out.println("GenerateAt:" + "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"));
File from = new File("./genparser/input/" + g4);
File out = new File(g4);
out.delete();
try {
Files.copy(from.toPath(), out.toPath());
} catch (Exception e) {
e.printStackTrace();
}
Tool.main(new String[]{g4, "-package", pkg, "-o", "./common/src/main/gen/" + pkg.replaceAll("\\.", "/"), "-visitor"});
}
}

View File

@ -5,12 +5,10 @@ import java.io.IOException;
import java.nio.file.Files;
public class AntlrTool {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
processLexer();
// processParser();
processLexer();
// processParser();
}
private static void processParser() {

View File

@ -0,0 +1,13 @@
import java.io.File;
import java.io.IOException;
public class CleanTempFiles {
public static void main(String[] args) throws IOException {
String g4 = "YJSParser.g4";
File out = new File(g4);
out.delete();
String g5 = "JavaScriptLexer.g4";
out = new File(g5);
out.delete();
}
}