mirror of
https://gitee.com/BDWare/genparser
synced 2025-04-26 22:12:17 +00:00
support interface
This commit is contained in:
parent
645f863d7b
commit
b60e81e1a1
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
||||
1.修改input下面的`YJSParser.g4`
|
||||
2.运行`AntlrGenLexerTool`
|
||||
3.运行`AntlrGenParserTool`
|
||||
4.运行`CleanTempFiles`
|
@ -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
|
||||
|
26
src/main/entry/AntlrGenLexerTool.java
Normal file
26
src/main/entry/AntlrGenLexerTool.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
33
src/main/entry/AntlrGenParserTool.java
Normal file
33
src/main/entry/AntlrGenParserTool.java
Normal 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"});
|
||||
}
|
||||
}
|
@ -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() {
|
||||
|
13
src/main/entry/CleanTempFiles.java
Normal file
13
src/main/entry/CleanTempFiles.java
Normal 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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user