Skip to content

Commit 383db44

Browse files
committed
Merge branch 'master' of github.com:antlr/grammars-v4
2 parents 3143dbd + 1089213 commit 383db44

File tree

3 files changed

+100
-20
lines changed

3 files changed

+100
-20
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@
6565
/support/antlr4test-maven-plugin/target/
6666

6767
/bnf/target/
68+
69+
/support/antlr4test-maven-plugin/.settings/
70+
/support/antlr4test-maven-plugin/.project
71+
/support/antlr4test-maven-plugin/.classpath
72+
73+
/swift/target/

support/antlr4test-maven-plugin/src/main/java/org/antlr/mojo/antlr4test/GrammarTestMojo.java

+42-20
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ public void setVerbose(boolean verbose) {
198198
this.verbose = verbose;
199199
}
200200

201-
private void testGrammars() throws Exception {
201+
/**
202+
* test a single grammar
203+
*/
204+
private void testGrammar(File grammarFile) throws Exception {
202205
/*
203206
* figure out class names
204207
*/
@@ -226,35 +229,54 @@ private void testGrammars() throws Exception {
226229
*/
227230
final Constructor<?> lexerConstructor = lexerClass.getConstructor(CharStream.class);
228231
final Constructor<?> parserConstructor = parserClass.getConstructor(TokenStream.class);
232+
System.out.println("Parsing :" + grammarFile.getAbsolutePath());
233+
ANTLRFileStream antlrFileStream = new ANTLRFileStream(grammarFile.getAbsolutePath(), "UTF-8");
234+
Lexer lexer = (Lexer) lexerConstructor.newInstance(antlrFileStream);
235+
final CommonTokenStream tokens = new CommonTokenStream(lexer);
236+
if (verbose) {
237+
tokens.fill();
238+
for (final Object tok : tokens.getTokens()) {
239+
System.out.println(tok);
240+
}
241+
}
242+
/*
243+
* get parser
244+
*/
245+
Parser parser = (Parser) parserConstructor.newInstance(tokens);
246+
parser.setErrorHandler(new BailErrorStrategy());
247+
final Method method = parserClass.getMethod(entryPoint);
248+
ParserRuleContext parserRuleContext = (ParserRuleContext) method.invoke(parser);
249+
/*
250+
* show the tree
251+
*/
252+
if (showTree) {
253+
final String lispTree = Trees.toStringTree(parserRuleContext, parser);
254+
System.out.println(lispTree);
255+
}
256+
/*
257+
* yup
258+
*/
259+
parser = null;
260+
lexer = null;
261+
parserRuleContext = null;
262+
antlrFileStream = null;
263+
}
264+
265+
private void testGrammars() throws Exception {
229266
/*
230267
* iterate examples
231268
*/
232269
final List<File> exampleFiles = FileUtil.getAllFiles(baseDir + "/" + this.exampleFiles);
233270
if (null != exampleFiles) {
234271
for (final File file : exampleFiles) {
235-
System.out.println("Parsing :" + file.getAbsolutePath());
236-
final Lexer lexer = (Lexer) lexerConstructor.newInstance(new ANTLRFileStream(file.getAbsolutePath(), "UTF-8"));
237-
final CommonTokenStream tokens = new CommonTokenStream(lexer);
238-
if (verbose) {
239-
tokens.fill();
240-
for (final Object tok : tokens.getTokens()) {
241-
System.out.println(tok);
242-
}
243-
}
244272
/*
245-
* get parser
273+
* test grammar
246274
*/
247-
final Parser parser = (Parser) parserConstructor.newInstance(tokens);
248-
parser.setErrorHandler(new BailErrorStrategy());
249-
final Method method = parserClass.getMethod(entryPoint);
250-
final ParserRuleContext parserRuleContext = (ParserRuleContext) method.invoke(parser);
275+
testGrammar(file);
251276
/*
252-
* show the tree
277+
* gc
253278
*/
254-
if (showTree) {
255-
final String lispTree = Trees.toStringTree(parserRuleContext);
256-
System.out.println(lispTree);
257-
}
279+
System.gc();
258280
}
259281
}
260282
}

swift/pom.xml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>swift</artifactId>
5+
<packaging>jar</packaging>
6+
<name>ANTLR Swift grammar</name>
7+
<parent>
8+
<groupId>com.antlr.grammarsv4</groupId>
9+
<artifactId>grammarsv4</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
<build>
14+
<plugins>
15+
<plugin>
16+
<groupId>org.antlr</groupId>
17+
<artifactId>antlr4-maven-plugin</artifactId>
18+
<version>${antlr.version}</version>
19+
<configuration>
20+
<sourceDirectory>${basedir}</sourceDirectory>
21+
<grammars>tnt.g4</grammars>
22+
</configuration>
23+
<executions>
24+
<execution>
25+
<goals>
26+
<goal>antlr4</goal>
27+
</goals>
28+
</execution>
29+
</executions>
30+
</plugin>
31+
<plugin>
32+
<groupId>org.antlr</groupId>
33+
<artifactId>antlr4test-maven-plugin</artifactId>
34+
<configuration>
35+
<verbose>false</verbose>
36+
<showTree>true</showTree>
37+
<entryPoint>statement</entryPoint>
38+
<grammarName>Swift</grammarName>
39+
<packageName></packageName>
40+
<exampleFiles>examples/</exampleFiles>
41+
</configuration>
42+
<executions>
43+
<execution>
44+
<goals>
45+
<goal>test</goal>
46+
</goals>
47+
</execution>
48+
</executions>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
</project>

0 commit comments

Comments
 (0)