Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git

Migrating to ANTLR.

Author Dave Jarvis <email>
Date 2015-02-28 18:19:22 GMT-0800
Commit 91d8f91e800642bd44966fb2ae5f775ebca2f28a
Parent 3b2a66d
Delta 25 lines added, 138 lines removed, 113-line decrease
build.gradle
+description = "Relational eXpression Map"
+
apply plugin: "java"
-apply plugin: "application"
sourceCompatibility = 1.8
}
}
+
+ext.antlr = [
+ grammarpackage: "com.whitemagicsoftware.rxm",
+ antlrSource: 'source/grammar',
+ destinationDir: "build"
+]
+
dependencies {
- compile fileTree(
- dir: 'lib',
- includes: ['*.jar']
- )
- compile files( "$buildDir" )
+
+ antlr "org.antlr:antlr4:4.5"
}
repositories {
- maven {
- url "https://maven.atlassian.com/repository/public/"
- }
-
- flatDir {
- dirs "lib"
- }
+ mavenCentral()
}
build.sh
-#!/bin/bash
-
-echo "Requires bnfc v2.7.1 (or greater)"
-
-echo -n "bnfc version: "
-bnfc --version
-
-echo "Converting BNFC to Java..."
-bnfc -m -java -p com.whitemagicsoftware rxm.cf > bnfc.log 2>&1
-
-echo "Creating a clean build..."
-make clean > /dev/null
-
-CLASSPATH="-cp .:lib/*"
-
-mkdir -p build
-
-echo "Building files..."
-make JAVA_FLAGS="$CLASSPATH" JAVAC_FLAGS="$CLASSPATH -d build" > make.log 2>&1
-
-echo "Removing backup files..."
-find . -type f -name "*.bak" -exec rm {} \;
-
lib/java-cup-11b-runtime.jar
Binary files differ
lib/java-cup-11b.jar
Binary files differ
lib/jlex.jar
Binary files differ
rxm.cf
-entrypoints Query ;
-
-token Identifier (letter (letter | digit | '_')*) ;
-token LineTerminator (',') ;
-token AssignMap ('>') ;
-token InnerJoin ('+' '>') ;
-token OuterJoin ('-' '>') ;
-
-TTbl. Table ::= Identifier ;
-TCol. Column ::= "." Identifier ;
-TTblCol. TableColumn ::= Identifier Column ;
-TAttr. Attribute ::= "@" Identifier ;
-TParam. Parameter ::= "$" Identifier ;
-
-RXM. Query ::= Start Map ";" Where ;
-
-SDecl. Start ::= StartDecl LineTerminator;
-SStart. StartDecl ::= "root" AssignMap Element ;
-SModule. StartDecl ::= "module" Identifier ;
-
-MDecl. Map ::= MapDecl LineTerminator ;
-MGlob. MapDecl ::= ".*" ;
-MLine. MapDecl ::= LineDecl ;
-
-ETbl. Entity ::= Table ;
-ECol. Entity ::= Column ;
-
-NElem. Node ::= Element ;
-NAttr. Node ::= Attribute ;
-
-DeclNode. LineDecl ::= Entity AssignMap Node ;
-DeclInner. LineDecl ::= TableColumn InnerJoin TableColumn ;
-DeclOuter. LineDecl ::= TableColumn OuterJoin TableColumn ;
-DeclPop. LineDecl ::= "^" ;
-DeclImport. LineDecl ::= "import" Identifier ;
-
-ElIdent. Element ::= Identifier ;
-ElPath. Element ::= Identifier "/" Element ;
-
-WCompEq. ComparatorOperatorEquality ::= "=" ;
-WCompNeq. ComparatorOperatorEquality ::= "<>" ;
-
-WCompLt. ComparatorOperator ::= "<" ;
-WCompGt. ComparatorOperator ::= ">" ;
-WCompLte. ComparatorOperator ::= "<=" ;
-WCompGte. ComparatorOperator ::= ">=" ;
-
-WAnd. LogicalOp ::= "&&" ;
-WOr. LogicalOp ::= "||" ;
-
-WEmpty. Where ::= Where ;
-WEq. Where ::= TableColumn ComparatorOperatorEquality AllValues ;
-WComp. Where ::= TableColumn ComparatorOperator Value ;
-WLogic. Where ::= Where LogicalOp Where ;
-WParen. Where ::= "(" Where ")" ;
-
-VValue. AllValues ::= Value ;
-VSet. AllValues ::= Set ;
-
-rules Value ::= Parameter | "null" | String | Double ;
-
-SBlock. Set ::= "{" SetValues "}" ;
-rules SetValues ::= Value | Value "," Value;
-
source/com/whitemagicsoftware/rxm/Parser.java
import java.io.IOException;
-import java.io.StringReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
-
-import java_cup.runtime.*;
-
-import com.whitemagicsoftware.rxm.*;
-import com.whitemagicsoftware.rxm.Absyn.*;
/**
* Parses the expression into an abstract tree.
*/
public class Parser {
/**
* Creates a Parser instance that parses a given <b>rxm</b> string.
*/
- public Parser( String rxm ) throws Exception {
- Yylex lexer = new Yylex( new StringReader( rxm ) );
- parser p = new parser( lexer );
-
- try {
- com.whitemagicsoftware.rxm.Absyn.Query parse_tree = p.pQuery();
- System.out.println();
- System.out.println("Parse Succesful!");
- System.out.println();
- System.out.println("[Abstract Syntax]");
- System.out.println();
- System.out.println(PrettyPrinter.show(parse_tree));
- System.out.println();
- System.out.println("[Linearized Tree]");
- System.out.println();
- System.out.println(PrettyPrinter.print(parse_tree));
- }
- catch(Throwable e) {
- throw new ParserException(
- lexer.line_num(), lexer.buff(), e.getMessage() );
- }
+ public Parser( String rxm ) throws ParserException {
}
/**
* @param args Contains the file name with an <b>rxm</b> to parse.
*/
- public static void main( String args[] ) throws Exception {
+ public static void main( String args[] )
+ throws IOException, ParserException {
Parser parser = new Parser( readFile( args[0] ) );
}
test/people.rxm
-root > people,
-person > person,
-.first_name > first,
-.last_name > name/last,
-.age > @age,
-account.person_id +> person.person_id,
-account > account,
-.id > @id,
+root > people,
+person > person,
+.first_name > first,
+.last_name > name/last,
+.age > @age,
+account.person_id +> person.person_id,
+account > account,
+.id > @id,
^,
-address > address,
+address > address,
.*,
-account.person_id -> company.person_id,
+account.person_id -> company.person_id,
;