diff --git a/README.md b/README.md new file mode 100644 index 0000000..49c66d6 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +1.修改input下面的`YJSParser.g4` +2.运行`AntlrGenLexerTool` +3.运行`AntlrGenParserTool` +4.运行`CleanTempFiles` \ No newline at end of file diff --git a/input/YJSParser.g4 b/input/YJSParser.g4 index 2b16e10..ac3ab32 100644 --- a/input/YJSParser.g4 +++ b/input/YJSParser.g4 @@ -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 diff --git a/src/main/entry/AntlrGenLexerTool.java b/src/main/entry/AntlrGenLexerTool.java new file mode 100644 index 0000000..f5645ca --- /dev/null +++ b/src/main/entry/AntlrGenLexerTool.java @@ -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(); + } + } +} diff --git a/src/main/entry/AntlrGenParserTool.java b/src/main/entry/AntlrGenParserTool.java new file mode 100644 index 0000000..5cd3751 --- /dev/null +++ b/src/main/entry/AntlrGenParserTool.java @@ -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"}); + } +} diff --git a/src/main/entry/AntlrTool.java b/src/main/entry/AntlrTool.java index 526ceeb..c3bff16 100644 --- a/src/main/entry/AntlrTool.java +++ b/src/main/entry/AntlrTool.java @@ -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() { diff --git a/src/main/entry/CleanTempFiles.java b/src/main/entry/CleanTempFiles.java new file mode 100644 index 0000000..03ed53b --- /dev/null +++ b/src/main/entry/CleanTempFiles.java @@ -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(); + } +}