summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RGens/data/seniordesign/dbdata.gram22
-rw-r--r--RGens/pom.xml43
-rw-r--r--RGens/src/main/java/bjc/rgens/newparser/RGrammars.java47
3 files changed, 94 insertions, 18 deletions
diff --git a/RGens/data/seniordesign/dbdata.gram b/RGens/data/seniordesign/dbdata.gram
index 58143ad..cf20455 100644
--- a/RGens/data/seniordesign/dbdata.gram
+++ b/RGens/data/seniordesign/dbdata.gram
@@ -14,14 +14,24 @@
admin
sysadmin
-[user+idno] 800 [idno-chain]
+pragma export-rule [user-role]
+
+[user-idno] [act-user+idno]
+
+pragma export-rule [user-idno]
+
+[act-user+idno] 800 [idno-chain]
700 [idno-chain]
-[idno-chain] [digit] [digit] [digit] [digit] [digit]
+[idno-chain] [digit] [digit] [digit] [digit] [digit] [digit]
+
+[term-code] [2000..2040] 0 [1..9]
+ [2000..2040] [10..12]
-[sd-user] User (role: ' [user-role] ' ; id: ' [user+idno] ' ; realname : ' [full-name-and-title] ' ; email: ' [email] ' )
+pragma despace-rule [term-code]
+pragma export-rule [term-code]
-[sd-pmsg] recipient: [full-name-and-title] ; nquestions: [small-number] ; questions: [mission-statement]
+[section-code] [0..9] [0..9]
-pragma export-rule [sd-user]
-pragma export-rule [sd-pmsg]
+pragma despace-rule [section-code]
+pragma export-rule [section-code]
diff --git a/RGens/pom.xml b/RGens/pom.xml
index 9926e95..b0de95c 100644
--- a/RGens/pom.xml
+++ b/RGens/pom.xml
@@ -2,6 +2,29 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+ <groupId>bjc</groupId>
+ <artifactId>RGens</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>RGens</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <distributionManagement>
+ <snapshotRepository>
+ <id>ossrh</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+ </snapshotRepository>
+ <repository>
+ <id>ossrh</id>
+ <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+ </repository>
+ </distributionManagement>
+
<build>
<plugins>
<plugin>
@@ -11,20 +34,25 @@
<target>1.8</target>
</configuration>
</plugin>
+
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
+
<configuration>
<mainClass>bjc.rgens.newparser.RGrammarTest</mainClass>
+
<arguments>
</arguments>
</configuration>
</plugin>
</plugins>
+
<resources>
<resource>
<directory>data/</directory>
+
<includes>
<include>**/*.gram</include>
<include>**/*.cfg</include>
@@ -33,34 +61,25 @@
</resources>
</build>
- <groupId>bjc</groupId>
- <artifactId>RGens</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
-
- <name>RGens</name>
- <url>http://maven.apache.org</url>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
<dependencies>
<dependency>
<groupId>bjc</groupId>
<artifactId>BJC-Utils2</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
+
<dependency>
<groupId>com.github.mifmif</groupId>
<artifactId>generex</artifactId>
<version>1.0.2</version>
</dependency>
+
<dependency>
<groupId>edu.gatech.gtri.bk-tree</groupId>
<artifactId>bk-tree</artifactId>
<version>1.0</version>
</dependency>
+
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
diff --git a/RGens/src/main/java/bjc/rgens/newparser/RGrammars.java b/RGens/src/main/java/bjc/rgens/newparser/RGrammars.java
new file mode 100644
index 0000000..b898726
--- /dev/null
+++ b/RGens/src/main/java/bjc/rgens/newparser/RGrammars.java
@@ -0,0 +1,47 @@
+package bjc.rgens.newparser;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Get access to the included grammars.
+ *
+ * @author Ben Culkin
+ */
+public class RGrammars {
+ private static RGrammarSet gramSet;
+
+ private static void loadSet() {
+ URL rsc = RGrammarTest.class.getResource("/server-config-sample.cfg");
+
+ try {
+ Path cfgPath = Paths.get(rsc.toURI());
+
+ gramSet = RGrammarSet.fromConfigFile(cfgPath);
+ } catch (IOException | URISyntaxException ex) {
+ RuntimeException rtex = new RuntimeException("Could not load grammars");
+
+ rtex.initCause(ex);
+
+ throw rtex;
+ }
+ }
+
+ public static String generateExport(String exportName) throws GrammarException {
+ if(gramSet == null) loadSet();
+
+ if(!gramSet.getExportedRules().contains(exportName)) {
+ throw new GrammarException(String.format("No built-in rule named %s", exportName));
+ }
+
+ RGrammar gram = gramSet.getExportSource(exportName);
+
+ String res = gram.generate(exportName);
+ if(exportName.contains("+")) res = res.replaceAll("\\s+", "");
+
+ return res;
+ }
+}