Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar Remake #342

Merged
merged 24 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
2d5a9b2
Moved hermes grammars and parsers under their own directory
patmagee Nov 20, 2019
432a042
Added Antlr4 grammars and parsers
patmagee Nov 20, 2019
d65b0d8
Fixed spelling mistakes
patmagee Nov 20, 2019
a5b761f
fixed typo in call body input token
patmagee Nov 20, 2019
a3e115f
allowed expressions within map literal keys
patmagee Nov 20, 2019
c7b917b
Added missing keywords and call after
patmagee Nov 20, 2019
7e80756
switched ordering of call_afters rule with call_alias
patmagee Nov 20, 2019
aaa59d3
Fixed interpolation lexing
patmagee Nov 21, 2019
5aed036
Added some additional rudimentary java tests
patmagee Nov 21, 2019
cb65e06
Removed Python2 references
patmagee Nov 22, 2019
f2e6fbb
Backported grammar changes to 1.0
patmagee Feb 19, 2020
48e0e44
Fixed some ambguities with the dev grammar
patmagee Feb 19, 2020
58e4998
Fixed versions of parsers
patmagee Feb 19, 2020
eb3584f
Added example listener
patmagee Feb 19, 2020
30ed6c8
refactored to remove language specific parser code and base lexer
patmagee Feb 20, 2020
d001b8c
fixed support for unirary operation in expression
patmagee Feb 20, 2020
f647be0
condenses unirary signed rule into a single line
patmagee Feb 20, 2020
96903ef
made task_command rule easier for visitors to handle
patmagee Mar 6, 2020
45a2661
made string command easier for visitors to parse
patmagee Mar 6, 2020
b47240d
fixed version parsing and typo
patmagee Mar 7, 2020
76a5299
Resolved several ambiguities with grammar and fixed object literal no…
patmagee Mar 10, 2020
7faa515
Fixed import statement to allow unnamed imports
patmagee Mar 10, 2020
2d5b5d6
Fixed ambiguity with identifiers
patmagee Mar 11, 2020
0a8b0b8
Added EOF to document rule
patmagee Mar 11, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions versions/development/parsers/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Parsers for WDL
# Grammars and Parsers

This directory contains pregenerated parsers for WDL in a variety of languages. Except for the Java parser, all of these are provided *as-is*. We believe that they work but do not have the resources to validate that claim. However if you're willing to help us fix any issues you come across we'll work with you to do so."
At the moment, WDL is transitioning away from `Hermes` as its primary grammar definition and parser generation tool and moving
towards [Antlr4](https://www.antlr.org/). The motivation for this transition was to provide a grammar language which would
be more familiar to more people as well as employing a well supported and actively developed tool for generating the parsers.
Antlr4 grammars are written as an EBNF and the tool itself supports 9 different target languages currently.

# How to rebuild

Typing `make` in this directory will trigger builds for all of the languages and produce the appropriate files. This requires you to have [Hermes](https://github.com/scottfrazer/hermes) installed on your system. To do this you might need to use a virtualenv, e.g. ``mkvirtualenv py3 -p `which python3` ``
Please note that hermes grammars will be removed from the specification at some point in the future, and this feature should
be considered deprecated.

16 changes: 16 additions & 0 deletions versions/development/parsers/antlr4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.interp
*.tokens
WdlLexer.py
WdlParser.py
WdlParserListener.py
WdlParserVisitor.py
WdlLexer.js
WdlParser.js
WdlParserListener.js
WdlParserVisitor.js
WdlLexerPython.py
target/
.idea/
*.jar
node_modules/
build/
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;

public class MavenWrapperDownloader {

private static final String WRAPPER_VERSION = "0.5.5";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar
22 changes: 22 additions & 0 deletions versions/development/parsers/antlr4/Java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# WDL Java Parser

This directory provides a parser implemented in java. The parser is built on top of the Base [WDLBaseLexer.java](src/main/java/org/openwdl/wdl/parser/WDLBaseLexer.java)

# Requirements
- Java 7+

# Building

Building the project can be accomplished using the packaged maven wrapper.

```bash
./mvnw -DskipTests clean package
```

# Running tests

There are a number of tests which can be run using surefire.

```bash
./mvnw test
```
Loading