forked from jasder/antlr
Merge remote-tracking branch 'refs/remotes/antlr/master'
This commit is contained in:
commit
df600054af
|
@ -1,6 +1,8 @@
|
|||
Before submitting an issue to ANTLR, please check off these boxes:
|
||||
Before submitting an issue to ANTLR, please check off these boxes:
|
||||
|
||||
- [ ] I am not submitting a question on how to use ANTLR; instead, go to [antlr4-discussion google group](https://groups.google.com/forum/#!forum/antlr-discussion) or ask at [stackoverflow](http://stackoverflow.com/questions/tagged/antlr4)
|
||||
- [ ] I have done a search of the existing issues to make sure I'm not sending in a duplicate
|
||||
|
||||
[cut]
|
||||
Please include information about the expected behavior, actual behavior, and the smallest grammar or code that reproduces the behavior. If appropriate, please indicate the code generation targets such as Java, C#, ... Pointers into offending code regions are also very welcome.
|
||||
[/cut]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
Thank you for proposing a contribution to the ANTLR project. In order to accept changes from the outside world, all contributors most "sign" the [contributors.txt](https://github.com/antlr/antlr4/blob/master/contributors.txt) contributors certificate of origin. It's an unfortunate reality of today's fuzzy and bizarre world of open-source ownership.
|
||||
[cut]
|
||||
Thank you for proposing a contribution to the ANTLR project. In order to accept changes from the outside world, all contributors must "sign" the [contributors.txt](https://github.com/antlr/antlr4/blob/master/contributors.txt) contributors certificate of origin. It's an unfortunate reality of today's fuzzy and bizarre world of open-source ownership.
|
||||
|
||||
Make sure you are already in the contributors.txt file or add a commit to this pull request with the appropriate change. Thanks!
|
||||
[/cut]
|
||||
|
|
10
LICENSE.txt
10
LICENSE.txt
|
@ -1,6 +1,5 @@
|
|||
[The "BSD license"]
|
||||
Copyright (c) 2015 Terence Parr, Sam Harwell
|
||||
All rights reserved.
|
||||
[The "BSD 3-clause license"]
|
||||
Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
|
@ -11,8 +10,9 @@ are met:
|
|||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
*Given day-job constraints, my time working on this project is limited so I'll have to focus first on fixing bugs rather than changing/improving the feature set. Likely I'll do it in bursts every few months. Please do not be offended if your bug or pull request does not yield a response! --parrt*
|
||||
|
||||
[![Donate](https://www.paypal.com/en_US/i/btn/x-click-butcc-donate.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BF92STRXT8F8Q)
|
||||
|
||||
## Authors and major contributors
|
||||
|
||||
* [Terence Parr](http://www.cs.usfca.edu/~parrt/), parrt@cs.usfca.edu
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<project-shared-configuration>
|
||||
<!--
|
||||
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||
|
|
|
@ -1,40 +1,14 @@
|
|||
<!--
|
||||
|
||||
[The "BSD license"]
|
||||
ANTLR - Copyright (c) Terence Parr, Sam Harwell
|
||||
Maven Plugin - Copyright (c) Jim Idle
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.6-SNAPSHOT</version>
|
||||
<version>4.6.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>antlr4-maven-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
@ -90,7 +64,7 @@
|
|||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -131,6 +105,11 @@
|
|||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<testSourceDirectory>src/test</testSourceDirectory>
|
||||
<testResources>
|
||||
<testResource>
|
||||
|
@ -189,7 +168,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<version>2.10.4</version>
|
||||
<configuration>
|
||||
<quiet>true</quiet>
|
||||
</configuration>
|
||||
|
@ -197,7 +176,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jxr-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<version>2.5</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
|
|
|
@ -1,31 +1,8 @@
|
|||
/*
|
||||
[The "BSD license"]
|
||||
Copyright (c) 2012 Terence Parr
|
||||
Copyright (c) 2012 Sam Harwell
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
* Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
* Use of this file is governed by the BSD 3-clause license that
|
||||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
package org.antlr.mojo.antlr4;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
|
|
|
@ -1,31 +1,8 @@
|
|||
/*
|
||||
[The "BSD license"]
|
||||
Copyright (c) 2012 Terence Parr
|
||||
Copyright (c) 2012 Sam Harwell
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. The name of the author may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
* Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
* Use of this file is governed by the BSD 3-clause license that
|
||||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.mojo.antlr4;
|
||||
|
||||
|
@ -173,6 +150,13 @@ public class Antlr4Mojo extends AbstractMojo {
|
|||
@Parameter(property = "project", required = true, readonly = true)
|
||||
protected MavenProject project;
|
||||
|
||||
/**
|
||||
* Specifies whether sources are added to the {@code compile} or
|
||||
* {@code test} scope.
|
||||
*/
|
||||
@Parameter(property = "antlr4.generateTestSources", defaultValue = "false")
|
||||
private boolean generateTestSources;
|
||||
|
||||
/**
|
||||
* The directory where the ANTLR grammar files ({@code *.g4}) are located.
|
||||
*/
|
||||
|
@ -213,7 +197,12 @@ public class Antlr4Mojo extends AbstractMojo {
|
|||
}
|
||||
|
||||
void addSourceRoot(File outputDir) {
|
||||
project.addCompileSourceRoot(outputDir.getPath());
|
||||
if (generateTestSources) {
|
||||
project.addTestCompileSourceRoot(outputDir.getPath());
|
||||
}
|
||||
else {
|
||||
project.addCompileSourceRoot(outputDir.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
* Use of this file is governed by the BSD 3-clause license that
|
||||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.mojo.antlr4;
|
||||
|
||||
import org.antlr.runtime.tree.Tree;
|
||||
|
||||
import org.antlr.v4.Tool;
|
||||
import org.antlr.v4.misc.Graph;
|
||||
import org.antlr.v4.parse.ANTLRParser;
|
||||
import org.antlr.v4.tool.ast.GrammarAST;
|
||||
import org.antlr.v4.tool.ast.GrammarRootAST;
|
||||
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -16,7 +20,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
* Use of this file is governed by the BSD 3-clause license that
|
||||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.mojo.antlr4;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<project name="ANTLR v4 Maven plugin">
|
||||
|
||||
<publishDate position="left"/>
|
||||
|
@ -7,7 +13,7 @@
|
|||
|
||||
<poweredBy>
|
||||
<logo name="ANTLR Web Site" href="http://antlr.org/"
|
||||
img="http://www.antlr.org/wiki/download/attachments/292/ANTLR4"/>
|
||||
img="http://www.antlr.org/images/antlr-logo.png"/>
|
||||
</poweredBy>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
* Use of this file is governed by the BSD 3-clause license that
|
||||
* can be found in the LICENSE.txt file in the project root.
|
||||
*/
|
||||
|
||||
package org.antlr.mojo.antlr4;
|
||||
|
||||
import io.takari.maven.testing.TestMavenRuntime;
|
||||
import io.takari.maven.testing.TestResources;
|
||||
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.plugin.MojoExecution;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
@ -21,6 +23,9 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class Antlr4MojoTest {
|
||||
@Rule
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
|
|
@ -126,3 +126,6 @@ YYYY/MM/DD, github id, Full name, email
|
|||
2016/11/29, Naios, Denis Blank, naios@users.noreply.github.com
|
||||
2016/12/01, samtatasurya, Samuel Tatasurya, xemradiant@gmail.com
|
||||
2016/12/03, redxdev, Samuel Bloomberg, sam@redxdev.com
|
||||
2016/12/11, Gaulouis, Gaulouis, gaulouis.com@gmail.com
|
||||
2016/12/22, akosthekiss, Akos Kiss, akiss@inf.u-szeged.hu
|
||||
2016/12/24, adrpo, Adrian Pop, adrian.pop@liu.se
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
# Integrating ANTLR into Development Systems
|
||||
|
||||
The Java target is the reference implementation mirrored by other targets. The following pages help you integrate ANTLR into development environments and build systems appropriate for your target language. As of January 2015, we have Java, C#, Python 2, Python 3, and JavaScript targets.
|
||||
The Java target is the reference implementation mirrored by other targets. The following pages help you integrate ANTLR into development environments and build systems appropriate for your target language. As of December 2016, we have Java, C#, Python 2, Python 3, JavaScript, Go, C++, and Swift targets.
|
||||
|
||||
The easiest thing is probably just to use an [ANTLR plug-in](http://www.antlr.org/tools.html) for your favorite development environment.
|
||||
|
||||
Java IDE Integration
|
||||
C# IDE Integration
|
||||
|
|
|
@ -174,13 +174,20 @@ At this point, you should have an editor which displays an error icon next to th
|
|||
|
||||
What remains to be done is have our validate function actually validate the input. Finally ANTLR comes in the picture!
|
||||
|
||||
To start with, let's load ANTLR and your parser, listener etc.. Easy, since you could write:
|
||||
To start with, let's load ANTLR and your parser, listener etc..
|
||||
|
||||
The preferred approach for loading parser code is to bundle your parser, [as described here](javascript-target.md).
|
||||
You can then load it as part of the importScripts instruction at the start of your worker code.
|
||||
|
||||
Another approach is to load it using 'require'. Easy, since you could write:
|
||||
|
||||
```js
|
||||
var antlr4 = require('antlr4/index');
|
||||
```
|
||||
|
||||
This may work, but it's actually unreliable. The reason is that the require function used by ANTLR, which exactly mimics the NodeJS require function, uses a different syntax than the require function that comes with ACE. So we need to bring in a require function that conforms to the NodeJS syntax. I personally use one that comes from Torben Haase's Honey project, which you can find here. But hey, now we're going to have 2 'require' functions not compatible with each other! Indeed, this is why you need to take special care, as follows:
|
||||
This may work, but it's actually unreliable. The reason is that the 'require' function that comes with ACE uses a different syntax than the 'require' function used by ANTLR, which follows the NodeJS 'require' convention.
|
||||
So we need to bring in a NodeJS compatible 'require' function that conforms to the NodeJS syntax. I personally use one that comes from Torben Haase's Honey project, which you can find in li/require.js.
|
||||
But hey, now we're going to have 2 'require' functions not compatible with each other! Indeed, this is why you need to take special care, as follows:
|
||||
|
||||
```js
|
||||
// load nodejs compatible require
|
||||
|
@ -191,7 +198,8 @@ importScripts("../lib/require.js");
|
|||
var antlr4_require = require;
|
||||
require = ace_require;
|
||||
```
|
||||
Now it's safe to load antlr, and the parsers generated for your language. Assuming that your language files (generated or hand-built) are in a folder with an index.js file that calls require for each file, your parser loading code can be as simple as follows:
|
||||
Now it's safe to load antlr and the parsers generated for your language.
|
||||
Assuming that your language files (generated or hand-built) are in a folder with an index.js file that calls require for each file, your parser loading code can be as simple as follows:
|
||||
```js
|
||||
// load antlr4 and myLanguage
|
||||
var antlr4, mylanguage;
|
||||
|
@ -204,6 +212,7 @@ try {
|
|||
}
|
||||
```
|
||||
Please note the try-finally construct. ANTLR uses 'require' synchronously so it's perfectly safe to ignore the ACE 'require' while running ANTLR code. ACE itself does not guarantee synchronous execution, so you are much safer always switching 'require' back to 'ace_require'.
|
||||
|
||||
Now detecting deep syntax errors in your code is a task for your ANTLR listener or visitor or whatever piece of code you've delegated this to. We're not going to describe this here, since it would require some knowledge of your language. However, detecting grammar syntax errors is something ANTLR does beautifully (isn't that why you went for ANTLR in the first place?). So what we will illustrate here is how to report grammar syntax errors. I have no doubt that from there, you will be able to extend the validator to suit your specific needs.
|
||||
Whenever ANTLR encounters an unexpected token, it fires an error. By default, the error is routed to an error listener which simply writes to the console.
|
||||
What we need to do is replace this listener by our own listener, se we can route errors to the ACE editor. First, let's create such a listener:
|
||||
|
@ -243,5 +252,4 @@ var validate = function(input) {
|
|||
};
|
||||
```
|
||||
You know what? That's it! You now have an ACE editor that does syntax validation using ANTLR! I hope you find this useful, and simple enough to get started.
|
||||
What I did not address here is packaging, not something I'm an expert at. The good news is that it makes development simple, since I don't have to run any compilation process. I just edit my code, reload my editor page, and check how it goes.
|
||||
Now wait, hey! How do you debug this? Well, as usual, using Chrome, since neither Firefox or Safari are able to debug worker code. What a shame...
|
||||
WNow wait, hey! How do you debug this? Well, as usual, using Chrome, since no other browser is able to debug worker code. What a shame...
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Adding unit tests
|
||||
# ANTLR project unit tests
|
||||
|
||||
## Introduction
|
||||
|
||||
|
@ -35,6 +35,39 @@ The mysterious `@CommentHasStringValue` annotation is a bit of a hack that allow
|
|||
The grammars are strings representing StringTemplates (`ST` objects) so `<writeln("$text")>` will get replace when the unit test file is generated (`Test.java`, `Test.cs`, ...). The `writeln` template must be defined per target. Here are all of the
|
||||
[Target templates for runtime tests](https://github.com/antlr/antlr4/tree/master/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates).
|
||||
|
||||
## Requirements
|
||||
|
||||
In order to perform the tests on all target languages, you need to have the following languages installed:
|
||||
|
||||
* `mono` (e.g., `brew install mono`) on non-Windows boxes (on Windows it uses the Microsoft .net stack). Also must [`xbuild` the runtime](https://github.com/antlr/antlr4/blob/master/doc/releasing-antlr.md) before tests will run; see below
|
||||
* `nodejs`
|
||||
* Python 2.7
|
||||
* Python 3.5
|
||||
* Go
|
||||
* Swift 3 (via XCode 8.x) tested currently only osx
|
||||
* clang (for C++ target)
|
||||
*
|
||||
To **install into local repository** `~/.m2/repository/org/antlr`, do this:
|
||||
|
||||
```bash
|
||||
$ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
|
||||
$ mvn install -DskipTests=true # make sure all artifacts are visible on this machine
|
||||
```
|
||||
|
||||
Now, make sure C# runtime is built and installed locally.
|
||||
|
||||
```bash
|
||||
cd ~/antlr/code/antlr4/runtime/CSharp/runtime/CSharp
|
||||
# kill previous ones manually as "xbuild /t:Clean" didn't seem to do it
|
||||
rm Antlr4.Runtime/bin/net20/Release/Antlr4.Runtime.dll
|
||||
rm Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.dll
|
||||
# build
|
||||
xbuild /p:Configuration=Release Antlr4.Runtime/Antlr4.Runtime.mono.csproj
|
||||
```
|
||||
|
||||
C++ test rig automatically builds C++ runtime during tests. Others don't need a prebuilt lib.
|
||||
|
||||
|
||||
## Running the runtime tests
|
||||
|
||||
A single test rig is sufficient to test all targets against all descriptors using the [junit parameterized tests](https://github.com/junit-team/junit4/wiki/parameterized-tests) mechanism. But, that is inconvenient because we often want to test just a single target or perhaps even just a single test within a single group of a single target. I have automatically generated a bunch of
|
||||
|
@ -49,26 +82,128 @@ And the result of testing the entire subdirectory:
|
|||
From `mvn`, on the commandline, you will see:
|
||||
|
||||
```bash
|
||||
$ cd antlr4
|
||||
$ mvn test
|
||||
...
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.javascript.node.TestCompositeLexers
|
||||
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.581 sec
|
||||
Running org.antlr.v4.test.runtime.javascript.node.TestLexerErrors
|
||||
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.721 sec
|
||||
Running org.antlr.v4.test.runtime.javascript.node.TestSemPredEvalParser
|
||||
Tests run: 26, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.084 sec
|
||||
Running org.antlr.v4.test.runtime.javascript.node.TestSets
|
||||
Tests run: 23, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.798 sec
|
||||
Running org.antlr.v4.test.runtime.javascript.node.TestPerformance
|
||||
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.505 sec
|
||||
Running org.antlr.v4.test.runtime.javascript.node.TestSemPredEvalLexer
|
||||
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.994 sec
|
||||
Running org.antlr.v4.test.runtime.javascript.node.TestLexerExec
|
||||
Tests run: 38, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.433 sec
|
||||
Running org.antlr.v4.test.runtime.csharp.TestCompositeLexers
|
||||
dir /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068612451
|
||||
Starting build /usr/bin/xbuild /p:Configuration=Release /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068612451/Antlr4.Test.mono.csproj
|
||||
dir /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068615081
|
||||
Starting build /usr/bin/xbuild /p:Configuration=Release /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068615081/Antlr4.Test.mono.csproj
|
||||
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.451 sec
|
||||
Running org.antlr.v4.test.runtime.csharp.TestCompositeParsers
|
||||
dir /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864
|
||||
antlr reports warnings from [-visitor, -Dlanguage=CSharp, -o, /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864, -lib, /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864, -encoding, UTF-8, /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864/M.g4]
|
||||
...
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Reactor Summary:
|
||||
[INFO]
|
||||
[INFO] ANTLR 4 ............................................ SUCCESS [ 0.445 s]
|
||||
[INFO] ANTLR 4 Runtime .................................... SUCCESS [ 3.392 s]
|
||||
[INFO] ANTLR 4 Tool ....................................... SUCCESS [ 1.373 s]
|
||||
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 1.519 s]
|
||||
[INFO] ANTLR 4 Runtime Test Annotations ................... SUCCESS [ 0.086 s]
|
||||
[INFO] ANTLR 4 Runtime Test Processors .................... SUCCESS [ 0.014 s]
|
||||
[INFO] ANTLR 4 Runtime Tests (2nd generation) ............. SUCCESS [06:39 min]
|
||||
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 6.922 s]
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] BUILD SUCCESS
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Total time: 06:53 min
|
||||
[INFO] Finished at: 2016-11-16T15:36:56-08:00
|
||||
[INFO] Final Memory: 44M/458M
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
```
|
||||
|
||||
Note: That is actually result of running the much faster:
|
||||
|
||||
```bash
|
||||
mvn -Dparallel=methods -DthreadCount=4 install
|
||||
```
|
||||
|
||||
## Running test subsets
|
||||
|
||||
*From the `runtime-testsuite` dir*
|
||||
|
||||
### Run one test group across targets
|
||||
|
||||
```bash
|
||||
$ cd runtime-testsuite
|
||||
$ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
|
||||
$ mvn -Dtest=TestParserExec test
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.cpp.TestParserExec
|
||||
...
|
||||
Tests run: 32, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 114.283 sec
|
||||
Running org.antlr.v4.test.runtime.csharp.TestParserExec
|
||||
...
|
||||
```
|
||||
|
||||
Or run all lexer related tests:
|
||||
|
||||
```
|
||||
$ cd runtime-testsuite
|
||||
$ mvn -Dtest=Test*Lexer* test
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.cpp.TestCompositeLexers
|
||||
...
|
||||
```
|
||||
|
||||
### Run all tests for a single target
|
||||
|
||||
```bash
|
||||
$ cd runtime-testsuite
|
||||
$ mvn -Dtest=java.* test
|
||||
...
|
||||
```
|
||||
|
||||
Or run all lexer related tests in Java target only:
|
||||
|
||||
```bash
|
||||
$ cd runtime-testsuite
|
||||
$ mvn -Dtest=java.*Lexer* test
|
||||
...
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.java.TestCompositeLexers
|
||||
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.277 sec
|
||||
Running org.antlr.v4.test.runtime.java.TestLexerErrors
|
||||
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.376 sec
|
||||
Running org.antlr.v4.test.runtime.java.TestLexerExec
|
||||
Tests run: 38, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.07 sec
|
||||
Running org.antlr.v4.test.runtime.java.TestSemPredEvalLexer
|
||||
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.255 sec
|
||||
|
||||
Results :
|
||||
|
||||
Tests run: 59, Failures: 0, Errors: 0, Skipped: 0
|
||||
```
|
||||
|
||||
## Testing in parallel
|
||||
|
||||
Use this to run tests in parallel:
|
||||
|
||||
```bash
|
||||
$ export MAVEN_OPTS="-Xmx1G"
|
||||
$ mvn -Dparallel=methods -DthreadCount=4 test
|
||||
...
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Concurrency config is parallel='methods', perCoreThreadCount=true, threadCount=4, useUnlimitedThreads=false
|
||||
...
|
||||
```
|
||||
|
||||
This can be combined with other `-D` above.
|
||||
|
||||
## Adding a runtime test
|
||||
|
||||
To add a new runtime test, first determine which [group of tests](https://github.com/antlr/antlr4/blob/master/runtime-testsuite/test/org/antlr/v4/test/runtime/descriptors) it belongs to. Then, add a new [RuntimeTestDescriptor](https://github.com/antlr/antlr4/blob/master/runtime-testsuite/test/org/antlr/v4/test/runtime/RuntimeTestDescriptor.java) implementation by subclassing one of:
|
|
@ -38,6 +38,7 @@ Receiving objects: 100% (59858/59858), 31.10 MiB | 819.00 KiB/s, done.
|
|||
Resolving deltas: 100% (31898/31898), done.
|
||||
Checking connectivity... done.
|
||||
$ cd antlr4
|
||||
$ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
|
||||
$ mvn -DskipTests install
|
||||
...
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
|
@ -67,65 +68,10 @@ We do `install` not `compile` as tool tests and such refer to modules that must
|
|||
To skip the tests (which require all the target languages be installed) and **install into local repository** `~/.m2/repository/org/antlr`, do this:
|
||||
|
||||
```bash
|
||||
$ export MAVEN_OPTS="-Xmx1G" # don't forget this on linux
|
||||
$ mvn install -DskipTests=true # make sure all artifacts are visible on this machine
|
||||
```
|
||||
|
||||
# Testing tool and targets
|
||||
|
||||
In order to perform the tests on all target languages, you need to have the following languages installed:
|
||||
|
||||
* `mono` (e.g., `brew install mono`)
|
||||
* `nodejs`
|
||||
* Python 2.7
|
||||
* Python 3.5
|
||||
* Go
|
||||
* Swift 3 (via XCode 8.x) tested currently only osx
|
||||
* clang (for C++ target)
|
||||
|
||||
To run the tests and **install into local repository** `~/.m2/repository/org/antlr`, do this:
|
||||
|
||||
```bash
|
||||
$ mvn install -DskipTests=true # make sure all artifacts are visible on this machine
|
||||
$ mvn install # now "do it with feeling"
|
||||
...
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.csharp.TestCompositeLexers
|
||||
dir /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068612451
|
||||
Starting build /usr/bin/xbuild /p:Configuration=Release /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068612451/Antlr4.Test.mono.csproj
|
||||
dir /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068615081
|
||||
Starting build /usr/bin/xbuild /p:Configuration=Release /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeLexers-1446068615081/Antlr4.Test.mono.csproj
|
||||
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.451 sec
|
||||
Running org.antlr.v4.test.runtime.csharp.TestCompositeParsers
|
||||
dir /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864
|
||||
antlr reports warnings from [-visitor, -Dlanguage=CSharp, -o, /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864, -lib, /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864, -encoding, UTF-8, /var/folders/s1/h3qgww1x0ks3pb30l8t1wgd80000gn/T/TestCompositeParsers-1446068615864/M.g4]
|
||||
...
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Reactor Summary:
|
||||
[INFO]
|
||||
[INFO] ANTLR 4 ............................................ SUCCESS [ 0.445 s]
|
||||
[INFO] ANTLR 4 Runtime .................................... SUCCESS [ 3.392 s]
|
||||
[INFO] ANTLR 4 Tool ....................................... SUCCESS [ 1.373 s]
|
||||
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 1.519 s]
|
||||
[INFO] ANTLR 4 Runtime Test Annotations ................... SUCCESS [ 0.086 s]
|
||||
[INFO] ANTLR 4 Runtime Test Processors .................... SUCCESS [ 0.014 s]
|
||||
[INFO] ANTLR 4 Runtime Tests (2nd generation) ............. SUCCESS [06:39 min]
|
||||
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 6.922 s]
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] BUILD SUCCESS
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Total time: 06:53 min
|
||||
[INFO] Finished at: 2016-11-16T15:36:56-08:00
|
||||
[INFO] Final Memory: 44M/458M
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
```
|
||||
|
||||
Note: That is actually result of running the much faster:
|
||||
|
||||
`mvn -Dparallel=methods -DthreadCount=4 install`
|
||||
|
||||
|
||||
You should see these jars (when building 4.6-SNAPSHOT):
|
||||
|
||||
```bash
|
||||
|
@ -143,87 +89,17 @@ antlr4/4.6-SNAPSHOT/antlr4-4.6-SNAPSHOT.jar
|
|||
|
||||
Note that ANTLR is written in itself, which is why maven downloads antlr4-4.5.jar for boostrapping 4.6-SNAPSHOT purposes.
|
||||
|
||||
## Running test subsets
|
||||
# Testing tool and targets
|
||||
|
||||
*From the `runtime-testsuite` dir*
|
||||
See [ANTLR project unit tests](antlr-project-testing.md).
|
||||
|
||||
### Run one test group across targets
|
||||
|
||||
```bash
|
||||
$ cd runtime-testsuite
|
||||
$ mvn -Dtest=TestParserExec test
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.cpp.TestParserExec
|
||||
...
|
||||
Tests run: 32, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 114.283 sec
|
||||
Running org.antlr.v4.test.runtime.csharp.TestParserExec
|
||||
...
|
||||
```
|
||||
|
||||
Or run all lexer related tests:
|
||||
|
||||
```
|
||||
$ mvn -Dtest=Test*Lexer* test
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.cpp.TestCompositeLexers
|
||||
...
|
||||
```
|
||||
|
||||
### Run all tests for a single target
|
||||
|
||||
```bash
|
||||
$ mvn -Dtest=java.* test
|
||||
...
|
||||
```
|
||||
|
||||
Or run all lexer related tests in Java target only:
|
||||
|
||||
```bash
|
||||
$ mvn -Dtest=java.*Lexer* test
|
||||
...
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Running org.antlr.v4.test.runtime.java.TestCompositeLexers
|
||||
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.277 sec
|
||||
Running org.antlr.v4.test.runtime.java.TestLexerErrors
|
||||
Tests run: 12, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.376 sec
|
||||
Running org.antlr.v4.test.runtime.java.TestLexerExec
|
||||
Tests run: 38, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.07 sec
|
||||
Running org.antlr.v4.test.runtime.java.TestSemPredEvalLexer
|
||||
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.255 sec
|
||||
|
||||
Results :
|
||||
|
||||
Tests run: 59, Failures: 0, Errors: 0, Skipped: 0
|
||||
```
|
||||
|
||||
## Testing in parallel
|
||||
|
||||
Use this to run tests in parallel:
|
||||
|
||||
```bash
|
||||
$ mvn -Dparallel=methods -DthreadCount=4 test
|
||||
...
|
||||
-------------------------------------------------------
|
||||
T E S T S
|
||||
-------------------------------------------------------
|
||||
Concurrency config is parallel='methods', perCoreThreadCount=true, threadCount=4, useUnlimitedThreads=false
|
||||
...
|
||||
```
|
||||
|
||||
This can be combined with other `-D` above.
|
||||
|
||||
## Building without testing
|
||||
# Building without testing
|
||||
|
||||
To build without running the tests (saves a lot of time), do this:
|
||||
|
||||
```bash
|
||||
mvn -DskipTests install
|
||||
$ mvn -DskipTests install
|
||||
```
|
||||
|
||||
## Building ANTLR in Intellij IDE
|
||||
|
|
|
@ -20,11 +20,13 @@ You will see that there are a whole bunch of files generated by this call. If vi
|
|||
|
||||
## Where can I get the runtime?
|
||||
|
||||
Once you've generated the lexer and/or parser code, you need to download or build the runtime. Prebuilt C++ runtime binaries for Windows (VS 2013 runtime), OSX and iOS are available on the ANTLR web site:
|
||||
Once you've generated the lexer and/or parser code, you need to download or build the runtime. Prebuilt C++ runtime binaries for Windows (Visual Studio 2013/2015), OSX/macOS and iOS are available on the ANTLR web site:
|
||||
|
||||
* http://www.antlr.org
|
||||
|
||||
Use CMake to build a Linux library (works also on OSX, however not for the iOS library). Building your own library on OSX or Windows is trivial, however. Just open the VS or XCode project, select target + arch and build it. Should work out of the box without any additional dependency.
|
||||
Use CMake to build a Linux library (works also on OSX, however not for the iOS library).
|
||||
|
||||
Instead of downloading a prebuilt binary you can also easily build your own library on OSX or Windows. Just use the provided projects for XCode or Visual Studio and build it. Should work out of the box without any additional dependency.
|
||||
|
||||
|
||||
## How do I run the generated lexer and/or parser?
|
||||
|
@ -76,6 +78,30 @@ This example assumes your grammar contains a parser rule named `key` for which t
|
|||
|
||||
There are a couple of things that only the C++ ANTLR target has to deal with. They are described here.
|
||||
|
||||
### Build Aspects
|
||||
The code generation (by running the ANTLR4 jar) allows to specify 2 values you might find useful for better integration of the generated files into your application (both are optional):
|
||||
|
||||
* A **namespace**: use the **`-package`** parameter to specify the namespace you want.
|
||||
* An **export macro**: especially in VC++ extra work is required to export your classes from a DLL. This is usually accomplished by a macro that has different values depending on whether you are creating the DLL or import it. The ANTLR4 runtime itself also uses one for its classes:
|
||||
|
||||
```c++
|
||||
#ifdef ANTLR4CPP_EXPORTS
|
||||
#define ANTLR4CPP_PUBLIC __declspec(dllexport)
|
||||
#else
|
||||
#ifdef ANTLR4CPP_STATIC
|
||||
#define ANTLR4CPP_PUBLIC
|
||||
#else
|
||||
#define ANTLR4CPP_PUBLIC __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
```
|
||||
Just like the `ANTLR4CPP_PUBLIC` macro here you can specify your own one for the generated classes using the **`-DexportMacro=...`** command-line parameter or
|
||||
grammar option `options {exportMacro='...';}` in your grammar file.
|
||||
|
||||
In order to create a static lib in Visual Studio define the `ANTLR4CPP_STATIC` macro in addition to the project settings that must be set for a static library (if you compile the runtime yourself).
|
||||
|
||||
For gcc and clang it is possible to use the `-fvisibility=hidden` setting to hide all symbols except those that are made default-visible (which has been defined for all public classes in the runtime).
|
||||
|
||||
### Memory Management
|
||||
Since C++ has no built-in memory management we need to take extra care. For that we rely mostly on smart pointers, which however might cause time penalties or memory side effects (like cyclic references) if not used with care. Currently however the memory household looks very stable. Generally, when you see a raw pointer in code consider this as being managed elsewehere. You should never try to manage such a pointer (delete, assign to smart pointer etc.).
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
# C♯
|
||||
|
||||
See also [Sam Harwell's Alternative C# target](https://github.com/tunnelvisionlabs/antlr4cs)
|
||||
|
||||
### Which frameworks are supported?
|
||||
## Which frameworks are supported?
|
||||
|
||||
The C# runtime is CLS compliant, and only requires a corresponding 3.5 .Net framework.
|
||||
|
||||
|
@ -13,19 +11,15 @@ In practice, the runtime has been extensively tested against:
|
|||
|
||||
No issue was found, so you should find that the runtime works pretty much against any recent .Net framework.
|
||||
|
||||
### How do I get started?
|
||||
## How do I get started?
|
||||
|
||||
You will find full instructions on the Git web page for ANTLR C# runtime.
|
||||
You will find full instructions on the [Git repo page for ANTLR C# runtime](https://github.com/antlr/antlr4/tree/master/runtime/CSharp).
|
||||
|
||||
### How do I use the runtime from my project?
|
||||
## How do I use the runtime from my project?
|
||||
|
||||
(i.e., How do I run the generated lexer and/or parser?)
|
||||
|
||||
Let's suppose that your grammar is named, as above, "MyGrammar".
|
||||
|
||||
Let's suppose this parser comprises a rule named "StartRule"
|
||||
|
||||
The tool will have generated for you the following files:
|
||||
Let's suppose that your grammar is named `MyGrammar`. The tool will generate for you the following files:
|
||||
|
||||
* MyGrammarLexer.cs
|
||||
* MyGrammarParser.cs
|
||||
|
@ -34,7 +28,7 @@ The tool will have generated for you the following files:
|
|||
* MyGrammarVisitor.js (if you have activated the -visitor option)
|
||||
* MyGrammarBaseVisitor.js (if you have activated the -visitor option)
|
||||
|
||||
Now a fully functioning code might look like the following:
|
||||
Now a fully functioning code might look like the following for start rule `StartRule`:
|
||||
|
||||
```
|
||||
using Antlr4.Runtime;
|
||||
|
@ -58,7 +52,7 @@ This program will work. But it won't be useful unless you do one of the followin
|
|||
|
||||
(please note that production code is target specific, so you can't have multi target grammars that include production code)
|
||||
|
||||
### How do I create and run a custom listener?
|
||||
## How do I create and run a custom listener?
|
||||
|
||||
Let's suppose your MyGrammar grammar comprises 2 rules: "key" and "value".
|
||||
|
||||
|
@ -96,4 +90,5 @@ ParseTreeWalker.DEFAULT.walk(printer, tree);
|
|||
|
||||
Further information can be found from The Definitive ANTLR Reference book.
|
||||
|
||||
The C# implementation of ANTLR is as close as possible to the Java one, so you shouldn't find it difficult to adapt the examples for C#.
|
||||
The C# implementation of ANTLR is as close as possible to the Java one, so you shouldn't find it difficult to adapt the examples for C#. See also [Sam Harwell's alternative C# target](https://github.com/tunnelvisionlabs/antlr4cs)
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
Binary file not shown.
After Width: | Height: | Size: 122 KiB |
Binary file not shown.
After Width: | Height: | Size: 439 KiB |
Binary file not shown.
After Width: | Height: | Size: 85 KiB |
|
@ -63,6 +63,6 @@ This documentation is a reference and summarizes grammar syntax and the key sema
|
|||
|
||||
* [Cutting an ANTLR Release](releasing-antlr.md)
|
||||
|
||||
* [Adding ANTLR unit tests](adding-tests.md)
|
||||
* [ANTLR project unit tests](antlr-project-testing.md)
|
||||
|
||||
* [Creating an ANTLR Language Target](creating-a-language-target.md)
|
||||
|
|
|
@ -15,7 +15,7 @@ The tests were conducted using Selenium. No issue was found, so you should find
|
|||
|
||||
## Is NodeJS supported?
|
||||
|
||||
The runtime has also been extensively tested against Node.js 0.10.33. No issue was found.
|
||||
The runtime has also been extensively tested against Node.js 0.12.7. No issue was found.
|
||||
|
||||
## How to create a JavaScript lexer or parser?
|
||||
|
||||
|
@ -31,7 +31,9 @@ For a full list of antlr4 tool options, please visit the [tool documentation pag
|
|||
|
||||
Once you've generated the lexer and/or parser code, you need to download the runtime.
|
||||
|
||||
The JavaScript runtime is available from the ANTLR web site [download section](http://www.antlr.org/download/index.html). The runtime is provided in the form of source code, so no additional installation is required.
|
||||
The JavaScript runtime is [available from npm](https://www.npmjs.com/package/antlr4).
|
||||
|
||||
If you can't use npm, the JavaScript runtime is also available from the ANTLR web site [download section](http://www.antlr.org/download/index.html). The runtime is provided in the form of source code, so no additional installation is required.
|
||||
|
||||
We will not document here how to refer to the runtime from your project, since this would differ a lot depending on your project type and IDE.
|
||||
|
||||
|
@ -47,11 +49,28 @@ However, it would be a bit of a problem when it comes to get it into a browser.
|
|||
<script src='lib/myscript.js'>
|
||||
```
|
||||
|
||||
In order to avoid having to do this, and also to have the exact same code for browsers and Node.js, we rely on a script which provides the equivalent of the Node.js 'require' function.
|
||||
To avoid having doing this, the preferred approach is to bundle antlr4 with your parser code, using webpack.
|
||||
|
||||
This script is provided by Torben Haase, and is NOT part of ANTLR JavaScript runtime, although the runtime heavily relies on it. Please note that syntax for 'require' in NodeJS is different from the one implemented by RequireJS and similar frameworks.
|
||||
You can get [information on webpack here](https://webpack.github.io).
|
||||
|
||||
So in short, assuming you have at the root of your web site, both the 'antlr4' directory and a 'lib' directory with 'require.js' inside it, all you need to put in your HTML header is the following:
|
||||
The steps to create your parsing code are the following:
|
||||
- generate your lexer, parser, listener and visitor using the antlr tool
|
||||
- write your parse tree handling code by providig your custom listener or visitor, and associated code, using 'require' to load antlr.
|
||||
- create an index.js file with the entry point to your parsing code (or several if required).
|
||||
- test your parsing logic thoroughly using node.js
|
||||
|
||||
You are now ready to bundle your parsing code as follows:
|
||||
- following webpack specs, create a webpack.config file
|
||||
- in the webpack.config file, exclude node.js only modules using: node: { module: "empty", net: "empty", fs: "empty" }
|
||||
- from the cmd line, nag-vigate to the directory containing webpack.config and type: webpack
|
||||
|
||||
This will produce a single js file containing all your parsing code. Easy to include in your web pages!
|
||||
|
||||
If you can't use webpack, you can use the lib/require.js script which implements the Node.js 'require' function in brwsers.
|
||||
|
||||
This script is provided by Torben Haase, and is NOT part of ANTLR JavaScript runtime.
|
||||
|
||||
Assuming you have, at the root of your web site, both the 'antlr4' directory and a 'lib' directory with 'require.js' inside it, all you need to put in your HTML header is the following:
|
||||
|
||||
```xml
|
||||
<script src='lib/require.js'>
|
||||
|
@ -62,16 +81,6 @@ So in short, assuming you have at the root of your web site, both the 'antlr4' d
|
|||
|
||||
This will load the runtime asynchronously.
|
||||
|
||||
## How do I get the runtime in Node.js?
|
||||
|
||||
Right now, there is no npm package available, so you need to register a link instead. This can be done by running the following command from the antlr4 directory:
|
||||
|
||||
```bash
|
||||
$ npm link antlr4
|
||||
```
|
||||
|
||||
This will install antlr4 using the package.json descriptor that comes with the script.
|
||||
|
||||
## How do I run the generated lexer and/or parser?
|
||||
|
||||
Let's suppose that your grammar is named, as above, "MyGrammar". Let's suppose this parser comprises a rule named "StartRule". The tool will have generated for you the following files:
|
||||
|
|
|
@ -4,12 +4,22 @@
|
|||
|
||||
Create a pre-release or full release at github; [Example 4.5-rc-1](https://github.com/antlr/antlr4/releases/tag/4.5-rc-1).
|
||||
|
||||
### Delete existing release tag
|
||||
|
||||
Wack any existing tag as mvn will create one and it fails if already there.
|
||||
|
||||
```
|
||||
$ git tag -d 4.5.2
|
||||
$ git push origin :refs/tags/4.5.2
|
||||
$ git push upstream :refs/tags/4.5.2
|
||||
$ git tag -d 4.6
|
||||
$ git push origin :refs/tags/4.6
|
||||
$ git push upstream :refs/tags/4.6
|
||||
```
|
||||
|
||||
### Create release candidate tag
|
||||
|
||||
```bash
|
||||
$ git tag -a 4.6-rc1 -m 'heading towards 4.6'
|
||||
$ git push origin 4.6-rc1
|
||||
$ git push upstream 4.6-rc1
|
||||
```
|
||||
|
||||
## Bump version
|
||||
|
@ -22,20 +32,30 @@ Edit the repository looking for 4.5 or whatever and update it. Bump version in t
|
|||
* runtime/Python3/setup.py
|
||||
* runtime/Python3/src/antlr4/Recognizer.py
|
||||
* runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Properties/AssemblyInfo.cs
|
||||
* runtime/CSharp/build/version.ps1
|
||||
* runtime/CSharp/runtime/CSharp/Package.nuspec
|
||||
* runtime/JavaScript/src/antlr4/package.json
|
||||
* runtime/JavaScript/src/antlr4/Recognizer.js
|
||||
* runtime/Cpp/VERSION
|
||||
* runtime/Cpp/runtime/src/RuntimeMetaData.cpp
|
||||
* runtime/Cpp/cmake/ExternalAntlr4Cpp.cmake
|
||||
* runtime/Cpp/demo/generate.cmd
|
||||
* runtime/Go/antlr/recognizer.go
|
||||
* runtime/Swift/Antlr4/org/antlr/v4/runtime/RuntimeMetaData.swift
|
||||
* tool/src/org/antlr/v4/codegen/target/GoTarget.java
|
||||
* tool/src/org/antlr/v4/codegen/target/CppTarget.java
|
||||
* tool/src/org/antlr/v4/codegen/target/CSharpTarget.java
|
||||
* tool/src/org/antlr/v4/codegen/target/JavaScriptTarget.java
|
||||
* tool/src/org/antlr/v4/codegen/target/Python2Target.java
|
||||
* tool/src/org/antlr/v4/codegen/target/Python3Target.java
|
||||
* runtime/Cpp/VERSION
|
||||
* runtime/Cpp/RuntimeMetaData.cpp
|
||||
* tool/src/org/antlr/v4/codegen/target/SwiftTarget.java
|
||||
* tool/src/org/antlr/v4/codegen/Target.java
|
||||
* tool/resources/org/antlr/v4/tool/templates/codegen/Swift/Swift.stg
|
||||
|
||||
Here is a simple script to display any line from the critical files with, say, `4.5` in it:
|
||||
|
||||
```bash
|
||||
find /tmp/antlr4 -type f -exec grep -l '4\.5' {} \;
|
||||
find tool runtime -type f -exec grep -l '4\.6' {} \;
|
||||
```
|
||||
|
||||
Commit to repository.
|
||||
|
@ -85,6 +105,47 @@ Here is the file template
|
|||
</settings>
|
||||
```
|
||||
|
||||
## Maven deploy snapshot
|
||||
|
||||
The goal is to get a snapshot, such as `4.6-SNAPSHOT`, to the staging server: [antlr4 tool](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4) and [antlr4 java runtime](https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-runtime).
|
||||
|
||||
Do this:
|
||||
|
||||
```bash
|
||||
$ mvn deploy -DskipTests
|
||||
...
|
||||
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ antlr4-tool-testsuite ---
|
||||
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.6-SNAPSHOT/maven-metadata.xml
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.6-SNAPSHOT/antlr4-tool-testsuite-4.6-20161211.173752-1.jar
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.6-SNAPSHOT/antlr4-tool-testsuite-4.6-20161211.173752-1.jar (3 KB at 3.4 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.6-SNAPSHOT/antlr4-tool-testsuite-4.6-20161211.173752-1.pom
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.6-SNAPSHOT/antlr4-tool-testsuite-4.6-20161211.173752-1.pom (3 KB at 6.5 KB/sec)
|
||||
Downloading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml
|
||||
Downloaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml (371 B at 1.4 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.6-SNAPSHOT/maven-metadata.xml
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/4.6-SNAPSHOT/maven-metadata.xml (774 B at 1.8 KB/sec)
|
||||
Uploading: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml
|
||||
Uploaded: https://oss.sonatype.org/content/repositories/snapshots/org/antlr/antlr4-tool-testsuite/maven-metadata.xml (388 B at 0.9 KB/sec)
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Reactor Summary:
|
||||
[INFO]
|
||||
[INFO] ANTLR 4 ............................................ SUCCESS [ 4.073 s]
|
||||
[INFO] ANTLR 4 Runtime .................................... SUCCESS [ 13.828 s]
|
||||
[INFO] ANTLR 4 Tool ....................................... SUCCESS [ 14.032 s]
|
||||
[INFO] ANTLR 4 Maven plugin ............................... SUCCESS [ 6.547 s]
|
||||
[INFO] ANTLR 4 Runtime Test Annotations ................... SUCCESS [ 2.519 s]
|
||||
[INFO] ANTLR 4 Runtime Test Processors .................... SUCCESS [ 2.385 s]
|
||||
[INFO] ANTLR 4 Runtime Tests (2nd generation) ............. SUCCESS [ 15.276 s]
|
||||
[INFO] ANTLR 4 Tool Tests ................................. SUCCESS [ 2.233 s]
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] BUILD SUCCESS
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Total time: 01:01 min
|
||||
[INFO] Finished at: 2016-12-11T09:37:54-08:00
|
||||
[INFO] Final Memory: 44M/470M
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
```
|
||||
|
||||
## Maven release
|
||||
|
||||
The maven deploy lifecycle phased deploys the artifacts and the poms for the ANTLR project to the [sonatype remote staging server](https://oss.sonatype.org/content/repositories/snapshots/).
|
||||
|
@ -103,24 +164,24 @@ It will start out by asking you the version number:
|
|||
|
||||
```
|
||||
...
|
||||
What is the release version for "ANTLR 4"? (org.antlr:antlr4-master) 4.5.2: : 4.5.2
|
||||
What is the release version for "ANTLR 4 Runtime"? (org.antlr:antlr4-runtime) 4.5.2: :
|
||||
What is the release version for "ANTLR 4 Tool"? (org.antlr:antlr4) 4.5.2: :
|
||||
What is the release version for "ANTLR 4 Maven plugin"? (org.antlr:antlr4-maven-plugin) 4.5.2: :
|
||||
What is the release version for "ANTLR 4 Runtime Test Generator"? (org.antlr:antlr4-runtime-testsuite) 4.5.2: :
|
||||
What is the release version for "ANTLR 4 Tool Tests"? (org.antlr:antlr4-tool-testsuite) 4.5.2: :
|
||||
What is SCM release tag or label for "ANTLR 4"? (org.antlr:antlr4-master) antlr4-master-4.5.2: : 4.5.2
|
||||
What is the new development version for "ANTLR 4"? (org.antlr:antlr4-master) 4.5.3-SNAPSHOT:
|
||||
What is the release version for "ANTLR 4"? (org.antlr:antlr4-master) 4.6: : 4.6
|
||||
What is the release version for "ANTLR 4 Runtime"? (org.antlr:antlr4-runtime) 4.6: :
|
||||
What is the release version for "ANTLR 4 Tool"? (org.antlr:antlr4) 4.6: :
|
||||
What is the release version for "ANTLR 4 Maven plugin"? (org.antlr:antlr4-maven-plugin) 4.6: :
|
||||
What is the release version for "ANTLR 4 Runtime Test Generator"? (org.antlr:antlr4-runtime-testsuite) 4.6: :
|
||||
What is the release version for "ANTLR 4 Tool Tests"? (org.antlr:antlr4-tool-testsuite) 4.6: :
|
||||
What is SCM release tag or label for "ANTLR 4"? (org.antlr:antlr4-master) antlr4-master-4.6: : 4.6
|
||||
What is the new development version for "ANTLR 4"? (org.antlr:antlr4-master) 4.6.1-SNAPSHOT:
|
||||
...
|
||||
```
|
||||
|
||||
Maven will go through your pom.xml files to update versions from 4.5.2-SNAPSHOT to 4.5.2 for release and then to 4.5.3-SNAPSHOT after release, which is done with:
|
||||
Maven will go through your pom.xml files to update versions from 4.6-SNAPSHOT to 4.6 for release and then to 4.6.1-SNAPSHOT after release, which is done with:
|
||||
|
||||
```bash
|
||||
mvn release:perform -Darguments="-DskipTests"
|
||||
```
|
||||
|
||||
Maven will use git to push pom.xml changes. (big smile)
|
||||
Maven will use git to push pom.xml changes.
|
||||
|
||||
Now, go here:
|
||||
|
||||
|
@ -133,11 +194,11 @@ and on the left click "Staging Repositories". You click the staging repo and clo
|
|||
Copy the jars to antlr.org site and update download/index.html
|
||||
|
||||
```bash
|
||||
cp ~/.m2/repository/org/antlr/antlr4-runtime/4.5.2/antlr4-runtime-4.5.2.jar ~/antlr/sites/website-antlr4/download/antlr-runtime-4.5.2.jar
|
||||
cp ~/.m2/repository/org/antlr/antlr4/4.5.2/antlr4-4.5.2.jar ~/antlr/sites/website-antlr4/download/antlr-4.5.2-complete.jar
|
||||
cp ~/.m2/repository/org/antlr/antlr4-runtime/4.6/antlr4-runtime-4.6.jar ~/antlr/sites/website-antlr4/download/antlr-runtime-4.6.jar
|
||||
cp ~/.m2/repository/org/antlr/antlr4/4.6/antlr4-4.6-complete.jar ~/antlr/sites/website-antlr4/download/antlr-4.6-complete.jar
|
||||
cd ~/antlr/sites/website-antlr4/download
|
||||
git add antlr-4.5.2-complete.jar
|
||||
git add antlr-runtime-4.5.2.jar
|
||||
git add antlr-4.6-complete.jar
|
||||
git add antlr-runtime-4.6.jar
|
||||
```
|
||||
|
||||
Update on site:
|
||||
|
@ -149,7 +210,7 @@ Update on site:
|
|||
* scripts/topnav.js
|
||||
|
||||
```
|
||||
git commit -a -m 'add 4.5.2 jars'
|
||||
git commit -a -m 'add 4.6 jars'
|
||||
git push origin gh-pages
|
||||
```
|
||||
|
||||
|
@ -159,8 +220,8 @@ git push origin gh-pages
|
|||
|
||||
```bash
|
||||
cd runtime/JavaScript/src
|
||||
zip -r /tmp/antlr-javascript-runtime-4.5.2.zip antlr4
|
||||
cp /tmp/antlr-javascript-runtime-4.5.2.zip ~/antlr/sites/website-antlr4/download
|
||||
zip -r /tmp/antlr-javascript-runtime-4.6.zip antlr4
|
||||
cp /tmp/antlr-javascript-runtime-4.6.zip ~/antlr/sites/website-antlr4/download
|
||||
# git add, commit, push
|
||||
```
|
||||
|
||||
|
@ -168,7 +229,7 @@ Move target to website
|
|||
|
||||
```bash
|
||||
pushd ~/antlr/sites/website-antlr4/download
|
||||
git add antlr-javascript-runtime-4.5.2.zip
|
||||
git add antlr-javascript-runtime-4.6.zip
|
||||
git commit -a -m 'update JS runtime'
|
||||
git push origin gh-pages
|
||||
popd
|
||||
|
@ -176,6 +237,70 @@ popd
|
|||
|
||||
### CSharp
|
||||
|
||||
*Publishing to Nuget from Linux/MacOSX*
|
||||
|
||||
**Getting ready to run Nuget**
|
||||
|
||||
Of course you need Mono and `nuget` to be installed. On mac:
|
||||
|
||||
```bash
|
||||
brew install mono
|
||||
brew install nuget
|
||||
```
|
||||
|
||||
Or, you can [download nuget.exe](https://dist.nuget.org/win-x86-commandline/latest/nuget.exe).
|
||||
|
||||
From the shell on mac, you can check all is ok by typing
|
||||
|
||||
```bash
|
||||
nuget
|
||||
```
|
||||
|
||||
This should display the nuget help.
|
||||
|
||||
**Creating the assembly**
|
||||
|
||||
```bash
|
||||
$ cd runtime/CSharp/runtime/CSharp/Antlr4.Runtime
|
||||
$ xbuild /p:Configuration=Release Antlr4.Runtime.mono.csproj
|
||||
...
|
||||
Copying file from '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.Standard.dll' to '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/lib/Release/Antlr4.Runtime.Standard.dll'
|
||||
Done building project "/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Antlr4.Runtime.mono.csproj".
|
||||
```
|
||||
|
||||
Alternately, you may want to build ANTLR using Xamarin Studio Community (free).
|
||||
|
||||
**Packaging for NuGet**
|
||||
|
||||
```bash
|
||||
cd runtime/CSharp/runtime/CSharp
|
||||
```
|
||||
|
||||
which is where the `Package.nuspec` file resides.
|
||||
|
||||
Type the following command:
|
||||
|
||||
```bash
|
||||
$ nuget pack Package.nuspec
|
||||
Attempting to build package from 'Package.nuspec'.
|
||||
Successfully created package '/Users/parrt/antlr/code/antlr4/runtime/CSharp/runtime/CSharp/Antlr4.Runtime.Standard.4.6.0.nupkg'.
|
||||
```
|
||||
|
||||
This should display: Successfully created package *<package-path>*
|
||||
|
||||
**Publishing to NuGet**
|
||||
|
||||
You need to be a NuGet owner for "ANTLR 4 Standard Runtime"
|
||||
As a registered NuGet user, you can then manually upload the package spec here (`runtime/CSharp/runtime/CSharp/Package.nuspec`): [https://www.nuget.org/packages/manage/upload](https://www.nuget.org/packages/manage/upload)
|
||||
|
||||
Alternately, you can publish from the cmd line. You need to get your NuGet key from [https://www.nuget.org/account#](https://www.nuget.org/account#) and then from the cmd line, you can then type:
|
||||
|
||||
```bash
|
||||
nuget push Antlr4.Runtime.Standard.<version>.nupkg <your-key> -Source https://www.nuget.org/api/v2/package
|
||||
```
|
||||
|
||||
**Creating DLLs**
|
||||
|
||||
```bash
|
||||
cd ~/antlr/code/antlr4/runtime/CSharp/runtime/CSharp
|
||||
# kill previous ones manually as "xbuild /t:Clean" didn't seem to do it
|
||||
|
@ -184,15 +309,15 @@ rm Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.dll
|
|||
# build
|
||||
xbuild /p:Configuration=Release Antlr4.Runtime/Antlr4.Runtime.mono.csproj
|
||||
# zip it up to get a version number on zip filename
|
||||
zip --junk-paths /tmp/antlr-csharp-runtime-4.5.2.zip Antlr4.Runtime/bin/net35/Release/Antlr4.Runtime.dll
|
||||
cp /tmp/antlr-csharp-runtime-4.5.2.zip ~/antlr/sites/website-antlr4/download
|
||||
zip --junk-paths /tmp/antlr-csharp-runtime-4.6.zip Antlr4.Runtime/obj/net20/Release/Antlr4.Runtime.Standard.dll
|
||||
cp /tmp/antlr-csharp-runtime-4.6.zip ~/antlr/sites/website-antlr4/download
|
||||
```
|
||||
|
||||
Move target to website
|
||||
|
||||
```bash
|
||||
pushd ~/antlr/sites/website-antlr4/download
|
||||
git add antlr-csharp-runtime-4.5.2.zip
|
||||
git add antlr-csharp-runtime-4.6.zip
|
||||
git commit -a -m 'update C# runtime'
|
||||
git push origin gh-pages
|
||||
popd
|
||||
|
@ -241,7 +366,7 @@ python setup.py register -r pypi
|
|||
python setup.py sdist bdist_wininst upload -r pypi
|
||||
```
|
||||
|
||||
Add links to the artifacts from download.html
|
||||
There are links to the artifacts in [download.html](http://www.antlr.org/download.html) already.
|
||||
|
||||
### C++
|
||||
|
||||
|
@ -261,6 +386,7 @@ On a Mac (with XCode 7+ installed):
|
|||
```bash
|
||||
cd runtime/Cpp
|
||||
./deploy-macos.sh
|
||||
cp antlr4-cpp-runtime-macos.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.6-macos.zip
|
||||
```
|
||||
|
||||
On any Mac or Linux machine:
|
||||
|
@ -268,6 +394,7 @@ On any Mac or Linux machine:
|
|||
```bash
|
||||
cd runtime/Cpp
|
||||
./deploy-source.sh
|
||||
cp antlr4-cpp-runtime-source.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.6-source.zip
|
||||
```
|
||||
|
||||
On a Windows machine the build scripts checks if VS 2013 and/or VS 2015 are installed and builds binaries for each, if found. This script requires 7z to be installed (http://7-zip.org).
|
||||
|
@ -275,15 +402,17 @@ On a Windows machine the build scripts checks if VS 2013 and/or VS 2015 are inst
|
|||
```bash
|
||||
cd runtime/Cpp
|
||||
deploy-windows.cmd
|
||||
cp antlr4-cpp-runtime-vs2015.zip ~/antlr/sites/website-antlr4/download/antlr4-cpp-runtime-4.6-vs2015.zip
|
||||
```
|
||||
|
||||
Move target to website (**_rename to a specific ANTLR version first if needed_**):
|
||||
|
||||
```bash
|
||||
pushd ~/antlr/sites/website-antlr4/download
|
||||
git add antlr4cpp-runtime-macos.zip
|
||||
git add antlr4cpp-runtime-windows.zip
|
||||
git add antlr4cpp-runtime-source.zip
|
||||
# vi index.html
|
||||
git add antlr4cpp-runtime-4.6-macos.zip
|
||||
git add antlr4cpp-runtime-4.6-windows.zip
|
||||
git add antlr4cpp-runtime-4.6-source.zip
|
||||
git commit -a -m 'update C++ runtime'
|
||||
git push origin gh-pages
|
||||
popd
|
||||
|
@ -291,7 +420,7 @@ popd
|
|||
|
||||
## Update javadoc for runtime and tool
|
||||
|
||||
First gen javadoc:
|
||||
First, gen javadoc:
|
||||
|
||||
```bash
|
||||
$ cd antlr4
|
||||
|
@ -305,9 +434,9 @@ cd ~/antlr/sites/website-antlr4/api
|
|||
git checkout gh-pages
|
||||
git pull origin gh-pages
|
||||
cd Java
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4-runtime/4.5.2/antlr4-runtime-4.5.2-javadoc.jar
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4-runtime/4.6/antlr4-runtime-4.6-javadoc.jar
|
||||
cd ../JavaTool
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4/4.5.2/antlr4-4.5.2-javadoc.jar
|
||||
jar xvf ~/.m2/repository/org/antlr/antlr4/4.6/antlr4-4.6-javadoc.jar
|
||||
git commit -a -m 'freshen api doc'
|
||||
git push origin gh-pages
|
||||
```
|
||||
|
|
|
@ -29,7 +29,7 @@ The underlying process of running the tests is quite a complicated setup to cate
|
|||
|
||||
## Generating JUnit Tests
|
||||
|
||||
The test specification part makes heavy use of the StringTemplate engine to allow defining target language agnostic tests. For that all tests are described in template (`stg`) files. You can find them in the [templates](../runtime-testsuite/resources/org/antlr/v4/test/runtime/templates) subfolder of the runtime tests folder. Read more about the folder structure in the [adding-tests.md](adding-tests.md) file. As lined out there you have to run
|
||||
The test specification part makes heavy use of the StringTemplate engine to allow defining target language agnostic tests. For that all tests are described in template (`stg`) files. You can find them in the [templates](../runtime-testsuite/resources/org/antlr/v4/test/runtime/templates) subfolder of the runtime tests folder. Read more about the folder structure in the [antlr-project-testing.md](antlr-project-testing.md) file. As lined out there you have to run
|
||||
|
||||
```bash
|
||||
$ mvn -Pgen generate-test-sources
|
||||
|
|
|
@ -1,47 +1,99 @@
|
|||
# ANTLR4 Language Target, Runtime for Swift
|
||||
|
||||
### Usage
|
||||
## Install ANTLR4
|
||||
|
||||
#### 1. Install ANTLR4
|
||||
Make sure you have the ANTLR
|
||||
installed.[The getting started guide](getting-started.md) should get
|
||||
you started.
|
||||
|
||||
[The getting started guide](getting-started.md) should get you started.
|
||||
|
||||
#### 2. create a Swift lexer or parser
|
||||
This is pretty much the same as creating a Java lexer or parser, except you need to specify the language target, for example:
|
||||
## Create a Swift lexer or parser
|
||||
This is pretty much the same as creating a Java lexer or parser,
|
||||
except you need to specify the language target, for example:
|
||||
|
||||
```
|
||||
$ antlr4 -Dlanguage=Swift MyGrammar.g4
|
||||
```
|
||||
For a full list of antlr4 tool options, please visit the [tool documentation page](tool-options.md).
|
||||
For a full list of antlr4 tool options, please visit the
|
||||
[tool documentation page](tool-options.md).
|
||||
|
||||
#### 3. Get the Swift ANTLR runtime
|
||||
You will find Swift runtime (framework project) in
|
||||
## Build your Swift project with ANTLR runtime
|
||||
|
||||
```
|
||||
antlr4/runtime/Swift
|
||||
```
|
||||
The following instructions are assuming Xcode as the IDE:
|
||||
|
||||
#### 4. Example playground
|
||||
* __Add parser/lexer to project__. Make sure the parsers/lexers
|
||||
generated in __step 2__ are added to the project. To do this, you can
|
||||
drag the generated files from Finder to the Xcode IDE. Remember to
|
||||
check __Copy items if needed__ to make sure the files are actually
|
||||
moved into the project folder instead of symbolic links (see the
|
||||
screenshot below). After moving you will be able to see your files in
|
||||
the project navigator. But when you open one of the files, you will
|
||||
see Xcode complaining the module "Antlr4" could not be found at the
|
||||
import statement. This is expected, since we still need the ANTLR
|
||||
Swift runtime for those missing symbols.
|
||||
|
||||
<img src=images/dragfile.png width="500">
|
||||
|
||||
* __Download ANTLR runtime__. Due to unstable ABI of Swift language,
|
||||
there will not be a single "library" for the Swift ANTLR runtime for
|
||||
now. To get Swift ANTLR runtime, clone the ANTLR repository. Open it
|
||||
in finder. From the root directory of the repo, go to runtime/Swift
|
||||
folder. You will see the Xcode project manifest file:
|
||||
__Antlr4.xcodeproj__.
|
||||
|
||||
* __Import ANTLR Swift runtime into project__. Drag Antlr4.xcodeproj
|
||||
into your project, after this is done, your Xcode project navigator
|
||||
will be something like the screenshot below. In this case, your own
|
||||
project is "Smalltalk", and you will be able to see the
|
||||
Antlr4.xcodeproj shown as a contained project. The error message will
|
||||
still be there, that's because we still need to tell Xcode how to find
|
||||
the runtime.
|
||||
|
||||
<img src=images/xcodenav.png width="300">
|
||||
|
||||
* __Build ANTLR runtime__. By expanding the "Products" folder in the
|
||||
inner project (Antlr4.xcodeproj), you will see two Antlr4.framework
|
||||
files. ".framework" file is the swift version of ".jar", ".a" as in
|
||||
JAVA, C/C++ Initially those two files should be red, that's because
|
||||
they are not built. To build, click the "target selection" button
|
||||
right next to your Xcode run button. And in the drop down select the
|
||||
target you want to build. And you will see the two Antlr4.framework
|
||||
files are for iOS and OSX, as shown below. After target selection,
|
||||
press "CMD+B", and Xcode will build the framework for you. Then you
|
||||
will see one of the frameworks become black.
|
||||
|
||||
<img src=images/targetselection.png width="500">
|
||||
|
||||
* __Add dependencies__. Simply adding ANTLR Swift runtime and build
|
||||
the artifact is not enough. You still need to specify
|
||||
dependencies. Click your own project (Smalltalk), and you will see
|
||||
project setting page. Go to "Build Phase", and inside it make sure
|
||||
your ANTLR Swift runtime framework is added to both "__Target
|
||||
Dependencies__" and "__Link Binary With Libraries__" sections, as
|
||||
shown below. After correctly added dependencies, the error message for
|
||||
importing library will be gone.
|
||||
|
||||
<img src=images/xcodedep.png width="800">
|
||||
|
||||
## Example playground
|
||||
|
||||
The Swift runtime includes an Xcode playground to get started with.
|
||||
|
||||
In Xcode, open `antlr4/runtime/Swift/Antlr4.xcworkspace`. Select
|
||||
"Antlr4 OSX > My Mac" as the build target, and build the project as normal.
|
||||
The playground should then be active.
|
||||
First go to the ANTLR4 repository, and open
|
||||
`runtime/Swift/Antlr4.xcworkspace` in Xcode. Select "Antlr4 OSX > My
|
||||
Mac" as the build target, and build the project as normal. The
|
||||
playground should then be active.
|
||||
|
||||
The playground includes a simple grammar called "Hello", and an example for
|
||||
walking the parse tree. You should see in the playground output that it is
|
||||
printing messages for each node in the parse tree as it walks.
|
||||
The playground includes a simple grammar called "Hello", and an
|
||||
example for walking the parse tree. You should see in the playground
|
||||
output that it is printing messages for each node in the parse tree as
|
||||
it walks.
|
||||
|
||||
The playground shows how to create a lexer, token stream, and parser, and
|
||||
how to execute the parse.
|
||||
|
||||
The grammar is defined in the playground's `Resources/Hello.g4`. The parser
|
||||
was generated from the grammar using Antlr4 like this:
|
||||
The grammar is defined in the playground's `Resources/Hello.g4`. The
|
||||
parser was generated from the grammar using ANTLR like this:
|
||||
|
||||
```
|
||||
cd 'antlr4/runtime/Swift/Antlr4 playground.playground/Resources'
|
||||
antlr4 -Dlanguage=Swift -visitor -o ../Sources/Autogen Hello.g4
|
||||
```
|
||||
|
||||
The example tree walker is in `Sources/HelloWalker.swift`.
|
||||
The example tree walker is in Sources/HelloWalker.swift.
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ This page lists the available and upcoming ANTLR runtimes. Please note that you
|
|||
|
||||
New features generally appear in the Java target and then migrate to the other targets, but these other targets don't always get updated in the same overall tool release. This section tries to identify features added to Java that have not been added to the other targets.
|
||||
|
||||
|Feature|Java|C♯|JavaScript|Python2|Python3|Swift|C++|
|
||||
|---|---|---|---|---|---|---|---|
|
||||
|Ambiguous tree construction|4.5.1|-|-|-|-|-|-|
|
||||
|Feature|Java|C♯|Python2|Python3|JavaScript|Go|C++|Swift|
|
||||
|---|---|---|---|---|---|---|---|---|
|
||||
|Ambiguous tree construction|4.5.1|-|-|-|-|-|-|-|
|
||||
|
||||
|
|
13
pom.xml
13
pom.xml
|
@ -1,3 +1,9 @@
|
|||
<!--
|
||||
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
|
||||
~ Use of this file is governed by the BSD 3-clause license that
|
||||
~ can be found in the LICENSE.txt file in the project root.
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
|
@ -7,7 +13,7 @@
|
|||
</parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.6-SNAPSHOT</version>
|
||||
<version>4.6.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>ANTLR 4</name>
|
||||
|
@ -30,7 +36,7 @@
|
|||
<developers>
|
||||
<developer>
|
||||
<name>Terence Parr</name>
|
||||
<url>http://antlr.org/wiki/display/~admin/Home</url>
|
||||
<url>http://parrt.cs.usfca.edu</url>
|
||||
<roles>
|
||||
<role>Project lead - ANTLR</role>
|
||||
</roles>
|
||||
|
@ -77,7 +83,6 @@
|
|||
<module>tool-testsuite</module>
|
||||
<module>runtime-testsuite/annotations</module>
|
||||
<module>runtime-testsuite/processors</module>
|
||||
<!-- <module>runtime-testsuite-legacy</module> -->
|
||||
<module>runtime-testsuite</module>
|
||||
</modules>
|
||||
|
||||
|
@ -114,7 +119,6 @@
|
|||
<directory>resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<testSourceDirectory>test</testSourceDirectory>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>test</directory>
|
||||
|
@ -125,6 +129,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<source>${maven.compiler.source}</source>
|
||||
<target>${maven.compiler.target}</target>
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-master</artifactId>
|
||||
<version>4.6-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>antlr4-runtime-testsuite-legacy</artifactId>
|
||||
<name>ANTLR 4 Legacy Runtime Test Generator</name>
|
||||
<description>Legacy collection of tests for ANTLR 4 Runtime libraries.</description>
|
||||
|
||||
<prerequisites>
|
||||
<maven>3.0</maven>
|
||||
</prerequisites>
|
||||
|
||||
<inceptionYear>2009</inceptionYear>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>ST4</artifactId>
|
||||
<version>4.0.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.antlr</groupId>
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>2.46.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>8.1.16.v20140903</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<!--
|
||||
<testSourceDirectory>test</testSourceDirectory>
|
||||
-->
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>resources</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>../runtime</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>gen</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-test-sources</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<mainClass>org.antlr.v4.testgen.TestGenerator</mainClass>
|
||||
<arguments>
|
||||
<argument>${basedir}/..</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>tests</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/Test*.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -1,111 +0,0 @@
|
|||
file(className, descriptors) ::= <<
|
||||
package org.antlr.v4.test.runtime.xxx.tests.junk;
|
||||
|
||||
import org.antlr.v4.runtime.misc.Pair;
|
||||
import org.antlr.v4.test.runtime.CommentHasStringValue;
|
||||
import org.antlr.v4.test.runtime.xxx.*;
|
||||
import org.antlr.v4.test.runtime.xxx.tests.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class <className> {
|
||||
<descriptors; separator="\n\n">
|
||||
}
|
||||
>>
|
||||
|
||||
rig(targetName, groupName, go, subdir) ::= <<
|
||||
package org.antlr.v4.test.runtime.xxx.tests.<subdir:{s|<s>.}><targetName; format="lower">;
|
||||
|
||||
import org.antlr.v4.test.runtime.xxx.RuntimeTestDescriptor;
|
||||
import org.antlr.v4.test.runtime.xxx.XXXBaseTest;
|
||||
import org.antlr.v4.test.runtime.xxx.descriptors.*;
|
||||
import org.junit.*;
|
||||
import org.junit.runner.*;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class Test<groupName> extends XXXBaseTest {
|
||||
public Test<groupName>(RuntimeTestDescriptor descriptor) {
|
||||
super(descriptor,new Base<targetName>Test());
|
||||
}
|
||||
|
||||
<if(go)>
|
||||
@BeforeClass
|
||||
public static void groupSetUp() throws Exception { BaseGoTest.groupSetUp(); }
|
||||
|
||||
@AfterClass
|
||||
public static void groupTearDown() throws Exception { BaseGoTest.groupTearDown(); }
|
||||
<endif>
|
||||
|
||||
@Parameterized.Parameters(name="{0}")
|
||||
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
|
||||
return XXXBaseTest.getRuntimeTestDescriptors(<groupName>Descriptors.class, "<targetName>");
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
descriptor(testName, TestType, Input, LongInput, Errors, LongErrors, Rule, Output, LongOutput,
|
||||
grammar, slaveGrammars, grammarName, LongAfterGrammar) ::= <<
|
||||
public static class <testName> extends Base<TestType>TestDescriptor {
|
||||
<if(LongInput)>
|
||||
/**
|
||||
<LongInput>
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String input;<\n>
|
||||
<else>
|
||||
public String input = "<Input>";
|
||||
<endif>
|
||||
<if(LongOutput)>
|
||||
/**
|
||||
<LongOutput>
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String output;<\n>
|
||||
<else>
|
||||
public String output = "<Output>";
|
||||
<endif>
|
||||
<if(LongErrors)>
|
||||
/**
|
||||
<LongErrors>
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String errors;<\n>
|
||||
<else>
|
||||
public String errors = "<Errors>";
|
||||
<endif>
|
||||
public String startRule = "<Rule>";
|
||||
public String grammarName = "<grammarName>";
|
||||
|
||||
<if(LongAfterGrammar)>
|
||||
/**
|
||||
<LongAfterGrammar>
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String afterGrammar;
|
||||
<endif>
|
||||
|
||||
/**
|
||||
<grammar>
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String grammar;
|
||||
|
||||
<if(slaveGrammars)>
|
||||
<slaveGrammars:{sg |
|
||||
/**
|
||||
<sg.grammar>
|
||||
*/
|
||||
@CommentHasStringValue
|
||||
public String slaveGrammar<sg.name>;
|
||||
}>
|
||||
@Override
|
||||
public List\<Pair\<String, String>\> getSlaveGrammars() {
|
||||
List\<Pair\<String,String>\> slaves = new ArrayList\<Pair\<String, String>\>();
|
||||
<slaveGrammars:{sg | slaves.add(new Pair\<String, String>("<sg.name>",slaveGrammar<sg.name>));<\n>}>
|
||||
return slaves;
|
||||
\}
|
||||
<endif>
|
||||
}
|
||||
>>
|
|
@ -1,280 +0,0 @@
|
|||
writeln(s) ::= "std::cout \<\< <s> \<\< std::endl;"
|
||||
write(s) ::= "std::cout \<\< <s>;"
|
||||
writeList(s) ::= << std::cout \<\< <s; separator=" \<\< "> \<\< std::endl;>>
|
||||
|
||||
False() ::= "false"
|
||||
True() ::= "true"
|
||||
Not(v) ::= "!<v>"
|
||||
Assert(s) ::= ""
|
||||
Cast(t,v) ::= "dynamic_cast\<<t> *>(<v>)" // Should actually use a more specific name. We may have to use other casts as well.
|
||||
Append(a,b) ::= "<a> + <b>->toString()"
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= "assert(<v>.size() >= 0);" // Use a method that exists only on a list (vector actually).
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= "int <n> = <v>;"
|
||||
InitBooleanMember(n,v) ::= "bool <n> = <v>;"
|
||||
|
||||
GetMember(n) ::= "<n>"
|
||||
SetMember(n,v) ::= "<n> = <v>;"
|
||||
AddMember(n,v) ::= "<n> += <v>;"
|
||||
PlusMember(v,n) ::= "<v> + <n>"
|
||||
MemberEquals(n,v) ::= "<n> == <v>"
|
||||
ModMemberEquals(n,m,v) ::= "<n> % <m> == <v>"
|
||||
ModMemberNotEquals(n,m,v) ::= "<n> % <m> != <v>"
|
||||
|
||||
DumpDFA() ::= "dumpDFA();"
|
||||
Pass() ::= "/* do nothing */"
|
||||
|
||||
StringList() ::= "std::vector\<std::string>"
|
||||
BuildParseTrees() ::= "setBuildParseTree(true);"
|
||||
BailErrorStrategy() ::= "_errHandler = std::make_shared\<BailErrorStrategy>();"
|
||||
|
||||
ToStringTree(s) ::= "<s>->toStringTree(this)"
|
||||
Column() ::= "getCharPositionInLine()"
|
||||
Text() ::= "getText()"
|
||||
ValEquals(a,b) ::= "<a> == <b>"
|
||||
TextEquals(a) ::= "getText() == \"<a>\""
|
||||
PlusText(a) ::="\"<a>\" + getText()"
|
||||
InputText() ::= "_input->getText()"
|
||||
LTEquals(i, v) ::= "_input->LT(<i>)->getText() == <v>"
|
||||
LANotEquals(i, v) ::= "_input->LA(<i>) != <v>"
|
||||
TokenStartColumnEquals(i) ::= "tokenStartCharPositionInLine == <i>"
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "getExpectedTokens().toString(_tokenNames)"
|
||||
|
||||
RuleInvocationStack() ::= "Arrays::listToString(getRuleInvocationStack(), \", \")"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<getInterpreter\<atn::ParserATNSimulator>()->setPredictionMode(atn::PredictionMode::LL_EXACT_AMBIG_DETECTION);>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>::<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
bool Property() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
protected:
|
||||
class PositionAdjustingLexerATNSimulator : public atn::LexerATNSimulator {
|
||||
public:
|
||||
PositionAdjustingLexerATNSimulator(Lexer *recog, const atn::ATN &atn, std::vector\<dfa::DFA> &decisionToDFA,
|
||||
atn::PredictionContextCache &sharedContextCache)
|
||||
: atn::LexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache) {
|
||||
}
|
||||
|
||||
void resetAcceptPosition(CharStream *input, int index, int line, int charPositionInLine) {
|
||||
input->seek(index);
|
||||
_line = line;
|
||||
_charPositionInLine = charPositionInLine;
|
||||
consume(input);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
virtual std::unique_ptr\<Token> nextToken() override {
|
||||
if (dynamic_cast\<PositionAdjustingLexerATNSimulator *>(_interpreter) == nullptr) {
|
||||
delete _interpreter;
|
||||
_interpreter = new PositionAdjustingLexerATNSimulator(this, _atn, _decisionToDFA, _sharedContextCache);
|
||||
}
|
||||
|
||||
return Lexer::nextToken();
|
||||
}
|
||||
|
||||
virtual Token* emit() override {
|
||||
switch (type) {
|
||||
case TOKENS:
|
||||
handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
|
||||
case LABEL:
|
||||
handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Lexer::emit();
|
||||
}
|
||||
|
||||
private:
|
||||
bool handleAcceptPositionForIdentifier() {
|
||||
std::string tokenText = getText();
|
||||
int identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length() && isIdentifierChar(tokenText[identifierLength])) {
|
||||
identifierLength++;
|
||||
}
|
||||
|
||||
if (getInputStream()->index() > tokenStartCharIndex + identifierLength) {
|
||||
int offset = identifierLength - 1;
|
||||
getInterpreter\<PositionAdjustingLexerATNSimulator>()->resetAcceptPosition(getInputStream(),
|
||||
tokenStartCharIndex + offset, tokenStartLine, tokenStartCharPositionInLine + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool handleAcceptPositionForKeyword(const std::string &keyword) {
|
||||
if (getInputStream()->index() > tokenStartCharIndex + keyword.length()) {
|
||||
long offset = keyword.size() - 1;
|
||||
getInterpreter\<PositionAdjustingLexerATNSimulator>()->resetAcceptPosition(getInputStream(),
|
||||
tokenStartCharIndex + offset, tokenStartLine, tokenStartCharPositionInLine + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool isIdentifierChar(char c) {
|
||||
return std::isalnum(c) || c == '_';
|
||||
}
|
||||
|
||||
public:
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
#include "TBaseListener.h"
|
||||
class LeafListener : public TBaseListener {
|
||||
public:
|
||||
virtual void visitTerminal(tree::TerminalNode *node) override {
|
||||
std::cout \<\< node->getSymbol()->getText() \<\< std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
LeafListener listener;
|
||||
tree::ParseTreeWalker::DEFAULT.walk(&listener, <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::members {
|
||||
class MyRuleNode : public ParserRuleContext {
|
||||
public:
|
||||
size_t altNum;
|
||||
MyRuleNode(ParserRuleContext *parent, int invokingStateNumber)
|
||||
: ParserRuleContext(parent, invokingStateNumber) {
|
||||
}
|
||||
virtual size_t getAltNumber() const override { return altNum; }
|
||||
virtual void setAltNumber(size_t altNum) override { this->altNum = altNum; }
|
||||
};
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
#include "TBaseListener.h"
|
||||
class LeafListener : public TBaseListener {
|
||||
public:
|
||||
virtual void exitA(TParser::AContext *ctx) override {
|
||||
if (ctx->children.size() == 2)
|
||||
std::cout \<\< ctx->INT(0)->getSymbol()->getText() \<\< " " \<\< ctx->INT(1)->getSymbol()->getText()
|
||||
\<\< " " \<\< Arrays::toString(ctx->INT()) \<\< std::endl;
|
||||
else
|
||||
std::cout \<\< ctx->ID()->getSymbol()->toString() \<\< std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
#include "TBaseListener.h"
|
||||
class LeafListener : public TBaseListener {
|
||||
public:
|
||||
virtual void exitA(TParser::AContext *ctx) override {
|
||||
if (ctx->children.size() == 2) {
|
||||
std::cout \<\< ctx->b(0)->start->getText() \<\< " " \<\< ctx->b(1)->start->getText() \<\< " " \<\< ctx->b()[0]->start->getText() \<\< std::endl;
|
||||
} else {
|
||||
std::cout \<\< ctx->b(0)->start->getText() \<\< std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
#include "TBaseListener.h"
|
||||
class LeafListener : public TBaseListener {
|
||||
public:
|
||||
virtual void exitE(TParser::EContext *ctx) override {
|
||||
if (ctx->children.size() == 3) {
|
||||
std::cout \<\< ctx->e(0)->start->getText() \<\< " " \<\< ctx->e(1)->start->getText() \<\< " " \<\< ctx->e()[0]->start->getText() \<\< std::endl;
|
||||
} else {
|
||||
std::cout \<\< ctx->INT()->getSymbol()->getText() \<\< std::endl;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::definitions {
|
||||
#include "TBaseListener.h"
|
||||
class LeafListener : public TBaseListener {
|
||||
public:
|
||||
virtual void exitCall(TParser::CallContext *ctx) override {
|
||||
std::cout \<\< ctx->e()->start->getText() \<\< " " \<\< ctx->eList()->toString() \<\< std::endl;
|
||||
}
|
||||
virtual void exitInt(TParser::IntContext *ctx) override {
|
||||
std::cout \<\< ctx->INT()->getSymbol()->getText() \<\< std::endl;
|
||||
}
|
||||
};
|
||||
}
|
||||
>>
|
||||
|
||||
ImportVisitor(X) ::= ""
|
||||
BasicVisitor(X) ::= ""
|
||||
WalkVisitor(s) ::= ""
|
||||
LRWithLabelsVisitor(X) ::= ""
|
||||
RuleGetterVisitor(X) ::= ""
|
||||
LRVisitor(x) ::= ""
|
||||
TokenGetterVisitor(x) ::= ""
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
void foo() {
|
||||
SContext *s;
|
||||
std::vector\<AContext *> a = s->a();
|
||||
std::vector\<BContext *> b = s->b();
|
||||
}
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<void foo() {
|
||||
std::cout \<\< "foo";
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_foo() ::= "foo();"
|
||||
|
||||
Declare_pred() ::= <<
|
||||
bool pred(bool v) {
|
||||
std::cout \<\< "eval=" \<\< std::boolalpha \<\< v \<\< std::endl;
|
||||
return v;
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<pred(<v>)>>
|
||||
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>-><rule>"
|
||||
StringType() ::= "std::string"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>-><subctx>-><member>"
|
|
@ -1,51 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{EDC70A11-C4C1-4209-93A6-CCE2B19E8E95}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Antlr4.Test.mono</RootNamespace>
|
||||
<AssemblyName>Test</AssemblyName>
|
||||
<StartupObject>Test</StartupObject>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="Antlr4.Runtime.mono.csproj">
|
||||
<Project>{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}</Project>
|
||||
<Name>Antlr4.Runtime.mono</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Test.cs" />
|
||||
<Compile Include="L.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<None Include="App.config">
|
||||
<LogicalName>Test.exe.config</LogicalName>
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,44 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{EDC70A11-C4C1-4209-93A6-CCE2B19E8E95}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>Antlr4.Test.mono</RootNamespace>
|
||||
<AssemblyName>Test</AssemblyName>
|
||||
<StartupObject>Test</StartupObject>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Externalconsole>true</Externalconsole>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs"/>
|
||||
<Compile Include="Test.cs"/>
|
||||
<Compile Include="L.cs"/>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="Antlr4.Runtime.vs2013.csproj">
|
||||
<Project>{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}</Project>
|
||||
<Name>Antlr4.Runtime.vs2013</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v2.0.50727"/>
|
||||
<supportedRuntime version="v4.0"/>
|
||||
</startup>
|
||||
</configuration>
|
|
@ -1,28 +0,0 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle ("Antlr4.Test.mono")]
|
||||
[assembly: AssemblyDescription ("")]
|
||||
[assembly: AssemblyConfiguration ("")]
|
||||
[assembly: AssemblyCompany ("")]
|
||||
[assembly: AssemblyProduct ("")]
|
||||
[assembly: AssemblyCopyright ("ericvergnaud")]
|
||||
[assembly: AssemblyTrademark ("")]
|
||||
[assembly: AssemblyCulture ("")]
|
||||
[assembly: CLSCompliant (true)]
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion ("1.0.*")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
|
@ -1,299 +0,0 @@
|
|||
writeln(s) ::= <<Console.WriteLine(<s>);>>
|
||||
write(s) ::= <<Console.Write(<s>);>>
|
||||
writeList(s) ::= <<Console.WriteLine(<s; separator="+">);>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= <<Debug.Assert(<s>);>>
|
||||
|
||||
Cast(t,v) ::= "((<t>)<v>)"
|
||||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "Object <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= "System.Collections.IList __ttt__ = <v>;" // just use static type system
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%int <n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%bool <n> = <v>;%>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.DumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "List\<String>"
|
||||
|
||||
BuildParseTrees() ::= "this.BuildParseTree = true;"
|
||||
|
||||
BailErrorStrategy() ::= <%ErrorHandler = new BailErrorStrategy();%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.ToStringTree(this)%>
|
||||
|
||||
Column() ::= "this.Column"
|
||||
|
||||
Text() ::= "this.Text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>==<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.Text.Equals("<a>")%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.Text%>
|
||||
|
||||
InputText() ::= "this.TokenStream.GetText()"
|
||||
|
||||
LTEquals(i, v) ::= <%this.TokenStream.Lt(<i>).Text.Equals(<v>)%>
|
||||
|
||||
LANotEquals(i, v) ::= <%this.InputStream.La(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this.TokenStartColumn==<i>%>
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "this.GetExpectedTokens().ToString(this.Vocabulary)"
|
||||
|
||||
RuleInvocationStack() ::= "GetRuleInvocationStackAsString()"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection;>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
bool Property() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
public override IToken NextToken() {
|
||||
if (!(Interpreter is PositionAdjustingLexerATNSimulator)) {
|
||||
Interpreter = new PositionAdjustingLexerATNSimulator(this, _ATN);
|
||||
}
|
||||
|
||||
return base.NextToken();
|
||||
}
|
||||
|
||||
public override IToken Emit() {
|
||||
switch (Type) {
|
||||
case TOKENS:
|
||||
HandleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
|
||||
case LABEL:
|
||||
HandleAcceptPositionForIdentifier();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return base.Emit();
|
||||
}
|
||||
|
||||
private bool HandleAcceptPositionForIdentifier() {
|
||||
string tokenText = this.Text;
|
||||
int identifierLength = 0;
|
||||
while (identifierLength \< tokenText.Length && IsIdentifierChar(tokenText[identifierLength])) {
|
||||
identifierLength++;
|
||||
}
|
||||
|
||||
if (InputStream.Index > TokenStartCharIndex + identifierLength) {
|
||||
int offset = identifierLength - 1;
|
||||
getInterpreter().ResetAcceptPosition((ICharStream)InputStream, TokenStartCharIndex + offset, TokenStartLine, TokenStartColumn + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool HandleAcceptPositionForKeyword(string keyword) {
|
||||
if (InputStream.Index > TokenStartCharIndex + keyword.Length) {
|
||||
int offset = keyword.Length - 1;
|
||||
getInterpreter().ResetAcceptPosition((ICharStream)InputStream, TokenStartCharIndex + offset, TokenStartLine, TokenStartColumn + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public PositionAdjustingLexerATNSimulator getInterpreter() {
|
||||
return (PositionAdjustingLexerATNSimulator)base.Interpreter;
|
||||
}
|
||||
|
||||
private static bool IsIdentifierChar(char c) {
|
||||
return Char.IsLetterOrDigit(c) || c == '_';
|
||||
}
|
||||
|
||||
public class PositionAdjustingLexerATNSimulator : LexerATNSimulator {
|
||||
|
||||
public PositionAdjustingLexerATNSimulator(Lexer recog, ATN atn)
|
||||
: base(recog, atn)
|
||||
{
|
||||
}
|
||||
|
||||
public void ResetAcceptPosition(ICharStream input, int index, int line, int column) {
|
||||
input.Seek(index);
|
||||
this.Line = line;
|
||||
this.Column = column;
|
||||
Consume(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
public class LeafListener : TBaseListener {
|
||||
public override void VisitTerminal(ITerminalNode node) {
|
||||
Console.WriteLine(node.Symbol.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.Walk(new LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::members {
|
||||
public class MyRuleNode : ParserRuleContext {
|
||||
public int altNum;
|
||||
public MyRuleNode(ParserRuleContext parent, int invokingStateNumber): base(parent, invokingStateNumber)
|
||||
{
|
||||
}
|
||||
public override int getAltNumber() { return altNum; }
|
||||
public override void setAltNumber(int altNum) { this.altNum = altNum; }
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
public class LeafListener : TBaseListener {
|
||||
public override void ExitA(TParser.AContext ctx) {
|
||||
if (ctx.ChildCount==2)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder ("[");
|
||||
foreach (ITerminalNode node in ctx.INT ()) {
|
||||
sb.Append (node.ToString ());
|
||||
sb.Append (", ");
|
||||
}
|
||||
sb.Length = sb.Length - 2;
|
||||
sb.Append ("]");
|
||||
Console.Write ("{0} {1} {2}", ctx.INT (0).Symbol.Text,
|
||||
ctx.INT (1).Symbol.Text, sb.ToString());
|
||||
}
|
||||
else
|
||||
Console.WriteLine(ctx.ID().Symbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
public class LeafListener : TBaseListener {
|
||||
public override void ExitA(TParser.AContext ctx) {
|
||||
if (ctx.ChildCount==2) {
|
||||
Console.Write("{0} {1} {2}",ctx.b(0).Start.Text,
|
||||
ctx.b(1).Start.Text,ctx.b()[0].Start.Text);
|
||||
} else
|
||||
Console.WriteLine(ctx.b(0).Start.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
public class LeafListener : TBaseListener {
|
||||
public override void ExitE(TParser.EContext ctx) {
|
||||
if (ctx.ChildCount==3) {
|
||||
Console.Write("{0} {1} {2}\n",ctx.e(0).Start.Text,
|
||||
ctx.e(1).Start.Text, ctx.e()[0].Start.Text);
|
||||
} else
|
||||
Console.WriteLine(ctx.INT().Symbol.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
public class LeafListener : TBaseListener {
|
||||
public override void ExitCall(TParser.CallContext ctx) {
|
||||
Console.Write("{0} {1}",ctx.e().Start.Text,ctx.eList());
|
||||
}
|
||||
public override void ExitInt(TParser.IntContext ctx) {
|
||||
Console.WriteLine(ctx.INT().Symbol.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ImportVisitor(X) ::= ""
|
||||
BasicVisitor(X) ::= ""
|
||||
WalkVisitor(s) ::= ""
|
||||
LRWithLabelsVisitor(X) ::= ""
|
||||
RuleGetterVisitor(X) ::= ""
|
||||
LRVisitor(x) ::= ""
|
||||
TokenGetterVisitor(x) ::= ""
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
void foo() {
|
||||
SContext s = null;
|
||||
AContext[] a = s.a();
|
||||
BContext[] b = s.b();
|
||||
}
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<public void foo() {Console.WriteLine("foo");}>>
|
||||
|
||||
Invoke_foo() ::= "this.foo();"
|
||||
|
||||
Declare_pred() ::= <<bool pred(bool v) {
|
||||
Console.WriteLine("eval="+v.ToString().ToLower());
|
||||
return v;
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,338 +0,0 @@
|
|||
writeln(s) ::= <<fmt.Println(<s>)>>
|
||||
write(s) ::= <<fmt.Print(<s>)>>
|
||||
writeList(s) ::= <<fmt.Print(<s; separator="+">);>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= ""
|
||||
|
||||
Cast(t,v) ::= "(<v>)"
|
||||
|
||||
Append(a,b) ::= "<a> + fmt.Sprint(<b>)"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s, v) ::= "var <s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= ""
|
||||
|
||||
AssignLocal(s, v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n, v) ::= <%var <n> int = <v>; var _ int = <n>; %>
|
||||
|
||||
InitBooleanMember(n, v) ::= <%var <n> bool = <v>; var _ bool = <n>; %>
|
||||
|
||||
GetMember(n) ::= <%<n>%>
|
||||
|
||||
SetMember(n, v) ::= <%<n> = <v>;%>
|
||||
|
||||
AddMember(n, v) ::= <%<n> += <v>;%>
|
||||
|
||||
PlusMember(v, n) ::= <%<v> + fmt.Sprint(<n>)%>
|
||||
|
||||
MemberEquals(n, v) ::= <%<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n, m, v) ::= <%<n> % <m> == <v>%>
|
||||
|
||||
ModMemberNotEquals(n, m, v) ::= <%<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "p.DumpDFA()"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "[]string"
|
||||
|
||||
BuildParseTrees() ::= "p.BuildParseTrees = true"
|
||||
|
||||
BailErrorStrategy() ::= <%p.SetErrorHandler(antlr.NewBailErrorStrategy())%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.ToStringTree(nil, p)%>
|
||||
|
||||
Column() ::= "p.GetCharPositionInLine()"
|
||||
|
||||
Text() ::= "l.GetText()"
|
||||
|
||||
ValEquals(a, b) ::= <%<a> == <b>%>
|
||||
|
||||
TextEquals(a) ::= <%p.GetText() == "<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + l.GetText()%>
|
||||
|
||||
InputText() ::= "p.GetTokenStream().GetAllText()"
|
||||
|
||||
LTEquals(i, v) ::= <%p.GetTokenStream().LT(<i>).GetText() == <v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%p.GetTokenStream().LA(<i>) != <v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%p.TokenStartColumn == <i>%>
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "p.GetExpectedTokens().StringVerbose(p.GetTokenNames(), nil, false)"
|
||||
|
||||
RuleInvocationStack() ::= "antlr.PrintArrayJavaStyle(p.GetRuleInvocationStack(nil))"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser><token>%>
|
||||
|
||||
Production(p) ::= <%<p; format="cap">%>
|
||||
|
||||
Result(r) ::= <%Get<r; format="cap">()%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@parser::members {
|
||||
func (p *TParser) Property() bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
func (p *PositionAdjustingLexer) NextToken() antlr.Token {
|
||||
if _, ok := p.Interpreter.(*PositionAdjustingLexerATNSimulator); !ok {
|
||||
p.Interpreter = NewPositionAdjustingLexerATNSimulator(p, lexerAtn, p.Interpreter.DecisionToDFA(), p.Interpreter.SharedContextCache())
|
||||
p.Virt = p
|
||||
}
|
||||
|
||||
return p.BaseLexer.NextToken()
|
||||
}
|
||||
|
||||
func (p *PositionAdjustingLexer) Emit() antlr.Token {
|
||||
switch p.GetType() {
|
||||
case PositionAdjustingLexerTOKENS:
|
||||
p.HandleAcceptPositionForKeyword("tokens")
|
||||
|
||||
case PositionAdjustingLexerLABEL:
|
||||
p.HandleAcceptPositionForIdentifier()
|
||||
}
|
||||
|
||||
return p.BaseLexer.Emit()
|
||||
}
|
||||
|
||||
func isIdentifierChar(c rune) bool {
|
||||
return unicode.IsLetter(c) || unicode.IsDigit(c) || c == '_'
|
||||
}
|
||||
|
||||
func (p *PositionAdjustingLexer) HandleAcceptPositionForIdentifier() bool {
|
||||
var tokenText = p.GetText()
|
||||
var identifierLength int
|
||||
|
||||
for identifierLength \< len(tokenText) && isIdentifierChar([]rune(tokenText)[identifierLength]) {
|
||||
identifierLength++
|
||||
}
|
||||
|
||||
if p.GetInputStream().Index() \<= p.TokenStartCharIndex + identifierLength {
|
||||
return false
|
||||
}
|
||||
|
||||
var offset = identifierLength - 1
|
||||
|
||||
p.GetInterpreter().(*PositionAdjustingLexerATNSimulator).ResetAcceptPosition(p.GetInputStream(), p.TokenStartCharIndex + offset, p.TokenStartLine, p.TokenStartColumn + offset)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (p *PositionAdjustingLexer) HandleAcceptPositionForKeyword(keyword string) bool {
|
||||
if p.GetInputStream().Index() \<= p.TokenStartCharIndex + len(keyword) {
|
||||
return false
|
||||
}
|
||||
|
||||
var offset = len(keyword) - 1
|
||||
|
||||
p.GetInterpreter().(*PositionAdjustingLexerATNSimulator).ResetAcceptPosition(p.GetInputStream(), p.TokenStartCharIndex + offset, p.TokenStartLine, p.TokenStartColumn + offset)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
type PositionAdjustingLexerATNSimulator struct {
|
||||
*antlr.LexerATNSimulator
|
||||
}
|
||||
|
||||
func NewPositionAdjustingLexerATNSimulator(recog antlr.Lexer, atn *antlr.ATN, decisionToDFA []*antlr.DFA, sharedContextCache *antlr.PredictionContextCache) *PositionAdjustingLexerATNSimulator {
|
||||
return &PositionAdjustingLexerATNSimulator{
|
||||
LexerATNSimulator: antlr.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *PositionAdjustingLexerATNSimulator) ResetAcceptPosition(input antlr.CharStream, index, line, charPositionInLine int) {
|
||||
input.Seek(index)
|
||||
p.Line = line
|
||||
p.CharPositionInLine = charPositionInLine
|
||||
p.Consume(input)
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::members {
|
||||
|
||||
type MyRuleNode struct {
|
||||
*antlr.BaseParserRuleContext
|
||||
|
||||
altNum int
|
||||
}
|
||||
|
||||
func NewMyRuleNode(parent antlr.ParserRuleContext, invokingStateNumber int) *MyRuleNode {
|
||||
return &MyRuleNode{
|
||||
BaseParserRuleContext : antlr.NewBaseParserRuleContext(parent, invokingStateNumber),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MyRuleNode) GetAltNumber() int {
|
||||
return m.altNum
|
||||
}
|
||||
|
||||
func (m *MyRuleNode) SetAltNumber(altNum int) {
|
||||
m.altNum = altNum
|
||||
}
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
BasicListener(notused) ::= <<
|
||||
@parser::members {
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
return &LeafListener{BaseTListener: &BaseTListener{}}
|
||||
}
|
||||
|
||||
func (*LeafListener) VisitTerminal(node antlr.TerminalNode) {
|
||||
fmt.Println(node.GetSymbol().GetText())
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
var walker = antlr.NewParseTreeWalker()
|
||||
|
||||
walker.Walk(NewLeafListener(), <s>)
|
||||
>>
|
||||
|
||||
TokenGetterListener(notused) ::= <<
|
||||
@parser::members {
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
return &LeafListener{BaseTListener: &BaseTListener{}}
|
||||
}
|
||||
|
||||
func (*LeafListener) ExitA(ctx *AContext) {
|
||||
if ctx.GetChildCount() == 2 {
|
||||
fmt.Printf("%s %s %s", ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(), antlr.PrintArrayJavaStyle(antlr.TerminalNodeToStringArray(ctx.AllINT())))
|
||||
} else {
|
||||
fmt.Println(ctx.ID().GetSymbol())
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(notused) ::= <<
|
||||
@parser::members {
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
return &LeafListener{BaseTListener: &BaseTListener{}}
|
||||
}
|
||||
|
||||
func (*LeafListener) ExitA(ctx *AContext) {
|
||||
if ctx.GetChildCount() == 2 {
|
||||
fmt.Printf("%s %s %s", ctx.B(0).GetStart().GetText(), ctx.B(1).GetStart().GetText(), ctx.AllB()[0].GetStart().GetText())
|
||||
} else {
|
||||
fmt.Println(ctx.B(0).GetStart().GetText())
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LRListener(notused) ::= <<
|
||||
@parser::members {
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
return &LeafListener{BaseTListener: &BaseTListener{}}
|
||||
}
|
||||
|
||||
func (*LeafListener) ExitE(ctx *EContext) {
|
||||
if ctx.GetChildCount() == 3 {
|
||||
fmt.Printf("%s %s %s\n", ctx.E(0).GetStart().GetText(), ctx.E(1).GetStart().GetText(), ctx.AllE()[0].GetStart().GetText())
|
||||
} else {
|
||||
fmt.Println(ctx.INT().GetSymbol().GetText())
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(notused) ::= <<
|
||||
@parser::members {
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
return &LeafListener{BaseTListener: &BaseTListener{}}
|
||||
}
|
||||
|
||||
func (*LeafListener) ExitCall(ctx *CallContext) {
|
||||
fmt.Printf("%s %s", ctx.E().GetStart().GetText(), ctx.EList().String(nil, nil))
|
||||
}
|
||||
|
||||
func (*LeafListener) ExitInt(ctx *IntContext) {
|
||||
fmt.Println(ctx.INT().GetSymbol().GetText())
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ImportVisitor(X) ::= ""
|
||||
BasicVisitor(X) ::= ""
|
||||
WalkVisitor(s) ::= ""
|
||||
LRWithLabelsVisitor(X) ::= ""
|
||||
RuleGetterVisitor(X) ::= ""
|
||||
LRVisitor(x) ::= ""
|
||||
TokenGetterVisitor(x) ::= ""
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
func foo() {
|
||||
// TODO
|
||||
// var s SContext
|
||||
// var a = s.A()
|
||||
// var b = s.B()
|
||||
}
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<
|
||||
func foo() {
|
||||
fmt.Println("foo")
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_foo() ::= "foo()"
|
||||
|
||||
Declare_pred() ::= <<
|
||||
func pred(v bool) bool {
|
||||
fmt.Println("eval=" + fmt.Sprint(v))
|
||||
|
||||
return v
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<pred(<v>)>>
|
||||
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member; format={cap}>"
|
|
@ -1,298 +0,0 @@
|
|||
writeln(s) ::= <<System.out.println(<s>);>>
|
||||
write(s) ::= <<System.out.print(<s>);>>
|
||||
writeList(s) ::= <<System.out.println(<s; separator="+">);>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= <<assert(<s>);>>
|
||||
|
||||
Cast(t,v) ::= "((<t>)<v>)"
|
||||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "Object <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= "List\<?> __ttt__ = <v>;" // just use static type system
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%int <n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%boolean <n> = <v>;%>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.dumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "List\<String>"
|
||||
|
||||
BuildParseTrees() ::= "setBuildParseTree(true);"
|
||||
|
||||
BailErrorStrategy() ::= <%setErrorHandler(new BailErrorStrategy());%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(this)%>
|
||||
|
||||
Column() ::= "this.getCharPositionInLine()"
|
||||
|
||||
Text() ::= "this.getText()"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>==<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.getText().equals("<a>")%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.getText()%>
|
||||
|
||||
InputText() ::= "this._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%this._input.LT(<i>).getText().equals(<v>)%>
|
||||
|
||||
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartCharPositionInLine==<i>%>
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.tokenNames)"
|
||||
|
||||
RuleInvocationStack() ::= "getRuleInvocationStack()"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<_interp.setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
boolean Property() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
@Override
|
||||
public Token nextToken() {
|
||||
if (!(_interp instanceof PositionAdjustingLexerATNSimulator)) {
|
||||
_interp = new PositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
|
||||
}
|
||||
|
||||
return super.nextToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token emit() {
|
||||
switch (_type) {
|
||||
case TOKENS:
|
||||
handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
|
||||
case LABEL:
|
||||
handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return super.emit();
|
||||
}
|
||||
|
||||
private boolean handleAcceptPositionForIdentifier() {
|
||||
String tokenText = getText();
|
||||
int identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length() && isIdentifierChar(tokenText.charAt(identifierLength))) {
|
||||
identifierLength++;
|
||||
}
|
||||
|
||||
if (getInputStream().index() > _tokenStartCharIndex + identifierLength) {
|
||||
int offset = identifierLength - 1;
|
||||
getInterpreter().resetAcceptPosition(getInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleAcceptPositionForKeyword(String keyword) {
|
||||
if (getInputStream().index() > _tokenStartCharIndex + keyword.length()) {
|
||||
int offset = keyword.length() - 1;
|
||||
getInterpreter().resetAcceptPosition(getInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PositionAdjustingLexerATNSimulator getInterpreter() {
|
||||
return (PositionAdjustingLexerATNSimulator)super.getInterpreter();
|
||||
}
|
||||
|
||||
private static boolean isIdentifierChar(char c) {
|
||||
return Character.isLetterOrDigit(c) || c == '_';
|
||||
}
|
||||
|
||||
protected static class PositionAdjustingLexerATNSimulator extends LexerATNSimulator {
|
||||
|
||||
public PositionAdjustingLexerATNSimulator(Lexer recog, ATN atn,
|
||||
DFA[] decisionToDFA,
|
||||
PredictionContextCache sharedContextCache)
|
||||
{
|
||||
super(recog, atn, decisionToDFA, sharedContextCache);
|
||||
}
|
||||
|
||||
protected void resetAcceptPosition(CharStream input, int index, int line, int charPositionInLine) {
|
||||
input.seek(index);
|
||||
this.line = line;
|
||||
this.charPositionInLine = charPositionInLine;
|
||||
consume(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
public static class LeafListener extends TBaseListener {
|
||||
public void visitTerminal(TerminalNode node) {
|
||||
System.out.println(node.getSymbol().getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
ParseTreeWalker walker = new ParseTreeWalker();
|
||||
walker.walk(new LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::members {
|
||||
public static class MyRuleNode extends ParserRuleContext {
|
||||
public int altNum;
|
||||
public MyRuleNode(ParserRuleContext parent, int invokingStateNumber) {
|
||||
super(parent, invokingStateNumber);
|
||||
}
|
||||
@Override public int getAltNumber() { return altNum; }
|
||||
@Override public void setAltNumber(int altNum) { this.altNum = altNum; }
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
public static class LeafListener extends TBaseListener {
|
||||
public void exitA(TParser.AContext ctx) {
|
||||
if (ctx.getChildCount()==2)
|
||||
System.out.printf("%s %s %s",ctx.INT(0).getSymbol().getText(),
|
||||
ctx.INT(1).getSymbol().getText(),ctx.INT());
|
||||
else
|
||||
System.out.println(ctx.ID().getSymbol());
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
public static class LeafListener extends TBaseListener {
|
||||
public void exitA(TParser.AContext ctx) {
|
||||
if (ctx.getChildCount()==2) {
|
||||
System.out.printf("%s %s %s",ctx.b(0).start.getText(),
|
||||
ctx.b(1).start.getText(),ctx.b().get(0).start.getText());
|
||||
} else
|
||||
System.out.println(ctx.b(0).start.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
public static class LeafListener extends TBaseListener {
|
||||
public void exitE(TParser.EContext ctx) {
|
||||
if (ctx.getChildCount()==3) {
|
||||
System.out.printf("%s %s %s\n",ctx.e(0).start.getText(),
|
||||
ctx.e(1).start.getText(), ctx.e().get(0).start.getText());
|
||||
} else
|
||||
System.out.println(ctx.INT().getSymbol().getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
public static class LeafListener extends TBaseListener {
|
||||
public void exitCall(TParser.CallContext ctx) {
|
||||
System.out.printf("%s %s",ctx.e().start.getText(),ctx.eList());
|
||||
}
|
||||
public void exitInt(TParser.IntContext ctx) {
|
||||
System.out.println(ctx.INT().getSymbol().getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ImportVisitor(X) ::= ""
|
||||
BasicVisitor(X) ::= ""
|
||||
WalkVisitor(s) ::= ""
|
||||
LRWithLabelsVisitor(X) ::= ""
|
||||
RuleGetterVisitor(X) ::= ""
|
||||
LRVisitor(x) ::= ""
|
||||
TokenGetterVisitor(x) ::= ""
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
void foo() {
|
||||
SContext s = null;
|
||||
List\<? extends AContext> a = s.a();
|
||||
List\<? extends BContext> b = s.b();
|
||||
}
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<
|
||||
public void foo() {System.out.println("foo");}
|
||||
>>
|
||||
|
||||
Invoke_foo() ::= "foo();"
|
||||
|
||||
Declare_pred() ::= <<boolean pred(boolean v) {
|
||||
System.out.println("eval="+v);
|
||||
return v;
|
||||
}
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,285 +0,0 @@
|
|||
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
|
||||
|
||||
write(s) ::= <<document.getElementById('output').value += <s>;>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= ""
|
||||
|
||||
Cast(t,v) ::= "<v>"
|
||||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.dumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "list"
|
||||
|
||||
BuildParseTrees() ::= "this.buildParseTrees = true;"
|
||||
|
||||
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
|
||||
|
||||
Column() ::= "this.column"
|
||||
|
||||
Text() ::= "this.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>===<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.text==="<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.text%>
|
||||
|
||||
InputText() ::= "this._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<var <X>Listener = require('./<X>Listener').<X>Listener;>>
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
this.Property = function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
this._input.seek(index);
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
this._interp.consume(this._input);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.nextToken = function() {
|
||||
if (!("resetAcceptPosition" in this._interp)) {
|
||||
var lexer = this;
|
||||
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
|
||||
}
|
||||
return antlr4.Lexer.prototype.nextToken.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.emit = function() {
|
||||
switch(this._type) {
|
||||
case PositionAdjustingLexer.TOKENS:
|
||||
this.handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
case PositionAdjustingLexer.LABEL:
|
||||
this.handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
}
|
||||
return antlr4.Lexer.prototype.emit.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
|
||||
var tokenText = this.text;
|
||||
var identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length &&
|
||||
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
|
||||
) {
|
||||
identifierLength += 1;
|
||||
}
|
||||
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
|
||||
var offset = identifierLength - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
|
||||
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
|
||||
var offset = keyword.length - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.isIdentifierChar = function(c) {
|
||||
return c.match(/^[0-9a-zA-Z_]+$/);
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
this.visitTerminal = function(node) {
|
||||
document.getElementById('output').value += node.symbol.text + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
var walker = new antlr4.tree.ParseTreeWalker();
|
||||
walker.walk(new this.LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
|
||||
@parser::header {
|
||||
MyRuleNode = function(parent, invokingState) {
|
||||
antlr4.ParserRuleContext.call(this, parent, invokingState);
|
||||
this.altNum = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
|
||||
MyRuleNode.prototype.constructor = MyRuleNode;
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
|
||||
} else {
|
||||
str = ctx.ID().symbol.toString();
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
|
||||
} else {
|
||||
str = ctx.b(0).start.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
this.exitE = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===3) {
|
||||
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
|
||||
} else {
|
||||
str = ctx.INT().symbol.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
this.LeafListener = function() {
|
||||
this.exitCall = function(ctx) {
|
||||
var str = ctx.e().start.text + ' ' + ctx.eList();
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
this.exitInt = function(ctx) {
|
||||
var str = ctx.INT().symbol.text;
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
function foo() {
|
||||
var s = new SContext();
|
||||
var a = s.a();
|
||||
var b = s.b();
|
||||
};
|
||||
>>
|
||||
|
||||
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
|
||||
|
||||
Invoke_foo() ::= "this.foo();"
|
||||
|
||||
Declare_pred() ::= <<this.pred = function(v) {
|
||||
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
|
||||
return v;
|
||||
};
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
|
@ -1,294 +0,0 @@
|
|||
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
|
||||
write(s) ::= <<document.getElementById('output').value += <s>;>>
|
||||
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= ""
|
||||
|
||||
Cast(t,v) ::= "<v>"
|
||||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.dumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "list"
|
||||
|
||||
BuildParseTrees() ::= "this.buildParseTrees = true;"
|
||||
|
||||
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
|
||||
|
||||
Column() ::= "this.column"
|
||||
|
||||
Text() ::= "this.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>===<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.text==="<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.text%>
|
||||
|
||||
InputText() ::= "this._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
var <X>Listener = require('./<X>Listener').<X>Listener;
|
||||
}
|
||||
>>
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
this.Property = function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
this._input.seek(index);
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
this._interp.consume(this._input);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.nextToken = function() {
|
||||
if (!("resetAcceptPosition" in this._interp)) {
|
||||
var lexer = this;
|
||||
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
|
||||
}
|
||||
return antlr4.Lexer.prototype.nextToken.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.emit = function() {
|
||||
switch(this._type) {
|
||||
case PositionAdjustingLexer.TOKENS:
|
||||
this.handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
case PositionAdjustingLexer.LABEL:
|
||||
this.handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
}
|
||||
return antlr4.Lexer.prototype.emit.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
|
||||
var tokenText = this.text;
|
||||
var identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length &&
|
||||
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
|
||||
) {
|
||||
identifierLength += 1;
|
||||
}
|
||||
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
|
||||
var offset = identifierLength - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
|
||||
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
|
||||
var offset = keyword.length - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.isIdentifierChar = function(c) {
|
||||
return c.match(/^[0-9a-zA-Z_]+$/);
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.visitTerminal = function(node) {
|
||||
document.getElementById('output').value += node.symbol.text + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
var walker = new antlr4.tree.ParseTreeWalker();
|
||||
walker.walk(new this.LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::header {
|
||||
MyRuleNode = function(parent, invokingState) {
|
||||
antlr4.ParserRuleContext.call(this, parent, invokingState);
|
||||
this.altNum = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
|
||||
MyRuleNode.prototype.constructor = MyRuleNode;
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
|
||||
} else {
|
||||
str = ctx.ID().symbol.toString();
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
|
||||
} else {
|
||||
str = ctx.b(0).start.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitE = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===3) {
|
||||
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
|
||||
} else {
|
||||
str = ctx.INT().symbol.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitCall = function(ctx) {
|
||||
var str = ctx.e().start.text + ' ' + ctx.eList();
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
this.exitInt = function(ctx) {
|
||||
var str = ctx.INT().symbol.text;
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
function foo() {
|
||||
var s = new SContext();
|
||||
var a = s.a();
|
||||
var b = s.b();
|
||||
};
|
||||
>>
|
||||
|
||||
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
|
||||
|
||||
Invoke_foo() ::= "this.foo();"
|
||||
|
||||
Declare_pred() ::= <<this.pred = function(v) {
|
||||
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
|
||||
return v;
|
||||
};
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,296 +0,0 @@
|
|||
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
|
||||
write(s) ::= <<document.getElementById('output').value += <s>;>>
|
||||
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= ""
|
||||
|
||||
Cast(t,v) ::= "<v>"
|
||||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array"}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
CheckVectorContext(s,v) ::= "<s> = [].concat(<v>);"
|
||||
|
||||
DumpDFA() ::= "this.dumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "list"
|
||||
|
||||
BuildParseTrees() ::= "this.buildParseTrees = true;"
|
||||
|
||||
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
|
||||
|
||||
Column() ::= "this.column"
|
||||
|
||||
Text() ::= "this.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>===<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.text==="<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.text%>
|
||||
|
||||
InputText() ::= "this._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
var <X>Listener = require('./<X>Listener').<X>Listener;
|
||||
}
|
||||
>>
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
this.Property = function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
this._input.seek(index);
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
this._interp.consume(this._input);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.nextToken = function() {
|
||||
if (!("resetAcceptPosition" in this._interp)) {
|
||||
var lexer = this;
|
||||
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
|
||||
}
|
||||
return antlr4.Lexer.prototype.nextToken.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.emit = function() {
|
||||
switch(this._type) {
|
||||
case PositionAdjustingLexer.TOKENS:
|
||||
this.handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
case PositionAdjustingLexer.LABEL:
|
||||
this.handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
}
|
||||
return antlr4.Lexer.prototype.emit.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
|
||||
var tokenText = this.text;
|
||||
var identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length &&
|
||||
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
|
||||
) {
|
||||
identifierLength += 1;
|
||||
}
|
||||
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
|
||||
var offset = identifierLength - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
|
||||
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
|
||||
var offset = keyword.length - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.isIdentifierChar = function(c) {
|
||||
return c.match(/^[0-9a-zA-Z_]+$/);
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.visitTerminal = function(node) {
|
||||
document.getElementById('output').value += node.symbol.text + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
var walker = new antlr4.tree.ParseTreeWalker();
|
||||
walker.walk(new this.LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::header {
|
||||
MyRuleNode = function(parent, invokingState) {
|
||||
antlr4.ParserRuleContext.call(this, parent, invokingState);
|
||||
this.altNum = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
|
||||
MyRuleNode.prototype.constructor = MyRuleNode;
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
|
||||
} else {
|
||||
str = ctx.ID().symbol.toString();
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
|
||||
} else {
|
||||
str = ctx.b(0).start.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitE = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===3) {
|
||||
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
|
||||
} else {
|
||||
str = ctx.INT().symbol.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitCall = function(ctx) {
|
||||
var str = ctx.e().start.text + ' ' + ctx.eList();
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
this.exitInt = function(ctx) {
|
||||
var str = ctx.INT().symbol.text;
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
function foo() {
|
||||
var s = new SContext();
|
||||
var a = s.a();
|
||||
var b = s.b();
|
||||
};
|
||||
>>
|
||||
|
||||
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
|
||||
|
||||
Invoke_foo() ::= "this.foo();"
|
||||
|
||||
Declare_pred() ::= <<this.pred = function(v) {
|
||||
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
|
||||
return v;
|
||||
};
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,389 +0,0 @@
|
|||
writeln(s) ::= <<console.log(<s>);>>
|
||||
write(s) ::= <<process.stdout.write(<s>);>>
|
||||
writeList(s) ::= <<console.log(<s; separator="+">);>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= <<console.assert(<s>);>>
|
||||
|
||||
Cast(t,v) ::= "<v>"
|
||||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.dumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "list"
|
||||
|
||||
BuildParseTrees() ::= "this.buildParseTrees = true;"
|
||||
|
||||
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
|
||||
|
||||
Column() ::= "this.column"
|
||||
|
||||
Text() ::= "this.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>===<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.text==="<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.text%>
|
||||
|
||||
InputText() ::= "this._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
var <X>Listener = require('./<X>Listener').<X>Listener;
|
||||
}
|
||||
>>
|
||||
|
||||
ImportVisitor(X) ::= <<var <X>Visitor = require('./<X>Visitor').<X>Visitor;>>
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
this.Property = function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
this._input.seek(index);
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
this._interp.consume(this._input);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.nextToken = function() {
|
||||
if (!("resetAcceptPosition" in this._interp)) {
|
||||
var lexer = this;
|
||||
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
|
||||
}
|
||||
return antlr4.Lexer.prototype.nextToken.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.emit = function() {
|
||||
switch(this._type) {
|
||||
case PositionAdjustingLexer.TOKENS:
|
||||
this.handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
case PositionAdjustingLexer.LABEL:
|
||||
this.handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
}
|
||||
return antlr4.Lexer.prototype.emit.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
|
||||
var tokenText = this.text;
|
||||
var identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length &&
|
||||
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
|
||||
) {
|
||||
identifierLength += 1;
|
||||
}
|
||||
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
|
||||
var offset = identifierLength - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
|
||||
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
|
||||
var offset = keyword.length - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.isIdentifierChar = function(c) {
|
||||
return c.match(/^[0-9a-zA-Z_]+$/);
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.visitTerminal = function(node) {
|
||||
console.log(node.symbol.text);
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
var walker = new antlr4.tree.ParseTreeWalker();
|
||||
walker.walk(new this.LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
BasicVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitTerminal = function(node) {
|
||||
return node.symbol.text;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
WalkVisitor(s) ::= <<
|
||||
var visitor = new this.LeafVisitor();
|
||||
console.log(<s>.accept(visitor));
|
||||
>>
|
||||
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::header {
|
||||
MyRuleNode = function(parent, invokingState) {
|
||||
antlr4.ParserRuleContext.call(this, parent, invokingState);
|
||||
|
||||
this.altNum = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
|
||||
MyRuleNode.prototype.constructor = MyRuleNode;
|
||||
MyRuleNode.prototype.getAltNumber = function() { return this.altNum; }
|
||||
MyRuleNode.prototype.setAltNumber = function(altNumber) { this.altNum = altNumber; }
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
|
||||
} else {
|
||||
str = ctx.ID().symbol.toString();
|
||||
}
|
||||
console.log(str);
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
|
||||
} else {
|
||||
str = ctx.ID().symbol.toString();
|
||||
}
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
|
||||
} else {
|
||||
str = ctx.b(0).start.text;
|
||||
}
|
||||
console.log(str);
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
|
||||
} else {
|
||||
str = ctx.b(0).start.text;
|
||||
}
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitE = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===3) {
|
||||
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
|
||||
} else {
|
||||
str = ctx.INT().symbol.text;
|
||||
}
|
||||
console.log(str);
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
LRVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitE = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===3) {
|
||||
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
|
||||
} else {
|
||||
str = ctx.INT().symbol.text;
|
||||
}
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitCall = function(ctx) {
|
||||
var str = ctx.e().start.text + ' ' + ctx.eList();
|
||||
console.log(str);
|
||||
};
|
||||
this.exitInt = function(ctx) {
|
||||
var str = ctx.INT().symbol.text;
|
||||
console.log(str);
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsVisitor(X) ::= <<
|
||||
this.LeafVisitor = function() {
|
||||
this.visitCall = function(ctx) {
|
||||
var str = ctx.e().start.text + ' ' + ctx.eList();
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
this.visitInt = function(ctx) {
|
||||
var str = ctx.INT().symbol.text;
|
||||
return this.visitChildren(ctx) + str;
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
|
||||
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
|
||||
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
function foo() {
|
||||
var s = new SContext();
|
||||
var a = s.a();
|
||||
var b = s.b();
|
||||
};
|
||||
>>
|
||||
|
||||
Declare_foo() ::= "this.foo = function() {console.log('foo');};"
|
||||
|
||||
Invoke_foo() ::= "this.foo();"
|
||||
|
||||
Declare_pred() ::= <<this.pred = function(v) {
|
||||
console.log("eval=" + v.toString());
|
||||
return v;
|
||||
};
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,295 +0,0 @@
|
|||
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
|
||||
write(s) ::= <<document.getElementById('output').value += <s>;>>
|
||||
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
|
||||
|
||||
False() ::= "false"
|
||||
|
||||
True() ::= "true"
|
||||
|
||||
Not(v) ::= "!<v>"
|
||||
|
||||
Assert(s) ::= ""
|
||||
|
||||
Cast(t,v) ::= "<v>"
|
||||
|
||||
Append(a,b) ::= "<a> + <b>"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "var <s> = <v>;"
|
||||
|
||||
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>;"
|
||||
|
||||
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> === <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "this.dumpDFA();"
|
||||
|
||||
Pass() ::= ""
|
||||
|
||||
StringList() ::= "list"
|
||||
|
||||
BuildParseTrees() ::= "this.buildParseTrees = true;"
|
||||
|
||||
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
|
||||
|
||||
Column() ::= "this.column"
|
||||
|
||||
Text() ::= "this.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>===<b>%>
|
||||
|
||||
TextEquals(a) ::= <%this.text==="<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + this.text%>
|
||||
|
||||
InputText() ::= "this._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
var <X>Listener = require('./<X>Listener').<X>Listener;
|
||||
}
|
||||
>>
|
||||
|
||||
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
|
||||
|
||||
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
this.Property = function() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
|
||||
this._input.seek(index);
|
||||
this.line = line;
|
||||
this.column = column;
|
||||
this._interp.consume(this._input);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.nextToken = function() {
|
||||
if (!("resetAcceptPosition" in this._interp)) {
|
||||
var lexer = this;
|
||||
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
|
||||
}
|
||||
return antlr4.Lexer.prototype.nextToken.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.emit = function() {
|
||||
switch(this._type) {
|
||||
case PositionAdjustingLexer.TOKENS:
|
||||
this.handleAcceptPositionForKeyword("tokens");
|
||||
break;
|
||||
case PositionAdjustingLexer.LABEL:
|
||||
this.handleAcceptPositionForIdentifier();
|
||||
break;
|
||||
}
|
||||
return antlr4.Lexer.prototype.emit.call(this);
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
|
||||
var tokenText = this.text;
|
||||
var identifierLength = 0;
|
||||
while (identifierLength \< tokenText.length &&
|
||||
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
|
||||
) {
|
||||
identifierLength += 1;
|
||||
}
|
||||
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
|
||||
var offset = identifierLength - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
|
||||
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
|
||||
var offset = keyword.length - 1;
|
||||
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
|
||||
this._tokenStartLine, this._tokenStartColumn + offset);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
PositionAdjustingLexer.isIdentifierChar = function(c) {
|
||||
return c.match(/^[0-9a-zA-Z_]+$/);
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.visitTerminal = function(node) {
|
||||
document.getElementById('output').value += node.symbol.text + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
var walker = new antlr4.tree.ParseTreeWalker();
|
||||
walker.walk(new this.LeafListener(), <s>);
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::header {
|
||||
MyRuleNode = function(parent, invokingState) {
|
||||
antlr4.ParserRuleContext.call(this, parent, invokingState);
|
||||
this.altNum = 0;
|
||||
return this;
|
||||
};
|
||||
|
||||
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
|
||||
MyRuleNode.prototype.constructor = MyRuleNode;
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
|
||||
} else {
|
||||
str = ctx.ID().symbol.toString();
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitA = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===2) {
|
||||
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
|
||||
} else {
|
||||
str = ctx.b(0).start.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitE = function(ctx) {
|
||||
var str;
|
||||
if(ctx.getChildCount()===3) {
|
||||
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
|
||||
} else {
|
||||
str = ctx.INT().symbol.text;
|
||||
}
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
this.LeafListener = function() {
|
||||
this.exitCall = function(ctx) {
|
||||
var str = ctx.e().start.text + ' ' + ctx.eList();
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
this.exitInt = function(ctx) {
|
||||
var str = ctx.INT().symbol.text;
|
||||
document.getElementById('output').value += str + '\\n';
|
||||
};
|
||||
return this;
|
||||
};
|
||||
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
|
||||
this.LeafListener.prototype.constructor = this.LeafListener;
|
||||
}
|
||||
>>
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
function foo() {
|
||||
var s = new SContext();
|
||||
var a = s.a();
|
||||
var b = s.b();
|
||||
};
|
||||
>>
|
||||
|
||||
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
|
||||
|
||||
Invoke_foo() ::= "this.foo();"
|
||||
|
||||
Declare_pred() ::= <<this.pred = function(v) {
|
||||
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
|
||||
return v;
|
||||
};
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,273 +0,0 @@
|
|||
writeln(s) ::= <<print(<s>)>>
|
||||
write(s) ::= <<print(<s>,end='')>>
|
||||
writeList(s) ::= <<print(<s: {v | str(<v>)}; separator="+">)>>
|
||||
|
||||
False() ::= "False"
|
||||
|
||||
True() ::= "True"
|
||||
|
||||
Not(v) ::= "not <v>"
|
||||
|
||||
Assert(s) ::= ""
|
||||
|
||||
Cast(t,v) ::= "<v>"
|
||||
|
||||
Append(a,b) ::= "<a> + str(<b>)"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
InitIntMember(n,v) ::= <%<n> = <v>%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%<n> = <v>%>
|
||||
|
||||
GetMember(n) ::= <%self.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%self.<n> = <v>%>
|
||||
|
||||
AddMember(n,v) ::= <%self.<n> += <v>%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + str(self.<n>)%>
|
||||
|
||||
MemberEquals(n,v) ::= <%self.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%self.<n> % <m> == <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%self.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "self.dumpDFA()"
|
||||
|
||||
Pass() ::= "pass"
|
||||
|
||||
StringList() ::= ""
|
||||
|
||||
BuildParseTrees() ::= "self._buildParseTrees = True"
|
||||
|
||||
BailErrorStrategy() ::= <%self._errHandler = BailErrorStrategy()%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(recog=self)%>
|
||||
|
||||
Column() ::= "self.column"
|
||||
|
||||
Text() ::= "self.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>==<b>%>
|
||||
|
||||
TextEquals(a) ::= <%self.text=="<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + self.text%>
|
||||
|
||||
InputText() ::= "self._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%self._input.LT(<i>).text==<v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%self._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%self._tokenStartColumn==<i>%>
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
GetExpectedTokenNames() ::= "self.getExpectedTokens().toString(self.literalNames, self.symbolicNames)"
|
||||
|
||||
RuleInvocationStack() ::= "str_list(self.getRuleInvocationStack())"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<self._interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
def Property(self):
|
||||
return True
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
def resetAcceptPosition(self, index, line, column):
|
||||
self._input.seek(index)
|
||||
self.line = line
|
||||
self.column = column
|
||||
self._interp.consume(self._input)
|
||||
|
||||
def nextToken(self):
|
||||
if self._interp.__dict__.get("resetAcceptPosition", None) is None:
|
||||
self._interp.__dict__["resetAcceptPosition"] = self.resetAcceptPosition
|
||||
return super(type(self),self).nextToken()
|
||||
|
||||
def emit(self):
|
||||
if self._type==PositionAdjustingLexer.TOKENS:
|
||||
self.handleAcceptPositionForKeyword("tokens")
|
||||
elif self._type==PositionAdjustingLexer.LABEL:
|
||||
self.handleAcceptPositionForIdentifier()
|
||||
return super(type(self),self).emit()
|
||||
|
||||
def handleAcceptPositionForIdentifier(self):
|
||||
tokenText = self.text
|
||||
identifierLength = 0
|
||||
while identifierLength \< len(tokenText) and self.isIdentifierChar(tokenText[identifierLength]):
|
||||
identifierLength += 1
|
||||
|
||||
if self._input.index > self._tokenStartCharIndex + identifierLength:
|
||||
offset = identifierLength - 1
|
||||
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
|
||||
self._tokenStartLine, self._tokenStartColumn + offset)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def handleAcceptPositionForKeyword(self, keyword):
|
||||
if self._input.index > self._tokenStartCharIndex + len(keyword):
|
||||
offset = len(keyword) - 1
|
||||
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
|
||||
self._tokenStartLine, self._tokenStartColumn + offset)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def isIdentifierChar(c):
|
||||
return c.isalnum() or c == '_'
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
if __name__ is not None and "." in __name__:
|
||||
from .<X>Listener import <X>Listener
|
||||
else:
|
||||
from <X>Listener import <X>Listener
|
||||
|
||||
class LeafListener(TListener):
|
||||
def visitTerminal(self, node):
|
||||
print(node.symbol.text)
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
walker = ParseTreeWalker()
|
||||
walker.walk(TParser.LeafListener(), <s>)
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::members {
|
||||
class MyRuleNode(ParserRuleContext):
|
||||
def __init__(self, parent = None, invokingStateNumber = None ):
|
||||
super(<X>Parser.MyRuleNode, self).__init__(parent, invokingStateNumber)
|
||||
self.altNum = 0;
|
||||
def getAltNumber(self):
|
||||
return self.altNum
|
||||
def setAltNumber(self, altNum):
|
||||
self.altNum = altNum
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
if __name__ is not None and "." in __name__:
|
||||
from .<X>Listener import <X>Listener
|
||||
else:
|
||||
from <X>Listener import <X>Listener
|
||||
|
||||
class LeafListener(TListener):
|
||||
def exitA(self, ctx):
|
||||
if ctx.getChildCount()==2:
|
||||
print(ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + str_list(ctx.INT()))
|
||||
else:
|
||||
print(str(ctx.ID().symbol))
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
if __name__ is not None and "." in __name__:
|
||||
from .<X>Listener import <X>Listener
|
||||
else:
|
||||
from <X>Listener import <X>Listener
|
||||
|
||||
class LeafListener(TListener):
|
||||
def exitA(self, ctx):
|
||||
if ctx.getChildCount()==2:
|
||||
print(ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text)
|
||||
else:
|
||||
print(ctx.b(0).start.text)
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
if __name__ is not None and "." in __name__:
|
||||
from .<X>Listener import <X>Listener
|
||||
else:
|
||||
from <X>Listener import <X>Listener
|
||||
|
||||
class LeafListener(TListener):
|
||||
def exitE(self, ctx):
|
||||
if ctx.getChildCount()==3:
|
||||
print(ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text)
|
||||
else:
|
||||
print(ctx.INT().symbol.text)
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
if __name__ is not None and "." in __name__:
|
||||
from .<X>Listener import <X>Listener
|
||||
else:
|
||||
from <X>Listener import <X>Listener
|
||||
|
||||
class LeafListener(TListener):
|
||||
def exitCall(self, ctx):
|
||||
print(ctx.e().start.text + ' ' + str(ctx.eList()))
|
||||
def exitInt(self, ctx):
|
||||
print(ctx.INT().symbol.text)
|
||||
}
|
||||
>>
|
||||
|
||||
ImportVisitor(X) ::= ""
|
||||
BasicVisitor(X) ::= ""
|
||||
WalkVisitor(s) ::= ""
|
||||
LRWithLabelsVisitor(X) ::= ""
|
||||
RuleGetterVisitor(X) ::= ""
|
||||
LRVisitor(x) ::= ""
|
||||
TokenGetterVisitor(x) ::= ""
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
def foo():
|
||||
s = SContext()
|
||||
a = s.a()
|
||||
b = s.b()
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<def foo(self):
|
||||
print('foo')
|
||||
>>
|
||||
|
||||
Invoke_foo() ::= "self.foo()"
|
||||
|
||||
Declare_pred() ::= <<def pred(self, v):
|
||||
print('eval=' + str(v).lower())
|
||||
return v
|
||||
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<self.pred(<v>)>>
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,258 +0,0 @@
|
|||
writeln(s) ::= <<print(<s>)>>
|
||||
write(s) ::= <<print(<s>,end='')>>
|
||||
writeList(s) ::= <<print(<s: {v | str(<v>)}; separator="+">)>>
|
||||
|
||||
False() ::= "False"
|
||||
|
||||
True() ::= "True"
|
||||
|
||||
Not(v) ::= "not <v>"
|
||||
|
||||
Assert(s) ::= ""
|
||||
|
||||
Cast(t,v) ::= "<v>"
|
||||
|
||||
Append(a,b) ::= "<a> + str(<b>)"
|
||||
|
||||
Concat(a,b) ::= "<a><b>"
|
||||
|
||||
DeclareLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
|
||||
|
||||
AssignLocal(s,v) ::= "<s> = <v>"
|
||||
|
||||
InitIntMember(n,v) ::= <%<n> = <v>%>
|
||||
|
||||
InitBooleanMember(n,v) ::= <%<n> = <v>%>
|
||||
|
||||
GetMember(n) ::= <%self.<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%self.<n> = <v>%>
|
||||
|
||||
AddMember(n,v) ::= <%self.<n> += <v>%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + str(self.<n>)%>
|
||||
|
||||
MemberEquals(n,v) ::= <%self.<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%self.<n> % <m> == <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%self.<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "self.dumpDFA()"
|
||||
|
||||
Pass() ::= "pass"
|
||||
|
||||
StringList() ::= ""
|
||||
|
||||
BuildParseTrees() ::= "self._buildParseTrees = True"
|
||||
|
||||
BailErrorStrategy() ::= <%self._errHandler = BailErrorStrategy()%>
|
||||
|
||||
ToStringTree(s) ::= <%<s>.toStringTree(recog=self)%>
|
||||
|
||||
Column() ::= "self.column"
|
||||
|
||||
Text() ::= "self.text"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>==<b>%>
|
||||
|
||||
TextEquals(a) ::= <%self.text=="<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + self.text%>
|
||||
|
||||
InputText() ::= "self._input.getText()"
|
||||
|
||||
LTEquals(i, v) ::= <%self._input.LT(<i>).text==<v>%>
|
||||
|
||||
LANotEquals(i, v) ::= <%self._input.LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%self._tokenStartColumn==<i>%>
|
||||
|
||||
ImportListener(X) ::= <<
|
||||
@parser::header {
|
||||
class MockListener:
|
||||
pass
|
||||
}
|
||||
>>
|
||||
|
||||
GetExpectedTokenNames() ::= "self.getExpectedTokens().toString(self.literalNames, self.symbolicNames)"
|
||||
|
||||
RuleInvocationStack() ::= "str_list(self.getRuleInvocationStack())"
|
||||
|
||||
LL_EXACT_AMBIG_DETECTION() ::= <<self._interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION>>
|
||||
|
||||
ParserToken(parser, token) ::= <%<parser>.<token>%>
|
||||
|
||||
Production(p) ::= <%<p>%>
|
||||
|
||||
Result(r) ::= <%<r>%>
|
||||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
def Property(self):
|
||||
return True
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
ParserPropertyCall(p, call) ::= "<p>.<call>"
|
||||
|
||||
PositionAdjustingLexer() ::= <<
|
||||
|
||||
def resetAcceptPosition(self, index, line, column):
|
||||
self._input.seek(index)
|
||||
self.line = line
|
||||
self.column = column
|
||||
self._interp.consume(self._input)
|
||||
|
||||
def nextToken(self):
|
||||
if self._interp.__dict__.get("resetAcceptPosition", None) is None:
|
||||
self._interp.__dict__["resetAcceptPosition"] = self.resetAcceptPosition
|
||||
return super(type(self),self).nextToken()
|
||||
|
||||
def emit(self):
|
||||
if self._type==PositionAdjustingLexer.TOKENS:
|
||||
self.handleAcceptPositionForKeyword("tokens")
|
||||
elif self._type==PositionAdjustingLexer.LABEL:
|
||||
self.handleAcceptPositionForIdentifier()
|
||||
return super(type(self),self).emit()
|
||||
|
||||
def handleAcceptPositionForIdentifier(self):
|
||||
tokenText = self.text
|
||||
identifierLength = 0
|
||||
while identifierLength \< len(tokenText) and self.isIdentifierChar(tokenText[identifierLength]):
|
||||
identifierLength += 1
|
||||
|
||||
if self._input.index > self._tokenStartCharIndex + identifierLength:
|
||||
offset = identifierLength - 1
|
||||
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
|
||||
self._tokenStartLine, self._tokenStartColumn + offset)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def handleAcceptPositionForKeyword(self, keyword):
|
||||
if self._input.index > self._tokenStartCharIndex + len(keyword):
|
||||
offset = len(keyword) - 1
|
||||
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
|
||||
self._tokenStartLine, self._tokenStartColumn + offset)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def isIdentifierChar(c):
|
||||
return c.isalnum() or c == '_'
|
||||
|
||||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
@parser::members {
|
||||
class LeafListener(MockListener):
|
||||
def visitTerminal(self, node):
|
||||
print(node.symbol.text)
|
||||
}
|
||||
>>
|
||||
|
||||
WalkListener(s) ::= <<
|
||||
if __name__ is not None and "." in __name__:
|
||||
from .TListener import TListener
|
||||
else:
|
||||
from TListener import TListener
|
||||
TParser.LeafListener.__bases__ = (TListener,)
|
||||
walker = ParseTreeWalker()
|
||||
walker.walk(TParser.LeafListener(), <s>)
|
||||
>>
|
||||
|
||||
TreeNodeWithAltNumField(X) ::= <<
|
||||
@parser::members {
|
||||
class MyRuleNode(ParserRuleContext):
|
||||
def __init__(self, parent:ParserRuleContext = None, invokingStateNumber:int = None ):
|
||||
super(<X>Parser.MyRuleNode, self).__init__(parent, invokingStateNumber)
|
||||
self.altNum = 0;
|
||||
def getAltNumber(self):
|
||||
return self.altNum
|
||||
def setAltNumber(self, altNum):
|
||||
self.altNum = altNum
|
||||
}
|
||||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
class LeafListener(MockListener):
|
||||
def exitA(self, ctx):
|
||||
if ctx.getChildCount()==2:
|
||||
print(ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + str_list(ctx.INT()))
|
||||
else:
|
||||
print(str(ctx.ID().symbol))
|
||||
}
|
||||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
@parser::members {
|
||||
class LeafListener(MockListener):
|
||||
def exitA(self, ctx):
|
||||
if ctx.getChildCount()==2:
|
||||
print(ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text)
|
||||
else:
|
||||
print(ctx.b(0).start.text)
|
||||
}
|
||||
>>
|
||||
|
||||
|
||||
LRListener(X) ::= <<
|
||||
@parser::members {
|
||||
class LeafListener(MockListener):
|
||||
def exitE(self, ctx):
|
||||
if ctx.getChildCount()==3:
|
||||
print(ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text)
|
||||
else:
|
||||
print(ctx.INT().symbol.text)
|
||||
}
|
||||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
@parser::members {
|
||||
class LeafListener(MockListener):
|
||||
def exitCall(self, ctx):
|
||||
print(ctx.e().start.text + ' ' + str(ctx.eList()))
|
||||
def exitInt(self, ctx):
|
||||
print(ctx.INT().symbol.text)
|
||||
}
|
||||
>>
|
||||
|
||||
ImportVisitor(X) ::= ""
|
||||
BasicVisitor(X) ::= ""
|
||||
WalkVisitor(s) ::= ""
|
||||
LRWithLabelsVisitor(X) ::= ""
|
||||
RuleGetterVisitor(X) ::= ""
|
||||
LRVisitor(x) ::= ""
|
||||
TokenGetterVisitor(x) ::= ""
|
||||
|
||||
DeclareContextListGettersFunction() ::= <<
|
||||
def foo():
|
||||
s = SContext()
|
||||
a = s.a()
|
||||
b = s.b()
|
||||
>>
|
||||
|
||||
Declare_foo() ::= <<def foo(self):
|
||||
print('foo')
|
||||
>>
|
||||
|
||||
Invoke_foo() ::= "self.foo()"
|
||||
|
||||
Declare_pred() ::= <<def pred(self, v):
|
||||
print('eval=' + str(v).lower())
|
||||
return v
|
||||
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<self.pred(<v>)>>
|
||||
ParserTokenType(t) ::= "Parser.<t>"
|
||||
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
|
||||
StringType() ::= "String"
|
||||
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
|
|
@ -1,34 +0,0 @@
|
|||
TestType() ::= "CompositeLexer"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Input() ::= "abc"
|
||||
|
||||
Output() ::= <<
|
||||
S.A
|
||||
[@0,0:0='a',\<3>,1:0]
|
||||
[@1,1:1='b',\<1>,1:1]
|
||||
[@2,2:2='c',\<4>,1:2]
|
||||
[@3,3:2='\<EOF>',\<-1>,1:3]<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
lexer grammar <grammarName>;
|
||||
import S;
|
||||
B : 'b';
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
lexer grammar <grammarName>;
|
||||
A : 'a' {<writeln("\"S.A\"")>};
|
||||
C : 'c' ;
|
||||
>>
|
|
@ -1,32 +0,0 @@
|
|||
TestType() ::= "CompositeLexer"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Input() ::= "ab"
|
||||
|
||||
Output() ::= <<
|
||||
M.A
|
||||
[@0,0:1='ab',\<1>,1:0]
|
||||
[@1,2:1='\<EOF>',\<-1>,1:2]<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
lexer grammar <grammarName>;
|
||||
import S;
|
||||
A : 'a' B {<writeln("\"M.A\"")>} ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
lexer grammar <grammarName>;
|
||||
A : 'a' {<writeln("\"S.A\"")>} ;
|
||||
B : 'b' {<writeln("\"S.B\"")>} ;
|
||||
>>
|
|
@ -1,31 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "=a"
|
||||
|
||||
Output() ::= <<
|
||||
S.a<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
s : a ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a : '=' 'a' {<write("\"S.a\"")>};
|
||||
>>
|
|
@ -1,40 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
AfterGrammar() ::= <<
|
||||
writeFile(tmpdir, "M.g4", grammar);
|
||||
ErrorQueue equeue = new ErrorQueue();
|
||||
new Grammar(tmpdir+"/M.g4", grammar, equeue);
|
||||
assertEquals("unexpected errors: " + equeue, 0, equeue.errors.size());<\n>
|
||||
>>
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "x 34 9"
|
||||
|
||||
Output() ::= <<
|
||||
S.x<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
s : x INT;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
tokens { A, B, C }
|
||||
x : 'x' INT {<writeln("\"S.x\"")>};
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
|
@ -1,66 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", ["S", "T"])>}
|
||||
]
|
||||
|
||||
AfterGrammar() ::= <<
|
||||
writeFile(tmpdir, "M.g4", grammar);
|
||||
ErrorQueue equeue = new ErrorQueue();
|
||||
Grammar g = new Grammar(tmpdir+"/M.g4", grammar, equeue);
|
||||
String expectedTokenIDToTypeMap = "{EOF=-1, B=1, A=2, C=3, WS=4}";
|
||||
String expectedStringLiteralToTypeMap = "{'a'=2, 'b'=1, 'c'=3}";
|
||||
String expectedTypeToTokenList = "[B, A, C, WS]";
|
||||
assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString());
|
||||
assertEquals(expectedStringLiteralToTypeMap, sort(g.stringLiteralToTypeMap).toString());
|
||||
assertEquals(expectedTypeToTokenList, realElements(g.typeToTokenList).toString());
|
||||
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());<\n>
|
||||
>>
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammarS("S")>},
|
||||
"T": {<slaveGrammarT("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "aa"
|
||||
|
||||
Output() ::= <<
|
||||
S.x
|
||||
T.y<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
// The lexer will create rules to match letters a, b, c.
|
||||
// The associated token types A, B, C must have the same value
|
||||
// and all import'd parsers. Since ANTLR regenerates all imports
|
||||
// for use with the delegator M, it can generate the same token type
|
||||
// mapping in each parser:
|
||||
// public static final int C=6;
|
||||
// public static final int EOF=-1;
|
||||
// public static final int B=5;
|
||||
// public static final int WS=7;
|
||||
// public static final int A=4;
|
||||
grammar M;
|
||||
import S,T;
|
||||
s : x y ; // matches AA, which should be 'aa'
|
||||
B : 'b' ; // another order: B, A, C
|
||||
A : 'a' ;
|
||||
C : 'c' ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammarS(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
tokens { A, B, C }
|
||||
x : A {<writeln("\"S.x\"")>};
|
||||
>>
|
||||
|
||||
slaveGrammarT(grammarName) ::= <<
|
||||
parser grammar T;
|
||||
tokens { C, B, A } // reverse order
|
||||
y : A {<writeln("\"T.y\"")>};
|
||||
>>
|
|
@ -1,34 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "b"
|
||||
|
||||
Output() ::= <<
|
||||
foo<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M; // uses no rules from the import
|
||||
import S;
|
||||
s : 'b' {<Invoke_foo()>} ; // gS is import pointer
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
@parser::members {
|
||||
<Declare_foo()>
|
||||
}
|
||||
a : B;
|
||||
>>
|
|
@ -1,32 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "b"
|
||||
|
||||
Output() ::= <<
|
||||
S.a<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
s : a ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a : B {<writeln("\"S.a\"")>};
|
||||
>>
|
|
@ -1,32 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "b"
|
||||
|
||||
Output() ::= <<
|
||||
S.a1000<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
s : label=a[3] {<writeln("$label.y")>} ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a[int x] returns [int y] : B {<write("\"S.a\"")>} {$y=1000;} ;
|
||||
>>
|
|
@ -1,32 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "b"
|
||||
|
||||
Output() ::= <<
|
||||
S.ab<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
s : a {<write("$a.text")>} ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a : B {<write("\"S.a\"")>} ;
|
||||
>>
|
|
@ -1,39 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", ["S", "T"])>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammarS("S")>},
|
||||
"T": {<slaveGrammarT("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "b"
|
||||
|
||||
Output() ::= <<
|
||||
S.a<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S,T;
|
||||
s : a ;
|
||||
B : 'b' ; // defines B from inherited token space
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammarS(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a : b {<writeln("\"S.a\"")>};
|
||||
b : B;
|
||||
>>
|
||||
|
||||
slaveGrammarT(grammarName) ::= <<
|
||||
parser grammar T;
|
||||
a : B {<writeln("\"T.a\"")>};<! hidden by S.a !>
|
||||
>>
|
|
@ -1,32 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Input() ::= "c"
|
||||
|
||||
Output() ::= <<
|
||||
S.a<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
b : 'b'|'c';
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a : b {<write("\"S.a\"")>};
|
||||
b : B ;
|
||||
>>
|
|
@ -1,40 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammarS("S")>},
|
||||
"T": {<slaveGrammarT("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Input() ::= "c"
|
||||
|
||||
Output() ::= <<
|
||||
M.b
|
||||
S.a<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S, T;
|
||||
b : 'b'|'c' {<writeln("\"M.b\"")>}|B|A;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammarS(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a : b {<writeln("\"S.a\"")>};
|
||||
b : 'b' ;
|
||||
>>
|
||||
|
||||
slaveGrammarT(grammarName) ::= <<
|
||||
parser grammar T;
|
||||
tokens { A }
|
||||
b : 'b' {<writeln("\"T.b\"")>};
|
||||
>>
|
|
@ -1,38 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "prog"
|
||||
|
||||
Input() ::= "float x = 3;"
|
||||
|
||||
Output() ::= <<
|
||||
JavaDecl: floatx=3;<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
// for float to work in decl, type must be overridden
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
prog : decl ;
|
||||
type_ : 'int' | 'float' ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
type_ : 'int' ;
|
||||
decl : type_ ID ';'
|
||||
| type_ ID init_ ';' {<write("\"JavaDecl: \" + $text")>};
|
||||
init_ : '=' INT;
|
||||
>>
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* This is a regression test for antlr/antlr4#248 "Including grammar with only
|
||||
* fragments breaks generated lexer".
|
||||
* https://github.com/antlr/antlr4/issues/248
|
||||
*/
|
||||
|
||||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"Test": {<masterGrammar("Test", "Unicode")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"Unicode": {<slaveGrammar("Unicode")>}
|
||||
]
|
||||
|
||||
Rule() ::= "program"
|
||||
|
||||
Input() ::= "test test"
|
||||
|
||||
Output() ::= <<
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
import Unicode;
|
||||
|
||||
program : 'test' 'test';
|
||||
|
||||
WS : (UNICODE_CLASS_Zs)+ -> skip;
|
||||
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
lexer grammar <grammarName>;
|
||||
|
||||
fragment
|
||||
UNICODE_CLASS_Zs : '\u0020' | '\u00A0' | '\u1680' | '\u180E'
|
||||
| '\u2000'..'\u200A'
|
||||
| '\u202F' | '\u205F' | '\u3000'
|
||||
;
|
||||
|
||||
>>
|
|
@ -1,32 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "b"
|
||||
|
||||
Output() ::= <<
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
s : a ;
|
||||
B : 'b' ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
options {}
|
||||
a : B ;
|
||||
>>
|
|
@ -1,32 +0,0 @@
|
|||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Input() ::= "b"
|
||||
|
||||
Output() ::= <<
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
s : a;
|
||||
B : 'b';
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
// wasn't terminating. @after was injected into M as if it were @members
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
parser grammar S;
|
||||
a @after {<InitIntMember("x","0")>} : B;
|
||||
>>
|
|
@ -1,37 +0,0 @@
|
|||
// rules in lexer are imported at END so rules in master override
|
||||
// *and* get priority over imported rules. So importing ID doesn't
|
||||
// mess up keywords in master grammar
|
||||
|
||||
TestType() ::= "CompositeParser"
|
||||
|
||||
Grammar ::= [
|
||||
"M": {<masterGrammar("M", "S")>}
|
||||
]
|
||||
|
||||
SlaveGrammars ::= [
|
||||
"S": {<slaveGrammar("S")>}
|
||||
]
|
||||
|
||||
Rule() ::= "a"
|
||||
|
||||
Input() ::= "abc"
|
||||
|
||||
Output() ::= <<
|
||||
M.A
|
||||
M.a: [@0,0:2='abc',\<1>,1:0]<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
||||
|
||||
masterGrammar(grammarName, slaveGrammarName) ::= <<
|
||||
grammar M;
|
||||
import S;
|
||||
a : A {<Append("\"M.a: \"","$A"):writeln()>};
|
||||
A : 'abc' {<writeln("\"M.A\"")>};
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
||||
|
||||
slaveGrammar(grammarName) ::= <<
|
||||
lexer grammar S;
|
||||
ID : 'a'..'z'+;
|
||||
>>
|
|
@ -1,30 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "abc"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 0:
|
||||
s0-ID->:s1^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:0 reportAttemptingFullContext d=0 (s), input='abc'<\n>
|
||||
>>
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: ID | ID {} ;
|
||||
ID : 'a'..'z'+;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
||||
>>
|
|
@ -1,39 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "a@"
|
||||
|
||||
Rule() ::= "prog"
|
||||
|
||||
Output() ::= <<
|
||||
alt 1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:2 reportAttemptingFullContext d=0 (prog), input='a@'
|
||||
line 1:2 reportAmbiguity d=0 (prog): ambigAlts={1, 2}, input='a@'
|
||||
line 1:2 reportAttemptingFullContext d=1 (expr), input='a@'
|
||||
line 1:2 reportContextSensitivity d=1 (expr), input='a@'<\n>
|
||||
>>
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
prog
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
: expr expr {<writeln("\"alt 1\"")>}
|
||||
| expr
|
||||
;
|
||||
expr: '@'
|
||||
| ID '@'
|
||||
| ID
|
||||
;
|
||||
ID : [a-z]+ ;
|
||||
WS : [ \r\n\t]+ -> skip ;
|
||||
>>
|
|
@ -1,23 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: '$' a | '@' b ;
|
||||
a : e ID ;
|
||||
b : e INT ID ;
|
||||
e : INT | ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
||||
>>
|
|
@ -1,39 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
|
||||
Input() ::= "$ 34 abc @ 34 abc"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 2:
|
||||
s0-INT->s1
|
||||
s1-ID->:s2^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:5 reportAttemptingFullContext d=2 (e), input='34abc'
|
||||
line 1:2 reportContextSensitivity d=2 (e), input='34'
|
||||
line 1:14 reportAttemptingFullContext d=2 (e), input='34abc'
|
||||
line 1:14 reportContextSensitivity d=2 (e), input='34abc'<\n>
|
||||
>>
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: ('$' a | '@' b)+ ;
|
||||
a : e ID ;
|
||||
b : e INT ID ;
|
||||
e : INT | ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
||||
>>
|
|
@ -1,14 +0,0 @@
|
|||
import "CtxSensitiveDFA.stg"
|
||||
|
||||
Input() ::= "$ 34 abc"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-INT->s1
|
||||
s1-ID->:s2^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:5 reportAttemptingFullContext d=1 (e), input='34abc'
|
||||
line 1:2 reportContextSensitivity d=1 (e), input='34'<\n>
|
||||
>>
|
|
@ -1,14 +0,0 @@
|
|||
import "CtxSensitiveDFA.stg"
|
||||
|
||||
Input() ::= "@ 34 abc"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-INT->s1
|
||||
s1-ID->:s2^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:5 reportAttemptingFullContext d=1 (e), input='34abc'
|
||||
line 1:5 reportContextSensitivity d=1 (e), input='34abc'<\n>
|
||||
>>
|
|
@ -1,28 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
: expr[0] {<ToStringTree("$expr.ctx"):writeln()>};
|
||||
expr[int _p]
|
||||
: ID
|
||||
(
|
||||
{5 >= $_p}? '*' expr[6]
|
||||
| {4 >= $_p}? '+' expr[5]
|
||||
)*
|
||||
;
|
||||
ID : [a-zA-Z]+ ;
|
||||
WS : [ \r\n\t]+ -> skip ;
|
||||
|
||||
>>
|
|
@ -1,12 +0,0 @@
|
|||
import "ExprAmbiguity.stg"
|
||||
|
||||
Input() ::= "a+b"
|
||||
|
||||
Output() ::= <<
|
||||
(expr a + (expr b))<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:1 reportAttemptingFullContext d=1 (expr), input='+'
|
||||
line 1:2 reportContextSensitivity d=1 (expr), input='+b'<\n>
|
||||
>>
|
|
@ -1,14 +0,0 @@
|
|||
import "ExprAmbiguity.stg"
|
||||
|
||||
Input() ::= "a+b*c"
|
||||
|
||||
Output() ::= <<
|
||||
(expr a + (expr b * (expr c)))<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:1 reportAttemptingFullContext d=1 (expr), input='+'
|
||||
line 1:2 reportContextSensitivity d=1 (expr), input='+b'
|
||||
line 1:3 reportAttemptingFullContext d=1 (expr), input='*'
|
||||
line 1:5 reportAmbiguity d=1 (expr): ambigAlts={1, 2}, input='*c'<\n>
|
||||
>>
|
|
@ -1,24 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
@after {<DumpDFA()>}
|
||||
: '{' stat* '}' ;
|
||||
stat: 'if' ID 'then' stat ('else' ID)?
|
||||
| 'return'
|
||||
;
|
||||
ID : 'a'..'z'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
||||
>>
|
|
@ -1,10 +0,0 @@
|
|||
import "FullContextIF_THEN_ELSEParse.stg"
|
||||
|
||||
Input() ::= "{ if x then return }"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-'}'->:s1=>2<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,20 +0,0 @@
|
|||
import "FullContextIF_THEN_ELSEParse.stg"
|
||||
|
||||
Input() ::= "{ if x then return else foo }"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-'else'->:s1^=>1<\n>
|
||||
>>
|
||||
|
||||
// Technically, this input sequence is not ambiguous because else
|
||||
// uniquely predicts going into the optional subrule. else cannot
|
||||
// be matched by exiting stat since that would only match '}' or
|
||||
// the start of a stat. But, we are using the theory that
|
||||
// SLL(1)=LL(1) and so we are avoiding full context parsing
|
||||
// by declaring all else clause parsing to be ambiguous.
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:19 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 1:19 reportContextSensitivity d=1 (stat), input='else'<\n>
|
||||
>>
|
|
@ -1,14 +0,0 @@
|
|||
import "FullContextIF_THEN_ELSEParse.stg"
|
||||
|
||||
Input() ::= "{ if x then if y then return else foo }"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-'}'->:s2=>2
|
||||
s0-'else'->:s1^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:29 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 1:38 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'<\n>
|
||||
>>
|
|
@ -1,19 +0,0 @@
|
|||
import "FullContextIF_THEN_ELSEParse.stg"
|
||||
|
||||
// should not be ambiguous because the second 'else bar' clearly
|
||||
// indicates that the first else should match to the innermost if.
|
||||
// LL_EXACT_AMBIG_DETECTION makes us keep going to resolve
|
||||
|
||||
Input() ::= "{ if x then if y then return else foo else bar }"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-'else'->:s1^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:29 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 1:38 reportContextSensitivity d=1 (stat), input='elsefooelse'
|
||||
line 1:38 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 1:38 reportContextSensitivity d=1 (stat), input='else'<\n>
|
||||
>>
|
|
@ -1,19 +0,0 @@
|
|||
import "FullContextIF_THEN_ELSEParse.stg"
|
||||
|
||||
Input() ::= <<
|
||||
{ if x then return else foo
|
||||
if x then if y then return else foo }
|
||||
>>
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-'}'->:s2=>2
|
||||
s0-'else'->:s1^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:19 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 1:19 reportContextSensitivity d=1 (stat), input='else'
|
||||
line 2:27 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 2:36 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'<\n>
|
||||
>>
|
|
@ -1,19 +0,0 @@
|
|||
import "FullContextIF_THEN_ELSEParse.stg"
|
||||
|
||||
Input() ::= <<
|
||||
{ if x then return else foo
|
||||
if x then if y then return else foo }
|
||||
>>
|
||||
|
||||
Output() ::= <<
|
||||
Decision 1:
|
||||
s0-'}'->:s2=>2
|
||||
s0-'else'->:s1^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:19 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 1:19 reportContextSensitivity d=1 (stat), input='else'
|
||||
line 2:27 reportAttemptingFullContext d=1 (stat), input='else'
|
||||
line 2:36 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'<\n>
|
||||
>>
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Tests predictions for the following case involving closures.
|
||||
* http://www.antlr.org/wiki/display/~admin/2011/12/29/Flaw+in+ANTLR+v3+LL(*)+analysis+algorithm
|
||||
*/
|
||||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "a(i)\<-x"
|
||||
|
||||
Rule() ::= "prog"
|
||||
|
||||
Output() ::= <<
|
||||
pass: a(i)\<-x<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:3 reportAttemptingFullContext d=3 (expr_primary), input='a(i)'
|
||||
line 1:7 reportAmbiguity d=3 (expr_primary): ambigAlts={2, 3}, input='a(i)\<-x'<\n>
|
||||
>>
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
prog
|
||||
@init {<LL_EXACT_AMBIG_DETECTION()>}
|
||||
: expr_or_assign*;
|
||||
expr_or_assign
|
||||
: expr '++' {<writeln("\"fail.\"")>}
|
||||
| expr {<writeln("\"pass: \"+$expr.text")>}
|
||||
;
|
||||
expr: expr_primary ('\<-' ID)?;
|
||||
expr_primary
|
||||
: '(' ID ')'
|
||||
| ID '(' ID ')'
|
||||
| ID
|
||||
;
|
||||
ID : [a-z]+ ;
|
||||
>>
|
|
@ -1,36 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Input() ::= "34 abc"
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
Output() ::= <<
|
||||
Decision 0:
|
||||
s0-INT->s1
|
||||
s1-ID->:s2^=>1<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= <<
|
||||
line 1:3 reportAttemptingFullContext d=0 (e), input='34abc'
|
||||
line 1:0 reportContextSensitivity d=0 (e), input='34'<\n>
|
||||
>>
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s @after {<DumpDFA()>}
|
||||
: a;
|
||||
a : e ID ;
|
||||
b : e INT ID ;
|
||||
e : INT | ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\t'|'\n')+ -> skip ;
|
||||
>>
|
|
@ -1,156 +0,0 @@
|
|||
TestFile(file) ::= <<
|
||||
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
package org.antlr.v4.test.runtime.<if(file.targetSubdir)><file.targetSubdir>.<endif><file.target; format="lower">;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.antlr.v4.test.runtime.java.ErrorQueue;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class Test<file.name> extends Base<file.target>Test {
|
||||
|
||||
<file.tests:{test | <test>}; separator="\n", wrap, anchor>
|
||||
|
||||
}
|
||||
>>
|
||||
|
||||
LexerTestMethod(test) ::= <<
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void test<test.name>() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
<test.SlaveGrammars:{grammar |
|
||||
String slave_<grammar> = <writeStringLiteral(test.SlaveGrammars.(grammar))>;
|
||||
writeFile(tmpdir, "<grammar>.g4", slave_<grammar>);
|
||||
}; separator="\n">
|
||||
<test.Grammar:{grammar |
|
||||
<buildStringLiteral(test.Grammar.(grammar), "grammar")>
|
||||
|
||||
<if(test.AfterGrammar)>
|
||||
<test.AfterGrammar>
|
||||
<endif>
|
||||
String input =<writeStringLiteral(test.Input)>;
|
||||
String found = execLexer("<grammar>.g4", grammar, "<grammar><if(test.Options.("CombinedGrammar"))>Lexer<endif>", input, <writeBoolean(test.Options.("ShowDFA"))>);
|
||||
assertEquals(<writeStringLiteral(test.Output)>, found);
|
||||
<if(!isEmpty.(test.Errors))>
|
||||
assertEquals(<writeStringLiteral(test.Errors)>, this.stderrDuringParse);
|
||||
<else>
|
||||
assertNull(this.stderrDuringParse);
|
||||
<endif>
|
||||
}>
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
CompositeLexerTestMethod(test) ::= <<
|
||||
<LexerTestMethod(test)>
|
||||
>>
|
||||
|
||||
ParserTestMethod(test) ::= <<
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
public void test<test.name>() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
|
||||
<test.SlaveGrammars:{grammar |
|
||||
String slave_<grammar> =<writeStringLiteral(test.SlaveGrammars.(grammar))>;
|
||||
<if(test.Options.("SlaveIsLexer"))>
|
||||
rawGenerateAndBuildRecognizer("<grammar>.g4", slave_<grammar>, null, "<grammar>");
|
||||
<else>
|
||||
writeFile(tmpdir, "<grammar>.g4", slave_<grammar>);
|
||||
<endif>
|
||||
}; separator="\n">
|
||||
|
||||
<test.Grammar:{grammar |
|
||||
<buildStringLiteral(test.Grammar.(grammar), "grammar")>
|
||||
|
||||
<test.AfterGrammar>
|
||||
|
||||
String input =<writeStringLiteral(test.Input)>;
|
||||
String found = execParser("<grammar>.g4", grammar, "<grammar><if(!test.SlaveIsLexer)>Parser<endif>", "<if(test.SlaveIsLexer)><first(test.SlaveGrammars).grammarName><else><grammar>Lexer<endif>", "<grammar>Listener", "<grammar>Visitor", "<test.Rule>", input, <writeBoolean(test.Options.("Debug"))>);
|
||||
|
||||
assertEquals(<writeStringLiteral(test.Output)>, found);
|
||||
<if(!isEmpty.(test.Errors))>
|
||||
assertEquals(<writeStringLiteral(test.Errors)>, this.stderrDuringParse);
|
||||
<else>
|
||||
assertNull(this.stderrDuringParse);
|
||||
<endif>
|
||||
}>
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
IgnoredTestMethod(test) ::= <<
|
||||
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
|
||||
@Test
|
||||
@Ignore("true")
|
||||
public void test<test.name>() throws Exception {
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
CompositeParserTestMethod(test) ::= <<
|
||||
<ParserTestMethod(test)>
|
||||
>>
|
||||
|
||||
AbstractParserTestMethod(test) ::= <<
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
String test<test.name>(String input) throws Exception {
|
||||
String grammar = <test.grammar.lines:{ line | "<line>};separator="\\n\" +\n", wrap, anchor>";
|
||||
return execParser("<test.grammar.grammarName>.g4", grammar, "<test.grammar.grammarName>Parser", "<test.grammar.grammarName>Lexer", "<test.startRule>", input, <test.debug>);
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
ConcreteParserTestMethod(test) ::= <<
|
||||
/* this file and method are generated, any edit will be overwritten by the next generation */
|
||||
@Test
|
||||
public void test<test.name>() throws Exception {
|
||||
String found = test<test.baseName>("<test.input>");
|
||||
assertEquals("<test.expectedOutput>", found);
|
||||
<if(test.expectedErrors)>
|
||||
assertEquals("<test.expectedErrors>", this.stderrDuringParse);
|
||||
<else>
|
||||
assertNull(this.stderrDuringParse);
|
||||
<endif>
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
buildStringLiteral(text, variable) ::= <<
|
||||
StringBuilder <variable>Builder = new StringBuilder(<strlen.(text)>);
|
||||
<lines.(text):{line|<variable>Builder.append("<escape.(line)>");}; separator="\n">
|
||||
String <variable> = <variable>Builder.toString();
|
||||
>>
|
||||
|
||||
writeStringLiteral(text) ::= <%
|
||||
<if(isEmpty.(text))>
|
||||
""
|
||||
<else>
|
||||
<writeLines(lines.(text))>
|
||||
<endif>
|
||||
%>
|
||||
|
||||
writeLines(textLines) ::= <%
|
||||
<if(rest(textLines))>
|
||||
<textLines:{line|
|
||||
<\n> "<escape.(line)>}; separator="\" +">"
|
||||
<else>
|
||||
"<escape.(first(textLines))>"
|
||||
<endif>
|
||||
%>
|
||||
|
||||
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
|
||||
|
||||
string(text) ::= <<
|
||||
"<escape.(text)>"
|
||||
>>
|
||||
|
||||
isEmpty ::= [
|
||||
"": true,
|
||||
default: false
|
||||
]
|
|
@ -1,35 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": true
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"Expr": {<grammar("Expr")>}
|
||||
]
|
||||
|
||||
Rule() ::= "prog"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
prog: stat ;
|
||||
stat: expr NEWLINE # printExpr
|
||||
| ID '=' expr NEWLINE # assign
|
||||
| NEWLINE # blank
|
||||
;
|
||||
expr: expr ('*'|'/') expr # MulDiv
|
||||
| expr ('+'|'-') expr # AddSub
|
||||
| INT # int
|
||||
| ID # id
|
||||
| '(' expr ')' # parens
|
||||
;
|
||||
|
||||
MUL : '*' ; // assigns token name to '*' used above in grammar
|
||||
DIV : '/' ;
|
||||
ADD : '+' ;
|
||||
SUB : '-' ;
|
||||
ID : [a-zA-Z]+ ; // match identifiers
|
||||
INT : [0-9]+ ; // match integers
|
||||
NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal)
|
||||
WS : [ \t]+ -> skip ; // toss out whitespace
|
||||
>>
|
|
@ -1,7 +0,0 @@
|
|||
import "AmbigLR.stg"
|
||||
|
||||
Input() ::= "1<\n>"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,7 +0,0 @@
|
|||
import "AmbigLR.stg"
|
||||
|
||||
Input() ::= "a = 5<\n>"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,7 +0,0 @@
|
|||
import "AmbigLR.stg"
|
||||
|
||||
Input() ::= "b = 6<\n>"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,7 +0,0 @@
|
|||
import "AmbigLR.stg"
|
||||
|
||||
Input() ::= "a+b*2<\n>"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,7 +0,0 @@
|
|||
import "AmbigLR.stg"
|
||||
|
||||
Input() ::= "(1+2)*3<\n>"
|
||||
|
||||
Output() ::= ""
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,28 +0,0 @@
|
|||
TestType() ::= "Parser"
|
||||
|
||||
Options ::= [
|
||||
"Debug": false
|
||||
]
|
||||
|
||||
Grammar ::= [
|
||||
"T": {<grammar("T")>}
|
||||
]
|
||||
|
||||
Rule() ::= "s"
|
||||
|
||||
grammar(grammarName) ::= <<
|
||||
grammar <grammarName>;
|
||||
s @after {<ToStringTree("$ctx"):writeln()>} : declarator EOF ; // must indicate EOF can follow
|
||||
declarator
|
||||
: declarator '[' e ']'
|
||||
| declarator '[' ']'
|
||||
| declarator '(' ')'
|
||||
| '*' declarator // binds less tight than suffixes
|
||||
| '(' declarator ')'
|
||||
| ID
|
||||
;
|
||||
e : INT ;
|
||||
ID : 'a'..'z'+ ;
|
||||
INT : '0'..'9'+ ;
|
||||
WS : (' '|'\n') -> skip ;
|
||||
>>
|
|
@ -1,9 +0,0 @@
|
|||
import "Declarations.stg"
|
||||
|
||||
Input() ::= "a"
|
||||
|
||||
Output() ::= <<
|
||||
(s (declarator a) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,9 +0,0 @@
|
|||
import "Declarations.stg"
|
||||
|
||||
Input() ::= "(*a)[]"
|
||||
|
||||
Output() ::= <<
|
||||
(s (declarator (declarator ( (declarator * (declarator a)) )) [ ]) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,9 +0,0 @@
|
|||
import "Declarations.stg"
|
||||
|
||||
Input() ::= "*a"
|
||||
|
||||
Output() ::= <<
|
||||
(s (declarator * (declarator a)) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,9 +0,0 @@
|
|||
import "Declarations.stg"
|
||||
|
||||
Input() ::= "**a"
|
||||
|
||||
Output() ::= <<
|
||||
(s (declarator * (declarator * (declarator a))) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
|
@ -1,9 +0,0 @@
|
|||
import "Declarations.stg"
|
||||
|
||||
Input() ::= "a[3]"
|
||||
|
||||
Output() ::= <<
|
||||
(s (declarator (declarator a) [ (e 3) ]) \<EOF>)<\n>
|
||||
>>
|
||||
|
||||
Errors() ::= ""
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue