Commit 2100b5f2 authored by Fred Eisele's avatar Fred Eisele
Browse files

handle graph literal

parent 04e6d42f
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/4kx/-ru88jt/AqlLexerRules.g4 by ANTLR 4.7
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/7wu/-ru88jt/AqlLexerRules.g4 by ANTLR 4.7
package catdata.aql.grammar;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
......
This diff is collapsed.
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/4kx/-ru88jt/AqlParser.g4 by ANTLR 4.7
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/7wu/-ru88jt/AqlParser.g4 by ANTLR 4.7
package catdata.aql.grammar;
import org.antlr.v4.runtime.ParserRuleContext;
......@@ -3112,13 +3112,13 @@ public class AqlParserBaseListener implements AqlParserListener {
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterGraphExp_Literal(AqlParser.GraphExp_LiteralContext ctx) { }
@Override public void enterGraph_Literal(AqlParser.Graph_LiteralContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitGraphExp_Literal(AqlParser.GraphExp_LiteralContext ctx) { }
@Override public void exitGraph_Literal(AqlParser.Graph_LiteralContext ctx) { }
/**
* {@inheritDoc}
*
......@@ -3155,6 +3155,18 @@ public class AqlParserBaseListener implements AqlParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitGraphLiteralSection(AqlParser.GraphLiteralSectionContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterGraphEdgeSig(AqlParser.GraphEdgeSigContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitGraphEdgeSig(AqlParser.GraphEdgeSigContext ctx) { }
/**
* {@inheritDoc}
*
......@@ -3167,6 +3179,30 @@ public class AqlParserBaseListener implements AqlParserListener {
* <p>The default implementation does nothing.</p>
*/
@Override public void exitGraphNodeId(AqlParser.GraphNodeIdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterGraphSourceNodeId(AqlParser.GraphSourceNodeIdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitGraphSourceNodeId(AqlParser.GraphSourceNodeIdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void enterGraphTargetNodeId(AqlParser.GraphTargetNodeIdContext ctx) { }
/**
* {@inheritDoc}
*
* <p>The default implementation does nothing.</p>
*/
@Override public void exitGraphTargetNodeId(AqlParser.GraphTargetNodeIdContext ctx) { }
/**
* {@inheritDoc}
*
......
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/4kx/-ru88jt/AqlParser.g4 by ANTLR 4.7
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/7wu/-ru88jt/AqlParser.g4 by ANTLR 4.7
package catdata.aql.grammar;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
......@@ -1823,7 +1823,7 @@ public class AqlParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> impleme
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitGraphExp_Literal(AqlParser.GraphExp_LiteralContext ctx) { return visitChildren(ctx); }
@Override public T visitGraph_Literal(AqlParser.Graph_LiteralContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
......@@ -1845,6 +1845,13 @@ public class AqlParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> impleme
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitGraphLiteralSection(AqlParser.GraphLiteralSectionContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitGraphEdgeSig(AqlParser.GraphEdgeSigContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
......@@ -1852,6 +1859,20 @@ public class AqlParserBaseVisitor<T> extends AbstractParseTreeVisitor<T> impleme
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitGraphNodeId(AqlParser.GraphNodeIdContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitGraphSourceNodeId(AqlParser.GraphSourceNodeIdContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitGraphTargetNodeId(AqlParser.GraphTargetNodeIdContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
......
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/4kx/-ru88jt/AqlParser.g4 by ANTLR 4.7
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/7wu/-ru88jt/AqlParser.g4 by ANTLR 4.7
package catdata.aql.grammar;
import org.antlr.v4.runtime.tree.ParseTreeListener;
......@@ -2762,17 +2762,17 @@ public interface AqlParserListener extends ParseTreeListener {
*/
void exitGraphAssignment(AqlParser.GraphAssignmentContext ctx);
/**
* Enter a parse tree produced by the {@code GraphExp_Literal}
* Enter a parse tree produced by the {@code Graph_Literal}
* labeled alternative in {@link AqlParser#graphDef}.
* @param ctx the parse tree
*/
void enterGraphExp_Literal(AqlParser.GraphExp_LiteralContext ctx);
void enterGraph_Literal(AqlParser.Graph_LiteralContext ctx);
/**
* Exit a parse tree produced by the {@code GraphExp_Literal}
* Exit a parse tree produced by the {@code Graph_Literal}
* labeled alternative in {@link AqlParser#graphDef}.
* @param ctx the parse tree
*/
void exitGraphExp_Literal(AqlParser.GraphExp_LiteralContext ctx);
void exitGraph_Literal(AqlParser.Graph_LiteralContext ctx);
/**
* Enter a parse tree produced by the {@code GraphKind_Ref}
* labeled alternative in {@link AqlParser#graphKind}.
......@@ -2807,6 +2807,16 @@ public interface AqlParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitGraphLiteralSection(AqlParser.GraphLiteralSectionContext ctx);
/**
* Enter a parse tree produced by {@link AqlParser#graphEdgeSig}.
* @param ctx the parse tree
*/
void enterGraphEdgeSig(AqlParser.GraphEdgeSigContext ctx);
/**
* Exit a parse tree produced by {@link AqlParser#graphEdgeSig}.
* @param ctx the parse tree
*/
void exitGraphEdgeSig(AqlParser.GraphEdgeSigContext ctx);
/**
* Enter a parse tree produced by {@link AqlParser#graphNodeId}.
* @param ctx the parse tree
......@@ -2817,6 +2827,26 @@ public interface AqlParserListener extends ParseTreeListener {
* @param ctx the parse tree
*/
void exitGraphNodeId(AqlParser.GraphNodeIdContext ctx);
/**
* Enter a parse tree produced by {@link AqlParser#graphSourceNodeId}.
* @param ctx the parse tree
*/
void enterGraphSourceNodeId(AqlParser.GraphSourceNodeIdContext ctx);
/**
* Exit a parse tree produced by {@link AqlParser#graphSourceNodeId}.
* @param ctx the parse tree
*/
void exitGraphSourceNodeId(AqlParser.GraphSourceNodeIdContext ctx);
/**
* Enter a parse tree produced by {@link AqlParser#graphTargetNodeId}.
* @param ctx the parse tree
*/
void enterGraphTargetNodeId(AqlParser.GraphTargetNodeIdContext ctx);
/**
* Exit a parse tree produced by {@link AqlParser#graphTargetNodeId}.
* @param ctx the parse tree
*/
void exitGraphTargetNodeId(AqlParser.GraphTargetNodeIdContext ctx);
/**
* Enter a parse tree produced by {@link AqlParser#graphEdgeId}.
* @param ctx the parse tree
......
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/4kx/-ru88jt/AqlParser.g4 by ANTLR 4.7
// Generated from /home/fred/.boot/cache/tmp/home/fred/github/fql2/gen_src/catdata/aql/grammar/7wu/-ru88jt/AqlParser.g4 by ANTLR 4.7
package catdata.aql.grammar;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
......@@ -1646,12 +1646,12 @@ public interface AqlParserVisitor<T> extends ParseTreeVisitor<T> {
*/
T visitGraphAssignment(AqlParser.GraphAssignmentContext ctx);
/**
* Visit a parse tree produced by the {@code GraphExp_Literal}
* Visit a parse tree produced by the {@code Graph_Literal}
* labeled alternative in {@link AqlParser#graphDef}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitGraphExp_Literal(AqlParser.GraphExp_LiteralContext ctx);
T visitGraph_Literal(AqlParser.Graph_LiteralContext ctx);
/**
* Visit a parse tree produced by the {@code GraphKind_Ref}
* labeled alternative in {@link AqlParser#graphKind}.
......@@ -1672,12 +1672,30 @@ public interface AqlParserVisitor<T> extends ParseTreeVisitor<T> {
* @return the visitor result
*/
T visitGraphLiteralSection(AqlParser.GraphLiteralSectionContext ctx);
/**
* Visit a parse tree produced by {@link AqlParser#graphEdgeSig}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitGraphEdgeSig(AqlParser.GraphEdgeSigContext ctx);
/**
* Visit a parse tree produced by {@link AqlParser#graphNodeId}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitGraphNodeId(AqlParser.GraphNodeIdContext ctx);
/**
* Visit a parse tree produced by {@link AqlParser#graphSourceNodeId}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitGraphSourceNodeId(AqlParser.GraphSourceNodeIdContext ctx);
/**
* Visit a parse tree produced by {@link AqlParser#graphTargetNodeId}.
* @param ctx the parse tree
* @return the visitor result
*/
T visitGraphTargetNodeId(AqlParser.GraphTargetNodeIdContext ctx);
/**
* Visit a parse tree produced by {@link AqlParser#graphEdgeId}.
* @param ctx the parse tree
......
......@@ -9,7 +9,7 @@ graphAssignment : GRAPH graphId EQUAL graphDef ;
graphDef
: LITERAL
(LBRACE graphLiteralSection RBRACE)?
#GraphExp_Literal
#Graph_Literal
;
graphKind
......@@ -20,8 +20,11 @@ graphKind
graphLiteralSection
: (IMPORTS graphRef*)?
(NODES graphNodeId*)?
(EDGES (graphEdgeId+ COLON graphNodeId RARROW graphNodeId)*)?
(EDGES graphEdgeSig*)?
;
graphEdgeSig : graphEdgeId+ COLON graphSourceNodeId RARROW graphTargetNodeId ;
graphNodeId : symbol ;
graphSourceNodeId : symbol ;
graphTargetNodeId : symbol ;
graphEdgeId : symbol ;
......@@ -9,12 +9,15 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeProperty;
import org.antlr.v4.runtime.tree.TerminalNode;
import catdata.Pair;
import catdata.Triple;
import catdata.aql.RawTerm;
import catdata.aql.exp.GraphExp.GraphExpRaw;
import catdata.aql.exp.SchExp.SchExpEmpty;
import catdata.aql.exp.SchExpRaw.Att;
import catdata.aql.exp.SchExpRaw.En;
......@@ -23,6 +26,7 @@ import catdata.aql.exp.TyExp.TyExpVar;
import catdata.aql.exp.TyExpRaw.Sym;
import catdata.aql.exp.TyExpRaw.Ty;
import catdata.aql.grammar.AqlParser;
import catdata.aql.grammar.AqlParser.GraphLiteralSectionContext;
import catdata.aql.grammar.AqlParser.TypesideLiteralSectionContext;
import catdata.aql.grammar.AqlParserBaseListener;
......@@ -39,9 +43,12 @@ public class AqlLoaderListener extends AqlParserBaseListener {
return ctx.getStart().getStartIndex();
}
private LocStr getLocStr(ParserRuleContext ctx) {
private LocStr makeLocStr(ParserRuleContext ctx) {
return new LocStr(ctx.getStart().getStartIndex(), ctx.getText());
}
private LocStr makeLocStr(Token node) {
return new LocStr(node.getStartIndex(), node.getText());
}
public AqlLoaderListener() {
this.decls = new LinkedList<Triple<String, Integer, Exp<?>>>();
......@@ -125,6 +132,43 @@ public class AqlLoaderListener extends AqlParserBaseListener {
this.exps.put(ctx,this.exps.get(ctx.graphDef()));
}
/** see tyExpRaw */
@Override
public void exitGraph_Literal(AqlParser.Graph_LiteralContext ctx) {
final GraphLiteralSectionContext
ctx_lit = ctx.graphLiteralSection();
final List<LocStr>
imports = ctx_lit.graphRef().stream()
.map(elt -> makeLocStr(elt))
.collect(Collectors.toList());
final List<LocStr>
nodes = ctx_lit.graphNodeId().stream()
.map(elt -> makeLocStr(elt))
.collect(Collectors.toList());
final List<Pair<LocStr, Pair<String, String>>>
edges = ctx_lit.graphEdgeSig().stream()
.map(sig -> {
final Pair<String,String> arrow = new Pair<String,String>(
sig.graphSourceNodeId().getText(),
sig.graphTargetNodeId().getText());
return new LinkedList<Pair<LocStr, Pair<String,String>>>(
sig.graphEdgeId().stream()
.map(elt -> new Pair<LocStr, Pair<String,String>>(
makeLocStr(elt), arrow))
.collect(Collectors.toList()));
})
.flatMap(x -> x.stream())
.collect(Collectors.toList());
final GraphExpRaw graph = new GraphExpRaw(nodes, edges, imports);
this.exps.put(ctx,graph);
};
/**
* TypeSide section
*/
......@@ -169,27 +213,22 @@ public class AqlLoaderListener extends AqlParserBaseListener {
ctx_lit = ctx.typesideLiteralSection();
final List<Pair<Integer,TyExp<?,?>>>
imports = ctx_lit
.typesideImport()
.stream()
imports = ctx_lit.typesideImport().stream()
.map(elt ->
new Pair<Integer,TyExp<?,?>>(
elt.getStart().getStartIndex(),
new TyExpVar<Ty,Sym>(elt.getText())))
.collect(Collectors.toList());
final List<LocStr> types = ctx_lit
.typesideConstantSig()
.stream()
.map(elt -> getLocStr(elt))
final List<LocStr>
types = ctx_lit.typesideConstantSig().stream()
.map(elt -> makeLocStr(elt))
.collect(Collectors.toList());
final List<Pair<LocStr, Pair<List<String>, String>>>
functions = ctx_lit
.typesideFunctionSig()
.stream()
functions = ctx_lit.typesideFunctionSig().stream()
.map(elt -> new Pair<LocStr, Pair<List<String>, String>>(
getLocStr(elt.typesideFnName()),
makeLocStr(elt.typesideFnName()),
new Pair<List<String>,String>(
elt.typesideFnLocal()
.stream()
......@@ -199,9 +238,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
.collect(Collectors.toList());
final List<Pair<Integer, Triple<List<Pair<String, String>>, RawTerm, RawTerm>>>
eqns = ctx_lit
.typesideEquationSig()
.stream()
eqns = ctx_lit.typesideEquationSig().stream()
.map(elt -> new Pair<Integer, Triple<List<Pair<String, String>>, RawTerm, RawTerm>>(
elt.getStart().getStartIndex(),
new Triple<List<Pair<String, String>>, RawTerm, RawTerm>(
......@@ -216,29 +253,23 @@ public class AqlLoaderListener extends AqlParserBaseListener {
.collect(Collectors.toList());
final List<Pair<LocStr, String>>
java_tys = ctx_lit
.typesideJavaTypeSig()
.stream()
java_tys = ctx_lit.typesideJavaTypeSig().stream()
.map(elt -> new Pair<LocStr, String>(
getLocStr(elt.typesideTypeId()),
makeLocStr(elt.typesideTypeId()),
elt.typesideJavaType().getText()))
.collect(Collectors.toList());
final List<Pair<LocStr, String>>
java_constant = ctx_lit
.typesideJavaConstantSig()
.stream()
java_constant = ctx_lit.typesideJavaConstantSig().stream()
.map(elt -> new Pair<LocStr, String>(
getLocStr(elt.typesideConstantId()),
makeLocStr(elt.typesideConstantId()),
elt.typesideJavaConstantValue().getText()))
.collect(Collectors.toList());
final List<Pair<LocStr, Triple<List<String>, String, String>>>
java_fns = ctx_lit
.typesideJavaFunctionSig()
.stream()
java_fns = ctx_lit.typesideJavaFunctionSig().stream()
.map(elt -> new Pair<LocStr, Triple<List<String>, String, String>>(
getLocStr(elt.typesideFnName()),
makeLocStr(elt.typesideFnName()),
new Triple<List<String>, String, String>(
elt.typesideFnLocal()
.stream()
......@@ -249,9 +280,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
.collect(Collectors.toList());
final List<Pair<String, String>>
options = ctx_lit
.allOptions().optionsDeclaration()
.stream()
options = ctx_lit.allOptions().optionsDeclaration().stream()
.map(elt -> new Pair<String, String>(
elt.getStart().getText(),
elt.getStop().getText()))
......@@ -262,7 +291,6 @@ public class AqlLoaderListener extends AqlParserBaseListener {
java_tys, java_constant, java_fns,
options);
// final Exp<?> exp = new TyExp.TyExpLit(typeside);
this.exps.put(ctx,typeside);
};
......@@ -384,7 +412,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
final int id = getLUid(ctx);
final Exp<?> exp = this.exps.get(ctx.transformDef());
if (exp == null) {
log.warning("null query exp " + name);
log.warning("null transform exp " + name);
return;
}
ns.put(name, exp);
......@@ -405,7 +433,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
final int id = getLUid(ctx);
final Exp<?> exp = this.exps.get(ctx.constraintDef());
if (exp == null) {
log.warning("null query exp " + name);
log.warning("null constraint exp " + name);
return;
}
ns.put(name, exp);
......@@ -426,7 +454,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
final int id = getLUid(ctx);
final Exp<?> exp = this.exps.get(ctx.commandDef());
if (exp == null) {
log.warning("null query exp " + name);
log.warning("null command exp " + name);
return;
}
ns.put(name, exp);
......@@ -448,7 +476,7 @@ public class AqlLoaderListener extends AqlParserBaseListener {
final int id = getLUid(ctx);
final Exp<?> exp = this.exps.get(ctx.schemaColimitDef());
if (exp == null) {
log.warning("null query exp " + name);
log.warning("null schema colimit exp " + name);
return;
}
ns.put(name, exp);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment