Skip to content

Commit

Permalink
Improvements on generated parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Brigl committed Nov 16, 2024
1 parent 3df1591 commit 5f597b7
Show file tree
Hide file tree
Showing 50 changed files with 902 additions and 1,225 deletions.
21 changes: 10 additions & 11 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
BSD 3-Clause License

Copyright (c) 2024, the respective contributors, as shown by the AUTHORS file.
All rights reserved.
Copyright (c) 2024 - Present HiveVM Contributors

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* 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.
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.

* 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.
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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand All @@ -26,4 +25,4 @@ 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.
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ plugins {
id "org.hivevm.cc" version "1.0.0"
}
hiveCC {
parserProject {
target = 'java'
step {
task {
name = 'tree'
output = 'src/main/generated'
jjtFile = 'src/main/resources/JJTree.jjt'
directory = 'src/main/generated2/org/hivevm/cc/jjtree'
excludes = [ 'BNF', 'BNFAction', 'BNFDeclaration', 'BNFNodeScope',
'ExpansionNodeScope', 'NodeDescriptor', 'OptionBinding' ]
}
step {
task {
name = 'parser'
output = 'src/main/generated'
jjFile = 'src/main/resources/JavaCC.jj'
directory = 'src/main/generated2/org/hivevm/cc/parser'
}
}
~~~
Expand Down
Binary file modified bootstrap/javacc.jar
Binary file not shown.
26 changes: 13 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.gradle.plugin-publish' version '1.3.0'
id "org.hivevm.cc" version "1.0.0"
id "org.hivevm.cc" version "1.0.1"
id 'java-gradle-plugin'
id 'maven-publish'
}
Expand All @@ -18,7 +18,7 @@ repositories {
}


version = '1.0.0'
version = '1.0.1'
group = 'org.hivevm'


Expand Down Expand Up @@ -87,33 +87,33 @@ gradlePlugin {
}


hiveCC {
parserProject {
target = 'java'

step {
task {
name = 'tree'
output = 'src/main/generated'
jjtFile = 'src/main/resources/JJTree.jjt'
directory = 'src/main/generated/org/hivevm/cc/jjtree'
excludes = [ 'BNF', 'BNFAction', 'BNFDeclaration', 'BNFNodeScope',
'ExpansionNodeScope', 'NodeDescriptor', 'OptionBinding' ]
}

step {
task {
name = 'parser'
jjFile = 'src/main/resources/JavaCC.jj'
directory = 'src/main/generated/org/hivevm/cc/parser'
output = 'src/main/generated'
jjFile = 'src/main/resources/JavaCC.jj'
}

// step {
// task {
// name = 'oql4java'
// directory = '/data/smartIO/develop/parser/parser/src/main/java/it/smartio/text/parser'
// output = '/data/smartIO/develop/parser/parser/src/main/java'
// jjtFile = '/data/smartIO/develop/parser/parser/src/main/resources/it/smartio/text/parser/OQL.jjt'
// }

// step {
// task {
// name = 'oql4cpp'
// target = 'cpp'
// directory = '/data/smartIO/develop/core-cpp/text/parser'
// output = '/data/smartIO/develop/core-cpp/text/parser'
// jjtFile = '/data/smartIO/develop/parser/parser/src/main/resources/it/smartio/text/parser/OQL-Cpp.jjt'
// }
}
}
9 changes: 4 additions & 5 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<property name="java-src" value="src/main/java" />
<property name="resources-src" value="src/main/resources" />
<property name="generated-src" value="src/main/generated" />
<property name="parser-generated-src" value="${generated-src}/org/hivevm/cc/parser" />
<property name="jjtree-generated-src" value="${generated-src}/org/hivevm/cc/jjtree" />

<property name="bootstrap-jar" value="bootstrap/javacc.jar" />
Expand Down Expand Up @@ -72,19 +71,19 @@

<!-- ReGenerate the Java CC Main Parser with the new jar -->
<java classname="${javacc-class-name}" classpath="${param-jar}" dir="${basedir}/src/main/resources" fork="true">
<arg value="-OUTPUT_DIRECTORY=${basedir}/${parser-generated-src}" />
<arg value="-OUTPUT_DIRECTORY=${basedir}/${generated-src}" />
<arg value="JavaCC.jj" />
</java>

<!-- ReGenerate the JJTree Parser Definition (from the tree definition) -->
<java classname="${jjtree-class-name}" classpath="${param-jar}" dir="${basedir}/src/main/resources" fork="true">
<arg value="-OUTPUT_DIRECTORY=${basedir}/${jjtree-generated-src}" />
<arg value="-OUTPUT_DIRECTORY=${basedir}/${generated-src}" />
<arg value="JJTree.jjt" />
</java>

<!-- Generate the JJTree Parser with the new jar -->
<java classname="${javacc-class-name}" classpath="${param-jar}" dir="${basedir}/${jjtree-generated-src}" fork="true">
<arg value="-OUTPUT_DIRECTORY=${basedir}/${jjtree-generated-src}" />
<java classname="${javacc-class-name}" classpath="${param-jar}" dir="${basedir}/${generated-src}" fork="true">
<arg value="-OUTPUT_DIRECTORY=${basedir}/${generated-src}" />
<arg value="JJTree.jj" />
</java>

Expand Down
7 changes: 3 additions & 4 deletions src/main/gradle/org/hivevm/cc/GradlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
*/
public class GradlePlugin implements Plugin<Project> {

public static final String CONFIG = "hiveCC";

private static final String CONFIG = "parserProject";

@Override
public void apply(Project project) {
ExtensionContainer extension = project.getExtensions();
extension.create(GradlePlugin.CONFIG, GeneratorConfig.class);
extension.create(GradlePlugin.CONFIG, ParserProject.class);

project.getTasks().register("generateParser", GeneratorTask.class);
project.getTasks().register("generateParser", ParserGenerator.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@

package org.hivevm.cc;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

import org.gradle.api.DefaultTask;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
Expand All @@ -18,13 +11,20 @@
import org.gradle.api.tasks.options.Option;
import org.gradle.api.tasks.options.OptionValues;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

/**
* The {@link GeneratorTask} class.
* The {@link ParserGenerator} class.
*/
public abstract class GeneratorTask extends DefaultTask {
public abstract class ParserGenerator extends DefaultTask {

@Inject
public GeneratorTask() {
public ParserGenerator() {
setGroup("HiveVM");
setDescription("Generates a parser");
}
Expand All @@ -41,16 +41,15 @@ public List<Language> getAvailableOutputTypes() {

@TaskAction
public void process() {
GeneratorConfig config = getProject().getExtensions().findByType(GeneratorConfig.class);
ParserProject config = getProject().getExtensions().findByType(ParserProject.class);

if (config == null) {
getProject().getLogger().error("No configuration defined");
return;
}

Language defaultTarget = (config.target == null) ? Language.JAVA : config.target;

config.getSteps().forEach(s -> process(s, defaultTarget));
config.getTasks().forEach(s -> process(s, defaultTarget));
}

protected File getFile(String pathname) {
Expand All @@ -67,14 +66,13 @@ protected File getFile(String pathname) {
return new File(projectDir, pathname);
}


protected void process(GeneratorStep step, Language target) {
Language language = (step.target == null) ? target : step.target;
protected void process(ParserTask task, Language target) {
Language language = (task.target == null) ? target : task.target;
HiveCCBuilder builder = HiveCCBuilder.of(language);
builder.setTargetDir(getFile(step.directory));
builder.setJJTreeFile(getFile(step.jjtFile));
builder.setJJFile(getFile(step.jjFile));
builder.setExcludes(step.excludes);
builder.setTargetDir(getFile(task.output));
builder.setJJTreeFile(getFile(task.jjtFile));
builder.setJJFile(getFile(task.jjFile));
builder.setExcludes(task.excludes);
builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,41 @@

package org.hivevm.cc;

import java.util.List;

import javax.inject.Inject;

import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.Nested;

public abstract class GeneratorConfig {
import java.util.List;

import javax.inject.Inject;

public abstract class ParserProject {

private final Project project;

public Language target;


private final ListProperty<GeneratorStep> steps;
private final ListProperty<ParserTask> tasks;

@Inject
public GeneratorConfig(Project project) {
public ParserProject(Project project) {
this.project = project;
this.steps = project.getObjects().listProperty(GeneratorStep.class).empty();
this.tasks = project.getObjects().listProperty(ParserTask.class).empty();
}

protected final Project getProject() {
return this.project;
}

@Nested
public final List<GeneratorStep> getSteps() {
return this.steps.get();
public final List<ParserTask> getTasks() {
return this.tasks.get();
}

public final void step(Action<? super GeneratorStep> action) {
this.steps.add(newInstance(GeneratorStep.class, action));
public final void task(Action<? super ParserTask> action) {
this.tasks.add(newInstance(ParserTask.class, action));
}

private <C> C newInstance(Class<C> clazz, Action<? super C> action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

package org.hivevm.cc;

import org.gradle.api.Project;

import java.util.List;

import javax.inject.Inject;

import org.gradle.api.Project;

public class GeneratorStep {
public class ParserTask {

private final Project project;

Expand All @@ -20,12 +20,12 @@ public class GeneratorStep {
public String jjFile;
public String jjtFile;

public String directory;
public String output;
public List<String> excludes;


@Inject
public GeneratorStep(Project project) {
public ParserTask(Project project) {
this.project = project;
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/javacc.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
* Intermediary between OS script and main program of application. Having this intermediary allows
* the OS scripts to be package name independent.
*/
public final class javacc {
public interface javacc {

private javacc() {}

public static void main(String[] args) throws Exception {
static void main(String[] args) throws Exception {
org.hivevm.cc.JJParser.main(args);
}
}
6 changes: 2 additions & 4 deletions src/main/java/jjdoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
* Intermediary between OS script and main program of application. Having this intermediary allows
* the OS scripts to be package name independent.
*/
public final class jjdoc {
public interface jjdoc {

private jjdoc() {}

public static void main(String[] args) throws Exception {
static void main(String[] args) throws Exception {
org.hivevm.cc.doc.JJDocMain.main(args);
}
}
7 changes: 2 additions & 5 deletions src/main/java/jjtree.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@
* Intermediary between OS script and main program of application. Having this intermediary allows
* the OS scripts to be package name independent.
*/
public final class jjtree {
public interface jjtree {

private jjtree() {}

public static void main(String[] args) {
static void main(String[] args) {
org.hivevm.cc.JJTree.main(args);
}

}
Loading

0 comments on commit 5f597b7

Please sign in to comment.