Skip to content

Commit

Permalink
adapt to changed project name
Browse files Browse the repository at this point in the history
  • Loading branch information
GuntherRademacher committed Jan 17, 2024
1 parent 6e0964c commit 1252306
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 86 deletions.
8 changes: 1 addition & 7 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="build/generated-src/main/resources">
<attributes>
<attribute name="gradle_scope" value="main"/>
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
<attributes>
Expand Down
4 changes: 2 additions & 2 deletions .project
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>convert</name>
<comment>Project convert created by Buildship.</comment>
<name>ebnf-convert</name>
<comment>Project ebnf-convert created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
Expand Down
82 changes: 68 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,81 @@
# convert - Grammar Converter
# ebnf-convert - Grammar Converter

This is an experimental version of RR - Railroad Diagram Generator, that includes
convert, the Grammar Converter. It builds both an experimental rr.war and convert.war.
This is a tool for converting various forms of BNF and EBNF grammars to [W3C-style EBNF][W3C-EBNF],
which is the notation that is used primarily in the XML and XQuery recommendations. It is
useful for creating syntax diagrams using the [RR][RR] tool, as well as for generating parsers
with [REx Parser Generator][REx].

# Distribution
Input grammars are accepted in these notations:

- [ABNF](https://datatracker.ietf.org/doc/html/rfc5234)
- [ANTLR 3](https://www.antlr3.org/>)
- [ANTLR 4](https://www.antlr.org/)
- [Bison](https://www.gnu.org/software/bison/manual/html_node/Grammar-File.html)
- [GOLD](http://goldparser.org/doc/index.htm)
- [Instaparse](https://github.com/Engelberg/instaparse/blob/master/src/instaparse/cfg.cljc)
- [Invisible XML](https://invisiblexml.org/ixml-specification.html)
- [JavaCC](https://javacc.github.io/javacc/documentation/grammar.html)
- [Jison](https://github.com/zaach/jison)
- [PEG](https://pegjs.org/documentation#grammar-syntax-and-semantics)
- [Xtext](https://eclipse.org/Xtext/documentation/301_grammarlanguage.html)

convert comes in a .war file, convert.war. This can be deployed
in servlet containers like Tomcat or Jetty for serving the GUI, and it makes up the webapp
that is running on the original website, <https://www.bottlecaps.de/convert>.
Besides converting these grammar notations, ebnf-convert can also perform some grammar transformation,
e.g. factorization and elimination of direct recursion. To some extent this transforms BNF to EBNF,
yielding more compact diagrams.

convert.war file is a Java "executable war", i.e. it can also be started
standalone from command line.
ebnf-convert has a simple browser UI as well as a command line interface for batch execution.

# Distribution

For listing the set of available command line options, run
ebnf-convert comes as a `.zip`, containing a `.war` file. The `.war` file can be deployed
in servlet containers like Tomcat or Jetty for serving the browser UI. This makes up the webapp
that is running on the original website, <https://www.bottlecaps.de/ebnf-convert>.

The `.war` file is a Java "executable war", i.e. it can also be started
standalone from command line:

```bash
java -jar convert.war
Usage: java -jar ebnf-convert.war [-xml|-f FACTORING|-r KIND|-noinline|-noepsilon|-v]... GRAMMAR

-xml create output grammar in XML, rather than EBNF
-f FACTORING apply factoring (any of "full-left" (default), "left-only", "full-right", "right-only", or "none")
-r KIND remove direct recursion, where KIND is any of "full" (default), "left", "right", or "none"
-noinline do not inline nonterminals that derive to a single string literal
-noepsilon do not keep nonterminal referemces, that derive to epsilon only
-v verbose output

GRAMMAR path of foreign grammar
```

## Building convert
For building convert, JDK 11 (or higher) must be available. In the
project folder, run this command to build the distribution .zip file:
## Building ebnf-convert
For building ebnf-convert, JDK 11 (or higher) must be available. In the
project folder, run this command to build the distribution `.zip` file in the `build/distributions` folder:

```bash
gradlew
```

## Thanks

This project makes use of
* [Saxon-HE][SAXON],
* [TagSoup][TAGSOUP],
* [Gradle][GRADLE], and
* [Gradle-License-Report][GRADLE-LICENSE-REPORT].

## License

Copyright (c) 2011-2024 Gunther Rademacher. ebnf-convert is provided under the [Apache 2 License][ASL].

## Links

The official website for ebnf-convert is <https://www.bottlecaps.de/ebnf-convert>.

[ASL]: http://www.apache.org/licenses/LICENSE-2.0
[W3C-EBNF]: http://www.w3.org/TR/2010/REC-xquery-20101214/#EBNFNotation
[SAXON]: http://www.saxonica.com/products/products.xml
[TAGSOUP]: https://search.maven.org/artifact/org.ccil.cowan.tagsoup/tagsoup/1.2.1/jar
[GRADLE]: https://gradle.org/
[GRADLE-LICENSE-REPORT]: https://github.com/jk1/Gradle-License-Report
[REx]: https://www.bottlecaps.de/rex
[RR]: https://www.bottlecaps.de/rr
66 changes: 25 additions & 41 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Gradle build file for Convert - Grammar Converter.
* Gradle build file for ebnf-convert - Grammar Converter.
*/

plugins {
Expand All @@ -13,10 +13,9 @@ plugins {
defaultTasks 'build'
build.dependsOn 'distZip'

version = '0.66'
group = 'de.bottlecaps.convert'
version = '0.67'
group = 'de.bottlecaps.ebnf-convert'
def buildTime = new Date()
def aceVersion = '1.32.3'
def rrVersion = '2.1'

def generatedSrc = "$buildDir/generated-src/main"
Expand All @@ -38,15 +37,13 @@ repositories {
}

configurations {
ace
rrLib
rrWebapp
rrLib
rrWebapp
}

dependencies {
ace "org.webjars.npm:ace-builds:$aceVersion"
rrLib "de.bottlecaps.rr:rr-lib:$rrVersion"
rrWebapp "de.bottlecaps.rr:rr-webapp:$rrVersion"
rrLib "de.bottlecaps.rr:rr-lib:$rrVersion"
rrWebapp "de.bottlecaps.rr:rr-webapp:$rrVersion"

compileOnly 'org.apache.tomcat:tomcat-servlet-api:8.5.97'
compileOnly "de.bottlecaps.rr:rr-lib:$rrVersion"
Expand All @@ -57,7 +54,11 @@ dependencies {
implementation 'commons-io:commons-io:2.15.1'
}

configurations.all {
configurations.rrLib {
transitive = false
}

configurations.runtimeClasspath {
transitive = false
}

Expand Down Expand Up @@ -86,21 +87,12 @@ jar {

licenseReport {
outputDir = "$buildDir/LICENSE"
configurations = ['runtimeClasspath', 'ace']
configurations = ['runtimeClasspath']
renderers = [new com.github.jk1.license.render.TextReportRenderer()]
}

task generateSrc {
doFirst {
def aceBuilds = configurations.ace.find { it =~ /ace-builds/ }
def zip = new java.util.zip.ZipFile(aceBuilds)
['ace.js', 'ext-searchbox.js'].each { script ->
def entry = zip.getEntry("META-INF/resources/webjars/ace-builds/$aceVersion/src-min-noconflict/$script")
def file = new File("$generatedSrc/resources/htdocs/$script")
file.parentFile.exists() || file.parentFile.mkdirs()
file.withWriter { it << zip.getInputStream(entry) }
}

def convertVersion = new File("$generatedSrc/java/de/bottlecaps/convert", 'ConvertVersion.java')
convertVersion.parentFile.exists() || convertVersion.parentFile.mkdirs()
convertVersion.withWriter {
Expand All @@ -120,6 +112,7 @@ public class ConvertVersion
compileJava {
dependsOn generateSrc
options.release = 11
options.encoding = 'UTF-8'
}

java {
Expand All @@ -135,9 +128,9 @@ task generateLicense {
def licenseTxt = new File("$buildDir", 'LICENSE.TXT')
licenseTxt.parentFile.exists() || licenseTxt.parentFile.mkdirs()
licenseTxt.withWriter {
it << $/Convert - Grammar Converter
it << $/${project.name} - Grammar Converter

Copyright 2010-$year Gunther Rademacher <grd@gmx.net>
Copyright 2011-$year Gunther Rademacher <grd@gmx.net>

Licensed under the Apache 2.0 License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -151,18 +144,9 @@ 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.

This distribution also includes

- Saxon-HE from Saxonica.com
- TagSoup
- Apache Batik
- Apache XML Graphics Commons
- Apache XML Commons XML APIs
- Ace Editor

For their license information see THIRD-PARTY-NOTICES.txt.
For third-party license information see THIRD-PARTY-NOTICES.txt.

Thank you for choosing Convert - Grammar Converter.
Thank you for choosing ${project.name} - Grammar Converter.
/$
}
}
Expand Down Expand Up @@ -196,7 +180,7 @@ war {
task distZip(type:JavaExec) {
dependsOn war
mainClass = '-jar'
args "$buildDir/libs/convert.war", '-distZip'
args "$buildDir/libs/${project.name}.war", '-distZip'
workingDir = "$buildDir/distributions"

doFirst {
Expand All @@ -211,7 +195,7 @@ void configureMetadata(MavenPublication mavenPublication) {
pom {
name = groupId + ':' + artifactId
description = 'Grammar Converter'
url = 'https://www.bottlecaps.de/convert'
url = "https://www.bottlecaps.de/${project.name}"
licenses {
license {
name = 'Apache-2.0'
Expand All @@ -227,9 +211,9 @@ void configureMetadata(MavenPublication mavenPublication) {
}
}
scm {
connection = 'git@github.com:GuntherRademacher/convert.git'
developerConnection = 'git@github.com:GuntherRademacher/convert.git'
url = 'https://github.com/GuntherRademacher/convert'
connection = "git@github.com:GuntherRademacher/${project.name}.git"
developerConnection = "git@github.com:GuntherRademacher/${project.name}.git"
url = "https://github.com/GuntherRademacher/${project.name}"
}
}
}
Expand All @@ -250,12 +234,12 @@ publishing {

publications {
jar(MavenPublication) {
artifactId = 'convert-lib'
artifactId = 'ebnf-convert-lib'
from components.java
configureMetadata delegate
}
war(MavenPublication) {
artifactId = 'convert-webapp'
artifactId = 'ebnf-convert-webapp'
from components.web
configureMetadata delegate
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions gradlew
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = 'convert'
rootProject.name = 'ebnf-convert'
6 changes: 3 additions & 3 deletions src/main/java/de/bottlecaps/convert/Convert.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ else if (inputFile == null)
{
String resource = Convert.class.getResource("/" + Convert.class.getName().replace('.', '/') + ".class").toString();
final String file = resource.startsWith("jar:fatjar:")
? "convert.war"
? ConvertVersion.PROJECT_NAME + ".war"
: Convert.class.getName();
usage(System.err, file);
}
Expand Down Expand Up @@ -595,9 +595,9 @@ private static final class IgnoringEventHandler implements Parser.EventHandler,

public static void usage(PrintStream out, final String file) {
final String jar = file.endsWith(".war") ? "-jar " : "";
out.println("Convert - Grammar Converter");
out.println("ebnf-onvert - Grammar Converter");
out.println();
out.println("converts foreign grammars to W3C-style EBNF as suitable for REx and RR");
out.println("Converts foreign grammars to W3C-style EBNF as suitable for REx and RR.");
out.println();
out.println(" version v" + ConvertVersion.VERSION);
out.println(" released " + ConvertVersion.DATE);
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/de/bottlecaps/convert/ConvertServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
public class ConvertServlet extends HttpServlet
{
private static final String DOWNLOAD_FILENAME =
"convert" +
ConvertVersion.PROJECT_NAME +
"-" + ConvertVersion.VERSION +
"-java" + Download.javaVersion() +
".zip";
Expand Down Expand Up @@ -74,21 +74,13 @@ private String getHtmlPage(String servletPath, HttpServletResponse response, Map
{
throw new RuntimeException(e.getMessage(), e);
}
content = content.replaceAll("VERSION", "v" + ConvertVersion.VERSION)
content = content.replaceAll("PROJECT", ConvertVersion.PROJECT_NAME)
.replaceAll("VERSION", "v" + ConvertVersion.VERSION)
.replaceAll("DATE", ConvertVersion.DATE)
.replaceAll("YEAR", ConvertVersion.DATE.replaceFirst("[^,]+, ", ""))
.replaceAll("TARGET-EBNF", "ebnf".equals(parameters.get("target")) ? "selected=\"selected\"" : "")
.replaceAll("TARGET-XML", "xml".equals(parameters.get("target")) ? "selected=\"selected\"" : "")
// .replaceAll("FACTORING-NONE", "none".equals(parameters.get("factoring")) ? "selected=\"selected\"" : "")
// .replaceAll("FACTORING-LEFT-ONLY", "left-only".equals(parameters.get("factoring")) ? "selected=\"selected\"" : "")
// .replaceAll("FACTORING-RIGHT-ONLY", "right-only".equals(parameters.get("factoring")) ? "selected=\"selected\"" : "")
// .replaceAll("FACTORING-FULL-LEFT", "full-left".equals(parameters.get("factoring")) ? "selected=\"selected\"" : "")
// .replaceAll("FACTORING-FULL-RIGHT", "full-right".equals(parameters.get("factoring")) ? "selected=\"selected\"" : "")
.replaceAll("FACTORING", parameters.get("factoring") == null ? "" : "checked=\"on\"")
// .replaceAll("RECURSION-REMOVAL-NONE", "none".equals(parameters.get("recursion-removal")) ? "selected=\"selected\"" : "")
// .replaceAll("RECURSION-REMOVAL-LEFT", "left".equals(parameters.get("recursion-removal")) ? "selected=\"selected\"" : "")
// .replaceAll("RECURSION-REMOVAL-RIGHT", "right".equals(parameters.get("recursion-removal")) ? "selected=\"selected\"" : "")
// .replaceAll("RECURSION-REMOVAL-FULL", "full".equals(parameters.get("recursion-removal")) ? "selected=\"selected\"" : "")
.replaceAll("RECURSION", parameters.get("recursion") == null ? "" : "checked=\"on\"")
.replaceAll("INLINE", parameters.get("inline") == null ? "" : "checked=\"on\"")
.replaceAll("KEEP", parameters.get("keep") == null ? "" : "checked=\"on\"")
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/de/bottlecaps/convert/index.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
--></script>
</head>
<body onload="onLoad()">
<h3>Grammar Conversion</h3>
<h3>PROJECT - Grammar Converter</h3>
<p class="text">
Paste grammar into textarea and click button for converting to
<a href="https://www.w3.org/TR/xquery-31/#EBNFNotation">W3C grammar notation</a>.
Expand Down Expand Up @@ -107,7 +107,7 @@ to epsilon only.">
</form>
<p class="result"/>
<hr/>
<small>Convert
<small>PROJECT
VERSION -
DATE
<br/>&#169;
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Convert - Grammar Converter</display-name>
<display-name>ebnf-convert - Grammar Converter</display-name>
<servlet>
<display-name>Convert - Grammar Converter</display-name>
<display-name>ebnf-convert - Grammar Converter</display-name>
<servlet-name>ConvertServlet</servlet-name>
<servlet-class>de.bottlecaps.convert.ConvertServlet</servlet-class>
</servlet>
Expand Down

0 comments on commit 1252306

Please sign in to comment.